aboutsummaryrefslogtreecommitdiff
path: root/room.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2016-10-23 19:08:41 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2016-10-23 19:08:41 +0900
commitcaaddebae6acf1a1c5281a5beba43782a8c899fc (patch)
tree48a35cbf8017efda88a4c16a3406662c1829b6cd /room.cpp
parent06a1131081e4f49a91f40ce00227104ebe6cd8fd (diff)
downloadlibquotient-caaddebae6acf1a1c5281a5beba43782a8c899fc.tar.gz
libquotient-caaddebae6acf1a1c5281a5beba43782a8c899fc.zip
Room: Don't let the read marker (of any user) get back, only forward
Diffstat (limited to 'room.cpp')
-rw-r--r--room.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/room.cpp b/room.cpp
index df230e38..c2a1ce70 100644
--- a/room.cpp
+++ b/room.cpp
@@ -169,10 +169,31 @@ void Room::setLastReadEvent(User* user, QString eventId)
emit lastReadEventChanged(user);
}
+bool Room::promoteReadMarker(User* user, QString eventId)
+{
+ // Check that the new read event is not before the previously set - only
+ // allow the read marker to move down the timeline, not up.
+ QString prevLastReadId = lastReadEvent(user);
+ // Older Qt doesn't provide rbegin()/rend() for Qt containers
+ for (auto it = messageEvents().end(); it != messageEvents().begin();)
+ {
+ --it;
+ if (prevLastReadId == (*it)->id())
+ return false;
+ if (eventId == (*it)->id())
+ {
+ setLastReadEvent(user, eventId);
+ return true;
+ }
+ }
+ return false;
+}
+
void Room::markMessagesAsRead(Timeline::const_iterator last)
{
QString prevLastReadId = lastReadEvent(connection()->user());
- setLastReadEvent(connection()->user(), (*last)->id());
+ if ( !promoteReadMarker(connection()->user(), (*last)->id()) )
+ return;
// We shouldn't send read receipts for messages from the local user - so
// shift back (if necessary) to the nearest message not from the local user
@@ -516,7 +537,7 @@ void Room::processEphemeralEvent(Event* event)
for( const Receipt& r: receipts )
{
if (auto m = d->member(r.userId))
- setLastReadEvent(m, eventId);
+ promoteReadMarker(m, eventId);
}
}
}