Begin working on requesting users' names.

This commit is contained in:
Danila Fedorin 2018-12-13 02:38:25 -08:00
parent 2449a3c8c4
commit 996da079e2
3 changed files with 18 additions and 0 deletions

View File

@ -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

View File

@ -21,6 +21,7 @@ type alias Model =
, errors : List String
, roomText : Dict String String
, transactionId : Int
, userData : Dict Username UserData
}
type Msg =

View File

@ -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