aboutsummaryrefslogtreecommitdiff
path: root/room.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2016-11-07 13:08:13 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2016-11-07 13:08:13 +0900
commitcb108696e62ffd54410297423b3aea0549ddcc84 (patch)
tree29d7034f8b204d988dc4955f1af02a43ab5b0433 /room.cpp
parent0b507b3683e6f4c6429c21f7dd71197dbec07a3d (diff)
downloadlibquotient-cb108696e62ffd54410297423b3aea0549ddcc84.tar.gz
libquotient-cb108696e62ffd54410297423b3aea0549ddcc84.zip
Room::doAddNewMessages: Extend auto-promotion to all users, not only local
Thanks to @maralorn for pointing out.
Diffstat (limited to 'room.cpp')
-rw-r--r--room.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/room.cpp b/room.cpp
index 3d2e88c9..6c33cc58 100644
--- a/room.cpp
+++ b/room.cpp
@@ -505,19 +505,35 @@ void Room::doAddNewMessageEvents(const Events& events)
{
d->messageEvents.reserve(d->messageEvents.size() + events.size());
- int newMessages = 0;
- Event* latestLocalEventBeforeUnread = nullptr;
+ Timeline::size_type newUnreadMessages = 0;
+
+ // The first message in the batch defines whose read marker we can
+ // automatically promote any further. Others will need explicit read receipts
+ // from the server (or, for the local user, markMessagesAsRead() invocation)
+ // to promote their read markers over the new message events.
+ User* firstWriter = d->member(events.front()->senderId());
+ bool canAutoPromote = d->messageEvents.empty() ||
+ lastReadEvent(firstWriter) == d->messageEvents.back()->id();
+ Event* firstWriterSeriesEnd = canAutoPromote ? events.front() : nullptr;
+
for (auto e: events)
{
d->messageEvents.push_back(e);
- newMessages += d->isEventNotable(e);
- if (!newMessages && e->senderId() == connection()->userId())
- latestLocalEventBeforeUnread = e;
+
+ newUnreadMessages += d->isEventNotable(e);
+ if (firstWriterSeriesEnd)
+ {
+ if (e->senderId() != firstWriter->id())
+ firstWriterSeriesEnd = e;
+ else
+ {
+ setLastReadEvent(firstWriter, firstWriterSeriesEnd->id());
+ firstWriterSeriesEnd = nullptr;
+ }
+ }
}
- if (latestLocalEventBeforeUnread)
- setLastReadEvent(d->connection->user(), latestLocalEventBeforeUnread->id());
- if( !d->unreadMessages && newMessages > 0)
+ if( !d->unreadMessages && newUnreadMessages > 0)
{
d->unreadMessages = true;
emit unreadMessagesChanged(this);