aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-07-20 19:25:51 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-07-20 19:26:28 +0200
commitcfe15ce7c3bf4bbd7e80d29fb708d5635c1ef001 (patch)
tree2068cbdd0673a5d5347441590b1087863ec0155f /lib
parent52beda703bd683944ce569c50bccde7ba9e5a0ac (diff)
downloadlibquotient-cfe15ce7c3bf4bbd7e80d29fb708d5635c1ef001.tar.gz
libquotient-cfe15ce7c3bf4bbd7e80d29fb708d5635c1ef001.zip
Promote read receipts/marker in addNewMessageEvents()
Read marker promotion worked before the rework - and it works again with this commit. Read receipts are promoted from anywhere, the fully read marker is only promoted if it's adjacent to the batch just added.
Diffstat (limited to 'lib')
-rw-r--r--lib/room.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index 49ce4c87..b3ece115 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -775,7 +775,8 @@ Room::Changes Room::Private::setFullyReadMarker(const QString& eventId)
return NoChange;
const auto prevFullyReadId = std::exchange(fullyReadUntilEventId, eventId);
- qCDebug(MESSAGES) << "Fully read marker moved to" << fullyReadUntilEventId;
+ qCDebug(MESSAGES) << "Fully read marker in" << q->objectName() //
+ << "moved to" << fullyReadUntilEventId;
emit q->readMarkerMoved(prevFullyReadId, fullyReadUntilEventId);
Changes changes = ReadMarkerChange;
@@ -954,7 +955,7 @@ void Room::setFirstDisplayedEventId(const QString& eventId)
if (d->firstDisplayedEventId == eventId)
return;
- if (findInTimeline(eventId) == historyEdge())
+ if (!eventId.isEmpty() && findInTimeline(eventId) == historyEdge())
qCWarning(MESSAGES)
<< eventId
<< "is marked as first displayed but doesn't seem to be loaded";
@@ -982,7 +983,7 @@ void Room::setLastDisplayedEventId(const QString& eventId)
return;
const auto marker = findInTimeline(eventId);
- if (marker == historyEdge())
+ if (!eventId.isEmpty() && marker == historyEdge())
qCWarning(MESSAGES)
<< eventId
<< "is marked as last displayed but doesn't seem to be loaded";
@@ -2387,15 +2388,20 @@ Room::Changes Room::Private::addNewMessageEvents(RoomEvents&& events)
<< timeline.back();
// The first event in the just-added batch (referred to by `from`)
- // defines whose read marker can possibly be promoted any further over
+ // defines whose read receipt can possibly be promoted any further over
// the same author's events newly arrived. Others will need explicit
// read receipts from the server - or, for the local user, calling
// setLastDisplayedEventId() - to promote their read receipts over
// the new message events.
if (auto* const firstWriter = q->user((*from)->senderId())) {
- const auto firstEventId = (*from)->id();
- if (lastReadEventIds.value(firstWriter) == firstEventId)
- setLastReadReceipt(firstWriter, rev_iter_t(from + 1));
+ setLastReadReceipt(firstWriter, rev_iter_t(from + 1));
+ if (firstWriter == q->localUser() && q->readMarker().base() == from) {
+ // If the local user's message(s) is/are first in the batch
+ // and the fully read marker was right before it, promote
+ // the fully read marker to the same event as the read receipt.
+ roomChanges |=
+ setFullyReadMarker(lastReadEventIds.value(firstWriter));
+ }
}
roomChanges |= updateUnreadCount(timeline.crbegin(), rev_iter_t(from));
}