Cleanup command code.
This commit is contained in:
parent
78620c3b4f
commit
55f40d5a51
28
src/Main.elm
28
src/Main.elm
|
@ -119,7 +119,7 @@ updateSyncResponse model r notify =
|
||||||
<| Result.map .nextBatch r
|
<| Result.map .nextBatch r
|
||||||
syncCmd = sync nextBatch model.apiUrl token
|
syncCmd = sync nextBatch model.apiUrl token
|
||||||
newUsers sr = List.filter (\s -> not <| Dict.member s model.userData) <| roomsUsers sr
|
newUsers sr = List.filter (\s -> not <| Dict.member s model.userData) <| roomsUsers sr
|
||||||
newUserCommands sr = Cmd.batch
|
newUserCmd sr = Cmd.batch
|
||||||
<| List.map (userData model.apiUrl
|
<| List.map (userData model.apiUrl
|
||||||
<| Maybe.withDefault "" model.token)
|
<| Maybe.withDefault "" model.token)
|
||||||
<| newUsers sr
|
<| newUsers sr
|
||||||
|
@ -127,13 +127,14 @@ updateSyncResponse model r notify =
|
||||||
(\(s, e) -> e.originServerTs)
|
(\(s, e) -> e.originServerTs)
|
||||||
(\(s, e) -> e.sender /= model.loginUsername)
|
(\(s, e) -> e.sender /= model.loginUsername)
|
||||||
<| notificationEvents sr
|
<| notificationEvents sr
|
||||||
notificationCommand sr = Maybe.withDefault Cmd.none
|
notificationCmd sr = if notify
|
||||||
<| Maybe.map (\(s, e) -> sendNotificationPort
|
then Maybe.withDefault Cmd.none
|
||||||
{ name = displayName model e.sender
|
<| Maybe.map (\(s, e) -> sendNotificationPort
|
||||||
, text = notificationText e
|
{ name = displayName model e.sender
|
||||||
, room = s
|
, text = notificationText e
|
||||||
})
|
, room = s
|
||||||
<| notification sr
|
}) <| notification sr
|
||||||
|
else Cmd.none
|
||||||
roomMessages sr = case currentRoomId model of
|
roomMessages sr = case currentRoomId model of
|
||||||
Just rid -> List.filter (((==) "m.room.message") << .type_)
|
Just rid -> List.filter (((==) "m.room.message") << .type_)
|
||||||
<| Maybe.withDefault []
|
<| Maybe.withDefault []
|
||||||
|
@ -143,14 +144,17 @@ updateSyncResponse model r notify =
|
||||||
<| Maybe.andThen .join
|
<| Maybe.andThen .join
|
||||||
<| sr.rooms
|
<| sr.rooms
|
||||||
Nothing -> []
|
Nothing -> []
|
||||||
setScrollCommand sr = if List.isEmpty <| roomMessages sr then Cmd.none else Task.attempt ViewportAfterMessage (Browser.Dom.getViewportOf "events-wrapper")
|
setScrollCmd sr = if List.isEmpty
|
||||||
|
<| roomMessages sr
|
||||||
|
then Cmd.none
|
||||||
|
else Task.attempt ViewportAfterMessage (Browser.Dom.getViewportOf "events-wrapper")
|
||||||
in
|
in
|
||||||
case r of
|
case r of
|
||||||
Ok sr -> ({ model | sync = mergeSyncResponse model.sync sr }, Cmd.batch
|
Ok sr -> ({ model | sync = mergeSyncResponse model.sync sr }, Cmd.batch
|
||||||
[ syncCmd
|
[ syncCmd
|
||||||
, newUserCommands sr
|
, newUserCmd sr
|
||||||
, if notify then notificationCommand sr else Cmd.none
|
, notificationCmd sr
|
||||||
, setScrollCommand sr
|
, setScrollCmd sr
|
||||||
])
|
])
|
||||||
_ -> (model, syncCmd)
|
_ -> (model, syncCmd)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user