From c9ddd9d513953f17e9a7cd47105fb109a7852cbd Mon Sep 17 00:00:00 2001 From: James Graham Date: Fri, 24 May 2024 07:55:05 +0000 Subject: [PATCH] Improve the behaviour of jump to last unread message. Improve the behaviour of jump to last unread message. The view will now jump as high as possible if the last unread message isn't loaded. This at least triggers more items to load which will eventually get the user to the last unread message. --- src/neochatroom.cpp | 2 +- src/qml/TimelineView.qml | 14 ++++++++++++-- src/timeline/ReadMarkerDelegate.qml | 14 +++++++------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 868cdd78d..47c365a04 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -69,7 +69,7 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS setHasFileUploading(false); }); - connect(this, &Room::aboutToAddHistoricalMessages, this, &NeoChatRoom::readMarkerLoadedChanged); + connect(this, &Room::addedMessages, this, &NeoChatRoom::readMarkerLoadedChanged); const auto &roomLastMessageProvider = RoomLastMessageProvider::self(); diff --git a/src/qml/TimelineView.qml b/src/qml/TimelineView.qml index 070c49e75..1c136335b 100644 --- a/src/qml/TimelineView.qml +++ b/src/qml/TimelineView.qml @@ -190,12 +190,15 @@ QQC2.ScrollView { implicitHeight: Kirigami.Units.gridUnit * 2 z: 2 - visible: root.currentRoom && root.currentRoom.hasUnreadMessages && root.currentRoom.readMarkerLoaded + visible: root.currentRoom && root.currentRoom.hasUnreadMessages + + text: root.currentRoom.readMarkerLoaded ? i18n("Jump to first unread message") : i18n("Jump to oldest loaded message") action: Kirigami.Action { onTriggered: { if (!Kirigami.Settings.isMobile) { root.focusChatBar(); } + goReadMarkerFab.textChanged() messageListView.goToEvent(root.currentRoom.readMarkerEventId); } icon.name: "go-up" @@ -203,7 +206,10 @@ QQC2.ScrollView { } QQC2.ToolTip { - text: i18n("Jump to first unread message") + id: goReadMarkerFabTooltip + text: goReadMarkerFab.text + delay: Kirigami.Units.toolTipDelay + visible: goReadMarkerFab.hovered } } KirigamiComponents.FloatingButton { @@ -274,6 +280,10 @@ QQC2.ScrollView { function goToEvent(eventID) { const index = eventToIndex(eventID); + if (index == -1) { + messageListView.positionViewAtEnd(); + return; + } messageListView.positionViewAtIndex(index, ListView.Center); itemAtIndex(index).isTemporaryHighlighted = true; } diff --git a/src/timeline/ReadMarkerDelegate.qml b/src/timeline/ReadMarkerDelegate.qml index 2be95247c..df4d4ad3e 100644 --- a/src/timeline/ReadMarkerDelegate.qml +++ b/src/timeline/ReadMarkerDelegate.qml @@ -10,22 +10,22 @@ import org.kde.kirigami as Kirigami TimelineDelegate { id: root + + property bool isTemporaryHighlighted: false + onIsTemporaryHighlightedChanged: if (isTemporaryHighlighted) { + temporaryHighlightTimer.start(); + } + contentItem: QQC2.ItemDelegate { padding: Kirigami.Units.largeSpacing topInset: Kirigami.Units.largeSpacing topPadding: Kirigami.Units.largeSpacing * 2 - property bool isTemporaryHighlighted: false - - onIsTemporaryHighlightedChanged: if (isTemporaryHighlighted) { - temporaryHighlightTimer.start(); - } - Timer { id: temporaryHighlightTimer interval: 1500 - onTriggered: isTemporaryHighlighted = false + onTriggered: root.isTemporaryHighlighted = false } contentItem: QQC2.Label {