diff --git a/src/Scylla/AccountData.elm b/src/Scylla/AccountData.elm index 24dc667..0137e7b 100644 --- a/src/Scylla/AccountData.elm +++ b/src/Scylla/AccountData.elm @@ -1,7 +1,7 @@ module Scylla.AccountData exposing (..) import Scylla.Sync exposing (SyncResponse, AccountData, JoinedRoom, roomAccountData) import Json.Decode as Decode -import Dict +import Dict exposing (Dict) type NotificationSetting = Normal | MentionsOnly | None @@ -28,3 +28,18 @@ roomIdNotificationSetting sr s = Maybe.withDefault Normal <| Maybe.andThen (Dict.get s) <| Maybe.andThen .join sr.rooms +type alias DirectMessages = Dict String String +type alias DirectMessagesRaw = Dict String (List String) + +directMessagesDecoder : Decode.Decoder DirectMessages +directMessagesDecoder = + Decode.dict (Decode.list Decode.string) + |> Decode.map (invertDirectMessages) + +invertDirectMessages : DirectMessagesRaw -> DirectMessages +invertDirectMessages dmr = + Dict.foldl + (\k lv acc -> List.foldl (\v -> Dict.insert v k) acc lv) + Dict.empty + dmr + diff --git a/src/Scylla/Model.elm b/src/Scylla/Model.elm index 9b33f96..0dd1ad7 100644 --- a/src/Scylla/Model.elm +++ b/src/Scylla/Model.elm @@ -1,6 +1,7 @@ module Scylla.Model exposing (..) import Scylla.Api exposing (..) -import Scylla.Sync exposing (SyncResponse, HistoryResponse, JoinedRoom, senderName, roomName, roomJoinedUsers, findFirst, directMessagesDecoder, AccountData) +import Scylla.Sync exposing (SyncResponse, HistoryResponse, JoinedRoom, senderName, roomName, roomJoinedUsers, findFirst, AccountData) +import Scylla.AccountData exposing (directMessagesDecoder) import Scylla.Login exposing (LoginResponse, Username, Password) import Scylla.UserData exposing (UserData) import Scylla.Route exposing (Route(..), RoomId) diff --git a/src/Scylla/Sync.elm b/src/Scylla/Sync.elm index 2ec933c..14a204d 100644 --- a/src/Scylla/Sync.elm +++ b/src/Scylla/Sync.elm @@ -258,22 +258,6 @@ historyResponseDecoder = |> required "end" string |> required "chunk" (list roomEventDecoder) --- Direct Messages -type alias DirectMessages = Dict String String -type alias DirectMessagesRaw = Dict String (List String) - -directMessagesDecoder : Decoder DirectMessages -directMessagesDecoder = - Decode.dict (Decode.list Decode.string) - |> Decode.map (invertDirectMessages) - -invertDirectMessages : DirectMessagesRaw -> DirectMessages -invertDirectMessages dmr = - Dict.foldl - (\k lv acc -> List.foldl (\v -> Dict.insert v k) acc lv) - Dict.empty - dmr - -- Business Logic: Helper Functions groupBy : (a -> comparable) -> List a -> Dict comparable (List a) groupBy f xs =