aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-08-01 17:22:42 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-08-09 22:29:23 +0200
commitc79dcb673b6f2888faa4b62cd53689fde9f7ea10 (patch)
tree41db1ba6d30f8cb577524ba4cacb884a29317d15
parent8093ea85347588431c0ddbf6e178a4db5f51b909 (diff)
downloadlibquotient-c79dcb673b6f2888faa4b62cd53689fde9f7ea10.tar.gz
libquotient-c79dcb673b6f2888faa4b62cd53689fde9f7ea10.zip
Room::toJson(): save the last local user's read receipt
Read receipts are entangled with counting unread messages, and saving them also helps in not sending receipts for too old events. Other users' read receipts are still treated as truly ephemeral.
-rw-r--r--lib/room.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index e7d4e137..1c84ece0 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -3003,6 +3003,32 @@ QJsonObject Room::Private::toJson() const
{ QStringLiteral("events"), accountDataEvents } });
}
+ if (const auto& readReceiptEventId =
+ lastReadReceipts.value(q->localUser()).eventId;
+ !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 } };