From c9dc5e12b835425f1ba5c447ddb3c3394ccac93e Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 3 Oct 2017 16:16:38 +0900 Subject: Room: cache unread indicator inside m.read content, not next to it The CS API, turns out, has a quite official extension point inside m.read event content - clients are allowed to put whatever extra data they feel reasonable. --- events/receiptevent.cpp | 7 ++++++- room.cpp | 6 ++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/events/receiptevent.cpp b/events/receiptevent.cpp index 3d6be9f1..646bb989 100644 --- a/events/receiptevent.cpp +++ b/events/receiptevent.cpp @@ -66,6 +66,11 @@ ReceiptEvent::ReceiptEvent(const QJsonObject& obj) } _eventsWithReceipts.push_back({eventIt.key(), receipts}); } - _unreadMessages = obj["x-qmatrixclient.unread_messages"].toBool(); + static const auto UnreadMsgsKey = + QStringLiteral("x-qmatrixclient.unread_messages"); + if (contents.contains(UnreadMsgsKey)) + _unreadMessages = contents["x-qmatrixclient.unread_messages"].toBool(); + else + _unreadMessages = obj["x-qmatrixclient.unread_messages"].toBool(); } diff --git a/room.cpp b/room.cpp index 64ff8cd6..05b16b65 100644 --- a/room.cpp +++ b/room.cpp @@ -994,14 +994,12 @@ QJsonObject Room::Private::toJson() const QJsonObject lastReadEvent; lastReadEvent.insert(q->readMarkerEventId(), receipt); + lastReadEvent.insert("x-qmatrixclient.unread_messages", + unreadMessages); QJsonObject receiptsObj; receiptsObj.insert("type", QStringLiteral("m.receipt")); receiptsObj.insert("content", lastReadEvent); - // In extension of the spec we add a hint to the receipt event - // to allow setting the unread indicator without downloading - // and analysing the timeline. - receiptsObj.insert("x-qmatrixclient.unread_messages", unreadMessages); ephemeralEvents.append(receiptsObj); } -- cgit v1.2.3