aboutsummaryrefslogtreecommitdiff
path: root/room.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2016-10-21 12:51:01 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2016-10-21 12:52:49 +0900
commitc8700b59d00d505c59de51d8dc259454073123e3 (patch)
treeeed310f8e41aceda5e3a916de5641b69cedddbae /room.cpp
parent372ed74c04f2c542451771aa792242a4e2afb351 (diff)
downloadlibquotient-c8700b59d00d505c59de51d8dc259454073123e3.tar.gz
libquotient-c8700b59d00d505c59de51d8dc259454073123e3.zip
Room::markMessagesAsRead correctly handles local user's messages now
setLastReadEvent() is called in any case (read marks a stored in a hashmap so it's a constant time operation anyway); postReceipt() is now called for the nearest previous non-local message.
Diffstat (limited to 'room.cpp')
-rw-r--r--room.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/room.cpp b/room.cpp
index 5181fb2a..674f0343 100644
--- a/room.cpp
+++ b/room.cpp
@@ -169,11 +169,32 @@ void Room::setLastReadEvent(User* user, QString eventId)
emit lastReadEventChanged(user);
}
-void Room::markMessageAsRead(Event* event)
+void Room::markMessagesAsRead(Timeline::const_iterator end)
{
- setLastReadEvent(connection()->user(), event->id());
- if (event->senderId() != connection()->userId())
- d->connection->postReceipt(this, event);
+ if (messageEvents().empty())
+ return;
+
+ QString prevLastReadId = lastReadEvent(connection()->user());
+ setLastReadEvent(connection()->user(), (*--end)->id());
+
+ // 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
+ // or the so far last read message, whichever comes first.
+ for (; (*end)->id() != prevLastReadId; --end)
+ {
+ if ((*end)->senderId() != connection()->userId())
+ {
+ d->connection->postReceipt(this, (*end));
+ break;
+ }
+ if (end == messageEvents().begin())
+ break;
+ }
+}
+
+void Room::markMessagesAsRead()
+{
+ markMessagesAsRead(messageEvents().end());
}
QString Room::lastReadEvent(User* user)