diff --git a/src/Main.elm b/src/Main.elm index 37ef039..da6b61b 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -36,6 +36,7 @@ init flags url key = , errors = [] , roomText = Dict.empty , transactionId = 0 + , userData = Dict.empty } cmd = case flags.token of Just _ -> Cmd.none diff --git a/src/Scylla/Model.elm b/src/Scylla/Model.elm index 2bb275c..47d27f9 100644 --- a/src/Scylla/Model.elm +++ b/src/Scylla/Model.elm @@ -21,6 +21,7 @@ type alias Model = , errors : List String , roomText : Dict String String , transactionId : Int + , userData : Dict Username UserData } type Msg = diff --git a/src/Scylla/Sync.elm b/src/Scylla/Sync.elm index dc7bc07..05b3ba9 100644 --- a/src/Scylla/Sync.elm +++ b/src/Scylla/Sync.elm @@ -1,6 +1,7 @@ module Scylla.Sync exposing (..) import Scylla.Api exposing (..) import Scylla.Notification exposing (..) +import Scylla.Login exposing (Username) import Dict exposing (Dict) import Json.Decode as Decode exposing (Decoder, int, string, float, list, value, dict, bool, field) import Json.Decode.Pipeline exposing (required, optional) @@ -384,3 +385,18 @@ joinedRoomsEvents s = Maybe.withDefault Dict.empty <| Maybe.map (Dict.map (\k v -> Maybe.withDefault [] <| Maybe.andThen .events v.timeline)) <| Maybe.andThen .join s.rooms + +-- Business Logic: User Extraction +roomsUsers : SyncResponse -> List Username +roomsUsers s = + let + users dict = + List.map .sender + <| (List.concatMap <| Maybe.withDefault [] << .events) + <| (List.filterMap .timeline) + <| Dict.values dict + usersFor f = Maybe.withDefault [] <| Maybe.map users <| Maybe.andThen f s.rooms + joinedUsers = usersFor .join + leftUsers = usersFor .leave + in + leftUsers ++ joinedUsers