From 64c0b7e045d9e8d58d91f252219a5579d4ba9441 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 1 Nov 2017 17:51:47 +0300 Subject: Add TypeId to more events --- events/roommemberevent.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'events/roommemberevent.h') diff --git a/events/roommemberevent.h b/events/roommemberevent.h index 9ebb75ee..358af257 100644 --- a/events/roommemberevent.h +++ b/events/roommemberevent.h @@ -28,6 +28,8 @@ namespace QMatrixClient { Q_GADGET public: + static constexpr const char* TypeId = "m.room.member"; + enum MembershipType : int {Invite = 0, Join, Knock, Leave, Ban}; explicit RoomMemberEvent(const QJsonObject& obj); -- cgit v1.2.3 From 08fda4edfb1753aff148a664d623aa2497621965 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 1 Nov 2017 21:01:25 +0300 Subject: Imbue RoomMemberEvent with EventContent It now allows to check what exactly has happened to the member (display name change, joining, avatar update), fixing #105. --- events/roommemberevent.h | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'events/roommemberevent.h') diff --git a/events/roommemberevent.h b/events/roommemberevent.h index 358af257..d0c63f15 100644 --- a/events/roommemberevent.h +++ b/events/roommemberevent.h @@ -20,32 +20,49 @@ #include "event.h" +#include "eventcontent.h" + #include namespace QMatrixClient { - class RoomMemberEvent: public RoomEvent + class MemberEventContent: public EventContent::Base + { + public: + enum MembershipType : size_t {Invite = 0, Join, Knock, Leave, Ban}; + + MemberEventContent(const QJsonObject& json); + + MembershipType membership; + QString displayName; + QUrl avatarUrl; + + protected: + void fillJson(QJsonObject* o) const override; + }; + + using MembershipType = MemberEventContent::MembershipType; + + class RoomMemberEvent: public StateEvent { Q_GADGET public: static constexpr const char* TypeId = "m.room.member"; - enum MembershipType : int {Invite = 0, Join, Knock, Leave, Ban}; + using MembershipType = MemberEventContent::MembershipType; - explicit RoomMemberEvent(const QJsonObject& obj); + explicit RoomMemberEvent(const QJsonObject& obj) + : StateEvent(Type::RoomMember, obj) + , _userId(obj["state_key"].toString()) + { } - MembershipType membership() const { return _membership; } - const QString& userId() const { return _userId; } - const QString& displayName() const { return _displayName; } - const QUrl& avatarUrl() const { return _avatarUrl; } + MembershipType membership() const { return content().membership; } + QString userId() const { return _userId; } + QString displayName() const { return content().displayName; } + QUrl avatarUrl() const { return content().avatarUrl; } private: - MembershipType _membership; QString _userId; - QString _displayName; - QUrl _avatarUrl; - REGISTER_ENUM(MembershipType) }; - using MembershipType = RoomMemberEvent::MembershipType; } // namespace QMatrixClient -- cgit v1.2.3