aboutsummaryrefslogtreecommitdiff
path: root/lib/syncdata.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/syncdata.cpp')
-rw-r--r--lib/syncdata.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/syncdata.cpp b/lib/syncdata.cpp
index 1023ed6a..f55d4396 100644
--- a/lib/syncdata.cpp
+++ b/lib/syncdata.cpp
@@ -28,6 +28,53 @@ using namespace QMatrixClient;
const QString SyncRoomData::UnreadCountKey =
QStringLiteral("x-qmatrixclient.unread_count");
+bool RoomSummary::isEmpty() const
+{
+ return joinedMemberCount.omitted() && invitedMemberCount.omitted() &&
+ heroes.omitted();
+}
+
+bool RoomSummary::merge(const RoomSummary& other)
+{
+ // Using bitwise OR to prevent computation shortcut.
+ return
+ joinedMemberCount.merge(other.joinedMemberCount) |
+ invitedMemberCount.merge(other.invitedMemberCount) |
+ heroes.merge(other.heroes);
+}
+
+QDebug QMatrixClient::operator<<(QDebug dbg, const RoomSummary& rs)
+{
+ QDebugStateSaver _(dbg);
+ QStringList sl;
+ if (!rs.joinedMemberCount.omitted())
+ sl << QStringLiteral("joined: %1").arg(rs.joinedMemberCount.value());
+ if (!rs.invitedMemberCount.omitted())
+ sl << QStringLiteral("invited: %1").arg(rs.invitedMemberCount.value());
+ if (!rs.heroes.omitted())
+ sl << QStringLiteral("heroes: [%1]").arg(rs.heroes.value().join(','));
+ dbg.nospace().noquote() << sl.join(QStringLiteral("; "));
+ return dbg;
+}
+
+void JsonObjectConverter<RoomSummary>::dumpTo(QJsonObject& jo,
+ const RoomSummary& rs)
+{
+ addParam<IfNotEmpty>(jo, QStringLiteral("m.joined_member_count"),
+ rs.joinedMemberCount);
+ addParam<IfNotEmpty>(jo, QStringLiteral("m.invited_member_count"),
+ rs.invitedMemberCount);
+ addParam<IfNotEmpty>(jo, QStringLiteral("m.heroes"), rs.heroes);
+}
+
+void JsonObjectConverter<RoomSummary>::fillFrom(const QJsonObject& jo,
+ RoomSummary& rs)
+{
+ fromJson(jo["m.joined_member_count"_ls], rs.joinedMemberCount);
+ fromJson(jo["m.invited_member_count"_ls], rs.invitedMemberCount);
+ fromJson(jo["m.heroes"], rs.heroes);
+}
+
template <typename EventsArrayT, typename StrT>
inline EventsArrayT load(const QJsonObject& batches, StrT keyName)
{
@@ -38,6 +85,7 @@ SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_,
const QJsonObject& room_)
: roomId(roomId_)
, joinState(joinState_)
+ , summary(fromJson<RoomSummary>(room_["summary"]))
, state(load<StateEvents>(room_, joinState == JoinState::Invite
? "invite_state"_ls : "state"_ls))
{