aboutsummaryrefslogtreecommitdiff
path: root/lib/syncdata.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-12-08 22:42:25 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-12-09 19:45:51 +0900
commitd51684b759f686b2c9895c5013dce88fead9661b (patch)
treed5fe7d6e3e01edabfa11b95f6fd04c802d4335c5 /lib/syncdata.cpp
parent4a252aa465c7a36268e8014674800e6d98a449e9 (diff)
downloadlibquotient-d51684b759f686b2c9895c5013dce88fead9661b.tar.gz
libquotient-d51684b759f686b2c9895c5013dce88fead9661b.zip
MSC 688: MSC-compliant RoomSummary; update Room::calculateDisplayname()
The members of the summary can be omitted in the payload; this change fixes calculation of the roomname from hero names passed in room summary. Also: RoomSummary can be dumped to QDebug now.
Diffstat (limited to 'lib/syncdata.cpp')
-rw-r--r--lib/syncdata.cpp57
1 files changed, 38 insertions, 19 deletions
diff --git a/lib/syncdata.cpp b/lib/syncdata.cpp
index a5f849b3..f55d4396 100644
--- a/lib/syncdata.cpp
+++ b/lib/syncdata.cpp
@@ -28,45 +28,64 @@ using namespace QMatrixClient;
const QString SyncRoomData::UnreadCountKey =
QStringLiteral("x-qmatrixclient.unread_count");
-template <typename EventsArrayT, typename StrT>
-inline EventsArrayT load(const QJsonObject& batches, StrT keyName)
+bool RoomSummary::isEmpty() const
{
- return fromJson<EventsArrayT>(batches[keyName].toObject().value("events"_ls));
+ 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)
{
- 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));
+ 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)
{
- 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"]);
+ fromJson(jo["m.joined_member_count"_ls], rs.joinedMemberCount);
+ fromJson(jo["m.invited_member_count"_ls], rs.invitedMemberCount);
+ fromJson(jo["m.heroes"], rs.heroes);
}
-bool RoomSummary::operator==(const RoomSummary& other) const
+template <typename EventsArrayT, typename StrT>
+inline EventsArrayT load(const QJsonObject& batches, StrT keyName)
{
- return joinedMemberCount == other.joinedMemberCount &&
- invitedMemberCount == other.invitedMemberCount &&
- heroes == other.heroes;
+ return fromJson<EventsArrayT>(batches[keyName].toObject().value("events"_ls));
}
SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_,
const QJsonObject& room_)
: roomId(roomId_)
, joinState(joinState_)
- , summary(fromJson<RoomSummary>(room_["summary"].toObject()))
+ , summary(fromJson<RoomSummary>(room_["summary"]))
, state(load<StateEvents>(room_, joinState == JoinState::Invite
? "invite_state"_ls : "state"_ls))
{