diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-08-01 17:22:42 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-08-01 17:22:42 +0200 |
commit | e4a8251d90c2e9f2847366085b3a2897a2d02201 (patch) | |
tree | d4f748eca38c4af1d90fdd5bef858dc5b26166fd | |
parent | 000710d2c78b0843d920b7cf983f693a3ddf193e (diff) | |
download | libquotient-e4a8251d90c2e9f2847366085b3a2897a2d02201.tar.gz libquotient-e4a8251d90c2e9f2847366085b3a2897a2d02201.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.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/room.cpp b/lib/room.cpp index a643ed68..7242c32e 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -2923,6 +2923,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 } }; |