diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-08-09 22:40:09 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-08-09 22:40:09 +0200 |
commit | f71dcc7571fe2d4e14e349a01bac474b2b8a553e (patch) | |
tree | c195cbd76150dd1de37bb9f33d629b6d9738e793 /lib | |
parent | 8398e7118503d51da431ba850812ec76d1976b67 (diff) | |
parent | b17867c2b74916055adbc158cdf6437b27bceb14 (diff) | |
download | libquotient-f71dcc7571fe2d4e14e349a01bac474b2b8a553e.tar.gz libquotient-f71dcc7571fe2d4e14e349a01bac474b2b8a553e.zip |
Merge branch 'kitsune-fix-read-receipts-markers-part3' into 0.6.x
Diffstat (limited to 'lib')
-rw-r--r-- | lib/room.cpp | 54 | ||||
-rw-r--r-- | lib/syncdata.cpp | 8 |
2 files changed, 48 insertions, 14 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index b461b0a1..029ff786 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -649,7 +649,8 @@ void Room::Private::setLastReadReceipt(User* u, rev_iter_t newMarker, return; // For Release builds } if (q->memberJoinState(u) != JoinState::Join) { - qCWarning(MAIN) << "Won't record read receipt for non-member" << u->id(); + qCWarning(EPHEMERAL) + << "Won't record read receipt for non-member" << u->id(); return; } @@ -657,8 +658,11 @@ void Room::Private::setLastReadReceipt(User* u, rev_iter_t newMarker, newMarker = q->findInTimeline(newEvtId); if (newMarker != historyEdge()) { // NB: with reverse iterators, timeline history >= sync edge - if (newMarker >= q->readMarker(u)) + if (newMarker >= q->readMarker(u)) { + qCDebug(EPHEMERAL) << "The new read receipt for" << u->id() + << "is at or behind the old one, skipping"; return; + } // Try to auto-promote the read marker over the user's own messages // (switch to direct iterators for that). @@ -680,6 +684,8 @@ void Room::Private::setLastReadReceipt(User* u, rev_iter_t newMarker, eventIdReadUsers.remove(storedId, u); eventIdReadUsers.insert(newEvtId, u); swap(storedId, newEvtId); // Now newEvtId actually stores the old eventId + qCDebug(EPHEMERAL) << "The new read receipt for" << u->id() << "is at" + << storedId; emit q->lastReadEventChanged(u); if (!isLocalUser(u)) emit q->readMarkerForUserMoved(u, newEvtId, storedId); @@ -937,11 +943,8 @@ void Room::setDisplayed(bool displayed) d->displayed = displayed; emit displayedChanged(displayed); - if (displayed) { - resetHighlightCount(); - resetNotificationCount(); + if (displayed) d->getAllMembers(); - } } QString Room::firstDisplayedEventId() const { return d->firstDisplayedEventId; } @@ -1561,11 +1564,21 @@ void Room::updateData(SyncRoomData&& data, bool fromCache) emit unreadMessagesChanged(this); } - if (data.highlightCount != d->highlightCount) { + // Similar to unreadCount, SyncRoomData constructor assigns -1 to + // highlightCount/notificationCount when those are missing in the payload + if (data.highlightCount != -1 && data.highlightCount != d->highlightCount) { + qCDebug(MESSAGES).nospace() + << "Highlights in " << objectName() // + << ": " << d->highlightCount << " -> " << data.highlightCount; d->highlightCount = data.highlightCount; emit highlightCountChanged(); } - if (data.notificationCount != d->notificationCount) { + if (data.notificationCount != -1 + && data.notificationCount != d->notificationCount) // + { + qCDebug(MESSAGES).nospace() + << "Notifications in " << objectName() // + << ": " << d->notificationCount << " -> " << data.notificationCount; d->notificationCount = data.notificationCount; emit notificationCountChanged(); } @@ -2907,6 +2920,31 @@ QJsonObject Room::Private::toJson() const { QStringLiteral("events"), accountDataEvents } }); } + if (const auto& readReceiptEventId = lastReadEventIds.value(q->localUser()); + !readReceiptEventId.isEmpty()) // + { + // Okay, that's a mouthful; but basically, it's simply placing an m.read + // event in the 'ephemeral' section of the cached sync payload. + // See also receiptevent.* and m.read example in the spec. + // Only the local user's read receipt is saved - others' are really + // considered ephemeral but this one is useful in understanding where + // the user is in the timeline before any history is loaded. + result.insert( + QStringLiteral("ephemeral"), + QJsonObject { + { QStringLiteral("events"), + QJsonArray { QJsonObject { + { TypeKey, ReceiptEvent::matrixTypeId() }, + { ContentKey, + QJsonObject { + { readReceiptEventId, + QJsonObject { + { QStringLiteral("m.read"), + QJsonObject { + { connection->userId(), + QJsonObject {} } } } } } } } } } } }); + } + QJsonObject unreadNotifObj { { SyncRoomData::UnreadCountKey, unreadMessages } }; diff --git a/lib/syncdata.cpp b/lib/syncdata.cpp index 64aa65fd..70c4a15f 100644 --- a/lib/syncdata.cpp +++ b/lib/syncdata.cpp @@ -106,12 +106,8 @@ SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_, const auto unreadJson = room_.value("unread_notifications"_ls).toObject(); unreadCount = unreadJson.value(UnreadCountKey).toInt(-2); - highlightCount = unreadJson.value("highlight_count"_ls).toInt(); - notificationCount = unreadJson.value("notification_count"_ls).toInt(); - if (highlightCount > 0 || notificationCount > 0) - qCDebug(SYNCJOB) << "Room" << roomId_ - << "has highlights:" << highlightCount - << "and notifications:" << notificationCount; + highlightCount = unreadJson.value("highlight_count"_ls).toInt(-1); + notificationCount = unreadJson.value("notification_count"_ls).toInt(-1); } SyncData::SyncData(const QString& cacheFileName) |