diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-02-23 10:50:03 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-02-23 10:50:03 +0900 |
commit | 76b1d775edae36dd2f36fdd4886c6c956bf6b49b (patch) | |
tree | 50e11ade4cd66eb62f455c266792683cc6e560cc /events/roommemberevent.cpp | |
parent | 8fbbd6063a2d313c630d14842bbce4de8c1e7851 (diff) | |
download | libquotient-76b1d775edae36dd2f36fdd4886c6c956bf6b49b.tar.gz libquotient-76b1d775edae36dd2f36fdd4886c6c956bf6b49b.zip |
RoomMemberEvent: make it sendable
To do that, both RoomMemberEvent and MemberEventContent got respective constructors.
Also: the fallback value for unknown _received_ membership types is now Undefined; it's not allowed in member events for sending (will fail on assertion now) because the server requires membership to be explicitly set.
Diffstat (limited to 'events/roommemberevent.cpp')
-rw-r--r-- | events/roommemberevent.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/events/roommemberevent.cpp b/events/roommemberevent.cpp index 76df5f2e..a9e301a4 100644 --- a/events/roommemberevent.cpp +++ b/events/roommemberevent.cpp @@ -44,7 +44,7 @@ namespace QMatrixClient return MembershipType(it - membershipStrings.begin()); qCWarning(EVENTS) << "Unknown MembershipType: " << membershipString; - return MembershipType::Join; + return MembershipType::Undefined; } }; } @@ -58,7 +58,11 @@ MemberEventContent::MemberEventContent(const QJsonObject& json) void MemberEventContent::fillJson(QJsonObject* o) const { Q_ASSERT(o); - o->insert("membership", membershipStrings[membership]); + Q_ASSERT_X(membership != MembershipType::Undefined, __FUNCTION__, + "The key 'membership' must be explicit in MemberEventContent"); + if (membership != MembershipType::Undefined) + o->insert("membership", membershipStrings[membership]); o->insert("displayname", displayName); - o->insert("avatar_url", avatarUrl.toString()); + if (avatarUrl.isValid()) + o->insert("avatar_url", avatarUrl.toString()); } |