Update new users in history responses.
This commit is contained in:
parent
437039bcc4
commit
2cdfc45a93
19
src/Main.elm
19
src/Main.elm
|
@ -82,9 +82,18 @@ update msg model = case msg of
|
|||
ReceiveHistoryResponse r hr -> updateHistoryResponse model r hr
|
||||
|
||||
updateHistoryResponse : Model -> RoomId -> Result Http.Error HistoryResponse -> (Model, Cmd Msg)
|
||||
updateHistoryResponse m r hr = case hr of
|
||||
Ok h -> ({ m | sync = appendHistoryResponse m.sync r h }, Cmd.none)
|
||||
Err _ -> (m, Cmd.none)
|
||||
updateHistoryResponse m r hr =
|
||||
let
|
||||
newUsersCmd h = Cmd.batch
|
||||
<| List.map (userData m.apiUrl (Maybe.withDefault "" m.token))
|
||||
<| newUsers m
|
||||
<| uniqueBy (\s -> s)
|
||||
<| List.map .sender
|
||||
<| h.chunk
|
||||
in
|
||||
case hr of
|
||||
Ok h -> ({ m | sync = appendHistoryResponse m.sync r h }, newUsersCmd h)
|
||||
Err _ -> (m, Cmd.none)
|
||||
|
||||
updateHistory : Model -> RoomId -> (Model, Cmd Msg)
|
||||
updateHistory m r =
|
||||
|
@ -212,11 +221,11 @@ updateSyncResponse model r notify =
|
|||
nextBatch = Result.withDefault model.sync.nextBatch
|
||||
<| Result.map .nextBatch r
|
||||
syncCmd = sync model.apiUrl token nextBatch
|
||||
newUsers sr = List.filter (\s -> not <| Dict.member s model.userData) <| roomsUsers sr
|
||||
newUserCmd sr = Cmd.batch
|
||||
<| List.map (userData model.apiUrl
|
||||
<| Maybe.withDefault "" model.token)
|
||||
<| newUsers sr
|
||||
<| newUsers model
|
||||
<| allUsers sr
|
||||
notification sr = findFirstBy
|
||||
(\(s, e) -> e.originServerTs)
|
||||
(\(s, e) -> e.sender /= model.loginUsername)
|
||||
|
|
|
@ -62,6 +62,9 @@ roomUrl s = Url.Builder.absolute [ "room", s ] []
|
|||
loginUrl : String
|
||||
loginUrl = Url.Builder.absolute [ "login" ] []
|
||||
|
||||
newUsers : Model -> List Username -> List Username
|
||||
newUsers m lus = List.filter (\u -> not <| Dict.member u m.userData) lus
|
||||
|
||||
currentRoom : Model -> Maybe JoinedRoom
|
||||
currentRoom m =
|
||||
let
|
||||
|
|
|
@ -448,9 +448,9 @@ roomStateEvents jr =
|
|||
, prevContent = Nothing
|
||||
, stateKey = ""
|
||||
}
|
||||
allEvents = uniqueBy .eventId (stateEvents ++ (List.map roomToStateEvent timelineEvents))
|
||||
allStateEvents = uniqueBy .eventId (stateEvents ++ (List.map roomToStateEvent timelineEvents))
|
||||
in
|
||||
allEvents
|
||||
allStateEvents
|
||||
|
||||
roomAccountData : JoinedRoom -> String -> Maybe Decode.Value
|
||||
roomAccountData jr et =
|
||||
|
@ -495,16 +495,21 @@ roomTypingUsers jr = Maybe.withDefault []
|
|||
<| Maybe.andThen (findLast (((==) "m.typing") << .type_))
|
||||
<| Maybe.andThen .events jr.ephemeral
|
||||
|
||||
roomsUsers : SyncResponse -> List Username
|
||||
roomsUsers s =
|
||||
allRoomDictEvents : Dict String { a | timeline : Maybe Timeline } -> List RoomEvent
|
||||
allRoomDictEvents dict = List.concatMap (Maybe.withDefault [] << .events)
|
||||
<| List.filterMap .timeline
|
||||
<| Dict.values dict
|
||||
|
||||
allEvents : SyncResponse -> List RoomEvent
|
||||
allEvents 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
|
||||
eventsFor f = Maybe.withDefault []
|
||||
<| Maybe.map allRoomDictEvents
|
||||
<| Maybe.andThen f s.rooms
|
||||
joinedEvents = eventsFor .join
|
||||
leftEvents = eventsFor .leave
|
||||
in
|
||||
uniqueBy (\u -> u) <| leftUsers ++ joinedUsers
|
||||
uniqueBy .eventId <| leftEvents ++ joinedEvents
|
||||
|
||||
allUsers : SyncResponse -> List Username
|
||||
allUsers s = uniqueBy (\u -> u) <| List.map .sender <| allEvents s
|
||||
|
|
Loading…
Reference in New Issue
Block a user