diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2016-11-07 13:08:13 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2016-11-07 13:08:13 +0900 |
commit | cb108696e62ffd54410297423b3aea0549ddcc84 (patch) | |
tree | 29d7034f8b204d988dc4955f1af02a43ab5b0433 /room.cpp | |
parent | 0b507b3683e6f4c6429c21f7dd71197dbec07a3d (diff) | |
download | libquotient-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.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -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); |