aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-02-23 10:50:03 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-02-23 10:50:03 +0900
commit76b1d775edae36dd2f36fdd4886c6c956bf6b49b (patch)
tree50e11ade4cd66eb62f455c266792683cc6e560cc
parent8fbbd6063a2d313c630d14842bbce4de8c1e7851 (diff)
downloadlibquotient-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.
-rw-r--r--events/roommemberevent.cpp10
-rw-r--r--events/roommemberevent.h11
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())