diff options
-rw-r--r-- | events/roommemberevent.cpp | 10 | ||||
-rw-r--r-- | events/roommemberevent.h | 11 |
2 files changed, 16 insertions, 5 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()); } diff --git a/events/roommemberevent.h b/events/roommemberevent.h index 224f29c2..b9ff0d70 100644 --- a/events/roommemberevent.h +++ b/events/roommemberevent.h @@ -29,9 +29,13 @@ namespace QMatrixClient class MemberEventContent: public EventContent::Base { public: - enum MembershipType : size_t {Invite = 0, Join, Knock, Leave, Ban}; + enum MembershipType : size_t { Invite = 0, Join, Knock, Leave, Ban, + Undefined }; - MemberEventContent(const QJsonObject& json); + explicit MemberEventContent(MembershipType mt = MembershipType::Join) + : membership(mt) + { } + explicit MemberEventContent(const QJsonObject& json); MembershipType membership; QString displayName; @@ -51,6 +55,9 @@ namespace QMatrixClient using MembershipType = MemberEventContent::MembershipType; + RoomMemberEvent(MemberEventContent&& c) + : StateEvent(Type::RoomMember, c) + { } explicit RoomMemberEvent(const QJsonObject& obj) : StateEvent(Type::RoomMember, obj) // , _userId(obj["state_key"].toString()) |