From fe065130fe6619c78c305fffb640ddd8f8a68213 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Mon, 25 Feb 2019 20:16:06 -0800 Subject: [PATCH] Scroll after "sending" messages. --- src/Main.elm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Main.elm b/src/Main.elm index 6c47e12..4bc85d1 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -100,6 +100,9 @@ update msg model = case msg of DismissError i -> updateDismissError model i AttemptReconnect -> ({ model | connected = True }, firstSync model.apiUrl (Maybe.withDefault "" model.token)) +requestScrollCmd : Cmd Msg +requestScrollCmd = Task.attempt ViewportAfterMessage (Browser.Dom.getViewportOf "messages-wrapper") + updateDismissError : Model -> Int -> (Model, Cmd Msg) updateDismissError m i = ({ m | errors = (List.take i m.errors) ++ (List.drop (i+1) m.errors)}, Cmd.none) @@ -115,7 +118,7 @@ updateMarkdown m { roomId, text, markdown } = , sending = Dict.insert (m.transactionId + 1) (roomId, TextMessage text) m.sending } in - (newModel, Cmd.batch [ storeValueCmd, sendMessageCmd ]) + (newModel, Cmd.batch [ storeValueCmd, sendMessageCmd, requestScrollCmd ]) updateFileUploadComplete : Model -> RoomId -> File -> (Result Http.Error String) -> (Model, Cmd Msg) updateFileUploadComplete m rid mime ur = @@ -315,7 +318,7 @@ updateSyncResponse model r notify = setScrollCmd sr = if List.isEmpty <| roomMessages sr then Cmd.none - else Task.attempt ViewportAfterMessage (Browser.Dom.getViewportOf "messages-wrapper") + else requestScrollCmd setReadReceiptCmd sr = case (room, List.head <| List.reverse <| roomMessages sr) of (Just rid, Just re) -> setReadMarkers model.apiUrl token rid re.eventId <| Just re.eventId _ -> Cmd.none