diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-12-08 15:37:16 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-12-08 20:12:27 +0900 |
commit | 9272d21ce6e5439444794e6da58e08421e8973db (patch) | |
tree | 736e4e165f910d52e30104abd4313786c065b966 /lib/syncdata.cpp | |
parent | 1ff8a0c26fc2738a085ca0302f0471ffa95a567e (diff) | |
download | libquotient-9272d21ce6e5439444794e6da58e08421e8973db.tar.gz libquotient-9272d21ce6e5439444794e6da58e08421e8973db.zip |
Room summaries
Diffstat (limited to 'lib/syncdata.cpp')
-rw-r--r-- | lib/syncdata.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/syncdata.cpp b/lib/syncdata.cpp index 1023ed6a..a5f849b3 100644 --- a/lib/syncdata.cpp +++ b/lib/syncdata.cpp @@ -34,10 +34,39 @@ inline EventsArrayT load(const QJsonObject& batches, StrT keyName) return fromJson<EventsArrayT>(batches[keyName].toObject().value("events"_ls)); } +void JsonObjectConverter<RoomSummary>::dumpTo(QJsonObject& jo, + const RoomSummary& rs) +{ + if (rs.joinedMemberCount != 0) + jo.insert(QStringLiteral("m.joined_member_count"), + rs.joinedMemberCount); + if (rs.invitedMemberCount != 0) + jo.insert(QStringLiteral("m.invited_member_count"), + rs.invitedMemberCount); + if (!rs.heroes.empty()) + jo.insert(QStringLiteral("m.heroes"), toJson(rs.heroes)); +} + +void JsonObjectConverter<RoomSummary>::fillFrom(const QJsonObject& jo, + RoomSummary& rs) +{ + rs.joinedMemberCount = fromJson<int>(jo["m.joined_member_count"_ls]); + rs.joinedMemberCount = fromJson<int>(jo["m.invited_member_count"_ls]); + rs.heroes = fromJson<QStringList>(jo["m.heroes"]); +} + +bool RoomSummary::operator==(const RoomSummary& other) const +{ + return joinedMemberCount == other.joinedMemberCount && + invitedMemberCount == other.invitedMemberCount && + heroes == other.heroes; +} + SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_, const QJsonObject& room_) : roomId(roomId_) , joinState(joinState_) + , summary(fromJson<RoomSummary>(room_["summary"].toObject())) , state(load<StateEvents>(room_, joinState == JoinState::Invite ? "invite_state"_ls : "state"_ls)) { |