From 983592d520fc53ff4ca8ce42a5e40ac671ebb44c Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 15 Dec 2018 20:56:17 -0800 Subject: [PATCH] Set read marker on opening room. --- src/Main.elm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Main.elm b/src/Main.elm index fe812de..f54dfb1 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -62,7 +62,7 @@ update msg model = case msg of AttemptLogin -> (model, Scylla.Http.login model.apiUrl model.loginUsername model.loginPassword) -- TODO TryUrl urlRequest -> updateTryUrl model urlRequest OpenRoom s -> (model, Nav.pushUrl model.key <| roomUrl s) - ChangeRoute r -> ({ model | route = r }, Cmd.none) + ChangeRoute r -> updateChangeRoute model r ViewportAfterMessage v -> updateViewportAfterMessage model v ViewportChangeComplete _ -> (model, Cmd.none) ReceiveLoginResponse r -> updateLoginResponse model r @@ -74,6 +74,19 @@ update msg model = case msg of SendRoomTextResponse r -> (model, Cmd.none) ReceiveCompletedReadMarker r -> (model, Cmd.none) +updateChangeRoute : Model -> Route -> (Model, Cmd Msg) +updateChangeRoute m r = + let + joinedRoom = case r of + Room rid -> Maybe.andThen (Dict.get rid) <| Maybe.andThen .join <| m.sync.rooms + _ -> Nothing + lastMessage = Maybe.andThen (findLastEvent (((==) "m.room.message") << .type_)) <| Maybe.andThen .events <| Maybe.andThen .timeline joinedRoom + readMarkerCmd = case (r, lastMessage) of + (Room rid, Just re) -> setReadMarkers m.apiUrl (Maybe.withDefault "" m.token) rid re.eventId <| Just re.eventId + _ -> Cmd.none + in + ({ m | route = r }, readMarkerCmd) + updateViewportAfterMessage : Model -> Result Browser.Dom.Error Viewport -> (Model, Cmd Msg) updateViewportAfterMessage m vr = let