From c2398b19dc081cf2fb955b3e51b34993c6825f1a Mon Sep 17 00:00:00 2001 From: James Graham Date: Sat, 5 Aug 2023 17:38:21 +0000 Subject: [PATCH] Fix mark all read on room change Fix it so that the view is correctly positioned at the bottom when the room is changed and make sure this is not seen as a scroll event (i.e. messages are not automatically marked as read but the timer has to time out first and all visible on screen). --- src/qml/Component/TimelineView.qml | 28 ++++++++++++++++++++-------- src/qml/Page/RoomPage.qml | 8 -------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/qml/Component/TimelineView.qml b/src/qml/Component/TimelineView.qml index cc87d05aa..1a85e02c4 100644 --- a/src/qml/Component/TimelineView.qml +++ b/src/qml/Component/TimelineView.qml @@ -16,9 +16,19 @@ import org.kde.neochat 1.0 QQC2.ScrollView { id: root required property NeoChatRoom currentRoom - readonly property bool isLoaded: root.width * root.height > 10 + onCurrentRoomChanged: { + roomChanging = true; + applicationWindow().hoverLinkIndicator.text = ""; + messageListView.positionViewAtBeginning(); + hasScrolledUpBefore = false; + roomChanging = true; + } + property bool roomChanging: false readonly property bool atYEnd: messageListView.atYEnd + /// Used to determine if scrolling to the bottom should mark the message as unread + property bool hasScrolledUpBefore: false; + signal focusChatBox() ListView { @@ -38,7 +48,7 @@ QQC2.ScrollView { interactive: Kirigami.Settings.isMobile bottomMargin: Kirigami.Units.largeSpacing + Math.round(Kirigami.Theme.defaultFont.pointSize * 2) - model: !isLoaded ? undefined : collapseStateProxyModel + model: collapseStateProxyModel MessageEventModel { id: messageEventModel @@ -70,13 +80,15 @@ QQC2.ScrollView { messageEventModel.fetchMore(messageEventModel.index(0, 0)); } - onAtYEndChanged: if (atYEnd && hasScrolledUpBefore) { - if (QQC2.ApplicationWindow.window && (QQC2.ApplicationWindow.window.visibility !== QQC2.ApplicationWindow.Hidden)) { - root.currentRoom.markAllMessagesAsRead(); + onAtYEndChanged: if (!root.roomChanging) { + if (atYEnd && root.hasScrolledUpBefore) { + if (QQC2.ApplicationWindow.window && (QQC2.ApplicationWindow.window.visibility !== QQC2.ApplicationWindow.Hidden)) { + root.currentRoom.markAllMessagesAsRead(); + } + root.hasScrolledUpBefore = false; + } else if (!atYEnd) { + root.hasScrolledUpBefore = true; } - hasScrolledUpBefore = false; - } else if (!atYEnd) { - hasScrolledUpBefore = true; } // Not rendered because the sections are part of the TimelineContainer.qml, this is only so that items have the section property available for use by sectionBanner. diff --git a/src/qml/Page/RoomPage.qml b/src/qml/Page/RoomPage.qml index 4fafa3ba7..bb4430a6a 100644 --- a/src/qml/Page/RoomPage.qml +++ b/src/qml/Page/RoomPage.qml @@ -19,8 +19,6 @@ Kirigami.Page { /// Not readonly because of the separate window view. property NeoChatRoom currentRoom: RoomManager.currentRoom property bool loading: !root.currentRoom || (root.currentRoom.timelineSize === 0 && !root.currentRoom.allHistoryLoaded) - /// Used to determine if scrolling to the bottom should mark the message as unread - property bool hasScrolledUpBefore: false; /// Disable cancel shortcut. Used by the separate window since it provides its own cancel implementation. property bool disableCancelShortcut: false @@ -32,12 +30,6 @@ Kirigami.Page { KeyNavigation.left: pageStack.get(0) onCurrentRoomChanged: { - if (!timelineViewLoader.item) { - return - } - applicationWindow().hoverLinkIndicator.text = ""; - timelineViewLoader.item.positionViewAtBeginning(); - hasScrolledUpBefore = false; if (!Kirigami.Settings.isMobile && chatBoxLoader.item) { chatBoxLoader.item.forceActiveFocus(); }