aboutsummaryrefslogtreecommitdiff
path: root/room.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'room.cpp')
-rw-r--r--room.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/room.cpp b/room.cpp
index 85953a5c..1a6b055d 100644
--- a/room.cpp
+++ b/room.cpp
@@ -119,6 +119,8 @@ class Room::Private
void setLastReadEvent(User* u, const QString& eventId);
rev_iter_pair_t promoteReadMarker(User* u, rev_iter_t newMarker);
+ QJsonObject toJson() const;
+
private:
QString calculateDisplayname() const;
QString roomNameFromMemberNames(const QList<User*>& userlist) const;
@@ -799,6 +801,8 @@ void Room::processEphemeralEvent(Event* event)
d->setLastReadEvent(m, p.evtId);
}
}
+ if (receiptEvent->unreadMessages())
+ d->unreadMessages = true;
break;
}
default:
@@ -886,6 +890,95 @@ void Room::Private::updateDisplayname()
emit q->displaynameChanged(q);
}
+QJsonObject stateEventToJson(const QString& type, const QString& name,
+ const QJsonValue& content)
+{
+ QJsonObject contentObj;
+ contentObj.insert(name, content);
+
+ QJsonObject eventObj;
+ eventObj.insert("type", type);
+ eventObj.insert("content", contentObj);
+
+ return eventObj;
+}
+
+QJsonObject Room::Private::toJson() const
+{
+ QJsonObject result;
+ {
+ QJsonArray stateEvents;
+
+ stateEvents.append(stateEventToJson("m.room.name", "name", name));
+ stateEvents.append(stateEventToJson("m.room.topic", "topic", topic));
+ stateEvents.append(stateEventToJson("m.room.aliases", "aliases",
+ QJsonArray::fromStringList(aliases)));
+ stateEvents.append(stateEventToJson("m.room.canonical_alias", "alias",
+ canonicalAlias));
+
+ for (const auto &i : membersMap)
+ {
+ QJsonObject content;
+ content.insert("membership", QStringLiteral("join"));
+ content.insert("displayname", i->displayname());
+ // avatar URL is not available
+
+ QJsonObject memberEvent;
+ memberEvent.insert("type", QStringLiteral("m.room.member"));
+ memberEvent.insert("state_key", i->id());
+ memberEvent.insert("content", content);
+ stateEvents.append(memberEvent);
+ }
+
+ QJsonObject roomStateObj;
+ roomStateObj.insert("events", stateEvents);
+
+ result.insert("state", roomStateObj);
+ }
+
+ if (!q->readMarkerEventId().isEmpty())
+ {
+ QJsonArray ephemeralEvents;
+ {
+ // Don't dump the timestamp because it's useless in the cache.
+ QJsonObject user;
+ user.insert(connection->userId(), {});
+
+ QJsonObject receipt;
+ receipt.insert("m.read", user);
+
+ QJsonObject lastReadEvent;
+ lastReadEvent.insert(q->readMarkerEventId(), receipt);
+
+ 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);
+ }
+
+ QJsonObject ephemeralObj;
+ ephemeralObj.insert("events", ephemeralEvents);
+
+ result.insert("ephemeral", ephemeralObj);
+ }
+
+ QJsonObject unreadNotificationsObj;
+ unreadNotificationsObj.insert("highlight_count", highlightCount);
+ unreadNotificationsObj.insert("notification_count", notificationCount);
+ result.insert("unread_notifications", unreadNotificationsObj);
+
+ return result;
+}
+
+QJsonObject Room::toJson() const
+{
+ return d->toJson();
+}
+
MemberSorter Room::memberSorter() const
{
return MemberSorter(this);