diff options
-rw-r--r-- | room.cpp | 18 | ||||
-rw-r--r-- | room.h | 5 |
2 files changed, 11 insertions, 12 deletions
@@ -169,32 +169,30 @@ void Room::setLastReadEvent(User* user, QString eventId) emit lastReadEventChanged(user); } -void Room::markMessagesAsRead(Timeline::const_iterator end) +void Room::markMessagesAsRead(Timeline::const_iterator last) { - if (messageEvents().empty()) - return; - QString prevLastReadId = lastReadEvent(connection()->user()); - setLastReadEvent(connection()->user(), (*--end)->id()); + setLastReadEvent(connection()->user(), (*last)->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) + for (; (*last)->id() != prevLastReadId; --last) { - if ((*end)->senderId() != connection()->userId()) + if ((*last)->senderId() != connection()->userId()) { - d->connection->postReceipt(this, (*end)); + d->connection->postReceipt(this, (*last)); break; } - if (end == messageEvents().begin()) + if (last == messageEvents().begin()) break; } } void Room::markMessagesAsRead() { - markMessagesAsRead(messageEvents().end()); + if (!messageEvents().empty()) + markMessagesAsRead(messageEvents().end() - 1); } QString Room::lastReadEvent(User* user) @@ -70,7 +70,6 @@ namespace QMatrixClient Q_INVOKABLE void setJoinState( JoinState state ); Q_INVOKABLE QString lastReadEvent(User* user); - Q_INVOKABLE void setLastReadEvent(User* user, QString eventId); /** * @brief Mark the message at the iterator as read * @@ -78,7 +77,7 @@ namespace QMatrixClient * receipt to the server either for this message or, if it's from * the local user, for the nearest non-local message before. */ - Q_INVOKABLE void markMessagesAsRead(Timeline::const_iterator iter); + Q_INVOKABLE void markMessagesAsRead(Timeline::const_iterator last); /** * @brief Mark the most recent message in the timeline as read * @@ -125,6 +124,8 @@ namespace QMatrixClient virtual void processStateEvents(const Events& events); virtual void processEphemeralEvent(Event* event); + void setLastReadEvent(User* user, QString eventId); + private: class Private; Private* d; |