diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2016-10-23 19:08:41 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2016-10-23 19:08:41 +0900 |
commit | caaddebae6acf1a1c5281a5beba43782a8c899fc (patch) | |
tree | 48a35cbf8017efda88a4c16a3406662c1829b6cd /room.cpp | |
parent | 06a1131081e4f49a91f40ce00227104ebe6cd8fd (diff) | |
download | libquotient-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.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -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); } } } |