diff --git a/imports/NeoChat/Page/RoomPage.qml b/imports/NeoChat/Page/RoomPage.qml index 7e3fc752d..6cd1fa57c 100644 --- a/imports/NeoChat/Page/RoomPage.qml +++ b/imports/NeoChat/Page/RoomPage.qml @@ -23,6 +23,7 @@ Kirigami.ScrollablePage { /// It's not readonly because of the seperate window view. property var currentRoom: RoomManager.currentRoom + property bool loading: page.currentRoom === null || (messageListView.count === 0 && !page.currentRoom.allHistoryLoaded && !page.currentRoom.isInvite) /// Used to determine if scrolling to the bottom should mark the message as unread property bool hasScrolledUpBefore: false; @@ -55,6 +56,25 @@ Kirigami.ScrollablePage { ChatBoxHelper.clearEditReply() } + Connections { + target: messageEventModel + function onRowsInserted() { + markReadIfVisibleTimer.restart() + } + } + + Timer { + id: markReadIfVisibleTimer + interval: 1000 + onTriggered: { + if (loading || !currentRoom.readMarkerLoaded || !applicationWindow().active) { + restart() + } else { + markReadIfVisible() + } + } + } + ActionsHandler { id: actionsHandler room: page.currentRoom @@ -123,7 +143,7 @@ Kirigami.ScrollablePage { Kirigami.PlaceholderMessage { id: loadingIndicator anchors.centerIn: parent - visible: page.currentRoom === null || (messageListView.count === 0 && !page.currentRoom.allHistoryLoaded && !page.currentRoom.isInvite) + visible: loading text: i18n("Loading…") QQC2.BusyIndicator { running: loadingIndicator.visible @@ -592,6 +612,14 @@ Kirigami.ScrollablePage { return index; } + // Mark all messages as read if all unread messages are visible to the user + function markReadIfVisible() { + let readMarkerRow = eventToIndex(currentRoom.readMarkerEventId) + if (readMarkerRow > 0 && readMarkerRow < firstVisibleIndex()) { + currentRoom.markAllMessagesAsRead() + } + } + /// Open message context dialog for file and videos function openFileContext(event, file) { const contextMenu = fileDelegateContextMenu.createObject(page, {