aboutsummaryrefslogtreecommitdiff
path: root/lib/room.cpp
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-09-08 05:47:10 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-10-10 22:27:26 +0200
commit5c0346f3a700e6af31463490b7af3382b86e09d5 (patch)
tree866b74b54dfda273954ddbb1c1bdf8696ecbe100 /lib/room.cpp
parent762be1e73d6f5021e63fc9a4fea273951b3fb113 (diff)
downloadlibquotient-5c0346f3a700e6af31463490b7af3382b86e09d5.tar.gz
libquotient-5c0346f3a700e6af31463490b7af3382b86e09d5.zip
Room: actually initialise read marker when needed
This fixes the `q->readMarker() != historyEdge()` assertion failure occuring in recalculateUnreadCount() when new events from sync arrive to a room with no read marker and all history loaded.
Diffstat (limited to 'lib/room.cpp')
-rw-r--r--lib/room.cpp31
1 files changed, 16 insertions, 15 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index a2b99039..ea8df286 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -686,23 +686,24 @@ Room::Changes Room::Private::updateUnreadCount(const rev_iter_t& from,
if (fullyReadMarker < from)
return NoChange; // What's arrived is already fully read
+ // If there's no read marker in the whole room, initialise it
if (fullyReadMarker == historyEdge() && q->allHistoryLoaded())
- --fullyReadMarker; // No read marker in the whole room, initialise it
- if (fullyReadMarker < to) {
- // Catch a special case when the last fully read event id refers to an
- // event that has just arrived. In this case we should recalculate
- // unreadMessages to get an exact number instead of an estimation
- // (see https://github.com/quotient-im/libQuotient/wiki/unread_count).
- // For the same reason (switching from the estimation to the exact
- // number) this branch always emits unreadMessagesChanged() and returns
- // UnreadNotifsChange, even if the estimation luckily matched the exact
- // result.
+ return setFullyReadMarker(timeline.front()->id());
+
+ // Catch a special case when the last fully read event id refers to an
+ // event that has just arrived. In this case we should recalculate
+ // unreadMessages to get an exact number instead of an estimation
+ // (see https://github.com/quotient-im/libQuotient/wiki/unread_count).
+ // For the same reason (switching from the estimation to the exact
+ // number) this branch always emits unreadMessagesChanged() and returns
+ // UnreadNotifsChange, even if the estimation luckily matched the exact
+ // result.
+ if (fullyReadMarker < to)
return recalculateUnreadCount(true);
- }
- // Fully read marker is somewhere beyond the most historical message from
- // the arrived batch - add up newly arrived messages to the current counter,
- // instead of a complete recalculation.
+ // At this point the fully read marker is somewhere beyond the "oldest"
+ // message from the arrived batch - add up newly arrived messages to
+ // the current counter, instead of a complete recalculation.
Q_ASSERT(to <= fullyReadMarker);
QElapsedTimer et;
@@ -769,7 +770,7 @@ Room::Changes Room::Private::setFullyReadMarker(const QString& eventId)
const auto prevFullyReadId = std::exchange(fullyReadUntilEventId, eventId);
qCDebug(MESSAGES) << "Fully read marker in" << q->objectName() //
- << "moved to" << fullyReadUntilEventId;
+ << "set to" << fullyReadUntilEventId;
emit q->fullyReadMarkerMoved(prevFullyReadId, fullyReadUntilEventId);
// TODO: Remove in 0.8
emit q->readMarkerMoved(prevFullyReadId, fullyReadUntilEventId);