Improve the unread marker behaviour

The fixes include:
- improving the timer to make it more reliable
- making sure a read marker is added when changin rooms, this is needed when the messages have already been loaded.
- increase the default timer to 10s to avoid the read marker disappearing and being re-added when a message arrive in quick succession. 

BUG: 465300
This commit is contained in:
James Graham
2023-12-31 17:47:27 +00:00
parent 2d8ad834a7
commit e807ad9908
2 changed files with 18 additions and 11 deletions

View File

@@ -253,6 +253,12 @@ void MessageEventModel::setRoom(NeoChatRoom *room)
lastReadEventId.clear(); lastReadEventId.clear();
} }
endResetModel(); endResetModel();
// After reset put a read marker in if required.
// This is needed when changing back to a room that has already loaded messages.
if (room) {
moveReadMarker(m_currentRoom->lastFullyReadEventId());
}
} }
int MessageEventModel::refreshEvent(const QString &eventId) int MessageEventModel::refreshEvent(const QString &eventId)

View File

@@ -102,6 +102,7 @@ QQC2.ScrollView {
interval: 1000 interval: 1000
onTriggered: { onTriggered: {
root.roomChanging = false root.roomChanging = false
markReadIfVisibleTimer.reset()
} }
} }
onAtYEndChanged: if (!root.roomChanging) { onAtYEndChanged: if (!root.roomChanging) {
@@ -273,19 +274,19 @@ QQC2.ScrollView {
target: root.timelineModel target: root.timelineModel
function onRowsInserted() { function onRowsInserted() {
markReadIfVisibleTimer.restart() markReadIfVisibleTimer.reset()
} }
} }
Timer { Timer {
id: markReadIfVisibleTimer id: markReadIfVisibleTimer
interval: 1000 running: messageListView.allUnreadVisible() && applicationWindow().active && (root.currentRoom.timelineSize > 0 || root.currentRoom.allHistoryLoaded)
onTriggered: { interval: 10000
if (loading || !root.currentRoom.readMarkerLoaded || !applicationWindow().active) { onTriggered: root.currentRoom.markAllMessagesAsRead()
restart()
} else { function reset() {
messageListView.markReadIfVisible() restart()
} running = Qt.binding(function() { return messageListView.allUnreadVisible() && applicationWindow().active && (root.currentRoom.timelineSize > 0 || root.currentRoom.allHistoryLoaded) })
} }
} }
@@ -364,12 +365,12 @@ QQC2.ScrollView {
return index; return index;
} }
// Mark all messages as read if all unread messages are visible to the user function allUnreadVisible() {
function markReadIfVisible() {
let readMarkerRow = eventToIndex(root.currentRoom.readMarkerEventId) let readMarkerRow = eventToIndex(root.currentRoom.readMarkerEventId)
if (readMarkerRow >= 0 && readMarkerRow < firstVisibleIndex() && messageListView.atYEnd) { if (readMarkerRow >= 0 && readMarkerRow < firstVisibleIndex() && messageListView.atYEnd) {
root.currentRoom.markAllMessagesAsRead() return true
} }
return false
} }
function setHoverActionsToDelegate(delegate) { function setHoverActionsToDelegate(delegate) {