diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-04 21:34:00 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-04 21:34:00 +0900 |
commit | 6a9de91752dfe75e185bf90ab856367b2c804582 (patch) | |
tree | 2a12ecc84bf0055e317ef2e4aeec3439d92b2035 /lib/events/roommemberevent.h | |
parent | d5397fe5ae2ca34d5cfb11394dac17728a2b50ce (diff) | |
parent | 5d1dd53890611376873f6f959e206d5a56cfff70 (diff) | |
download | libquotient-6a9de91752dfe75e185bf90ab856367b2c804582.tar.gz libquotient-6a9de91752dfe75e185bf90ab856367b2c804582.zip |
Merge branch 'kitsune-events-rewritten'
Diffstat (limited to 'lib/events/roommemberevent.h')
-rw-r--r-- | lib/events/roommemberevent.h | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/events/roommemberevent.h b/lib/events/roommemberevent.h index 8e0cc0a4..f3e4f53a 100644 --- a/lib/events/roommemberevent.h +++ b/lib/events/roommemberevent.h @@ -18,12 +18,9 @@ #pragma once -#include "event.h" - +#include "stateevent.h" #include "eventcontent.h" -#include <QtCore/QUrl> - namespace QMatrixClient { class MemberEventContent: public EventContent::Base @@ -36,6 +33,9 @@ namespace QMatrixClient : membership(mt) { } explicit MemberEventContent(const QJsonObject& json); + explicit MemberEventContent(const QJsonValue& jv) + : MemberEventContent(jv.toObject()) + { } MembershipType membership; bool isDirect = false; @@ -52,23 +52,26 @@ namespace QMatrixClient { Q_GADGET public: - static constexpr const char* typeId() { return "m.room.member"; } + DEFINE_EVENT_TYPEID("m.room.member", RoomMemberEvent) using MembershipType = MemberEventContent::MembershipType; - explicit RoomMemberEvent(Type type, const QJsonObject& obj) - : StateEvent(type, obj) + explicit RoomMemberEvent(const QJsonObject& obj) + : StateEvent(typeId(), obj) { } RoomMemberEvent(MemberEventContent&& c) - : StateEvent(Type::RoomMember, c) + : StateEvent(typeId(), matrixTypeId(), c.toJson()) { } - explicit RoomMemberEvent(const QJsonObject& obj) - : RoomMemberEvent(Type::RoomMember, obj) + + // This is a special constructor enabling RoomMemberEvent to be + // a base class for more specific member events. + RoomMemberEvent(Type type, const QJsonObject& fullJson) + : StateEvent(type, fullJson) { } MembershipType membership() const { return content().membership; } QString userId() const - { return originalJsonObject().value("state_key").toString(); } + { return fullJson()["state_key"_ls].toString(); } bool isDirect() const { return content().isDirect; } QString displayName() const { return content().displayName; } QUrl avatarUrl() const { return content().avatarUrl; } @@ -76,4 +79,6 @@ namespace QMatrixClient private: REGISTER_ENUM(MembershipType) }; + REGISTER_EVENT_TYPE(RoomMemberEvent) + DEFINE_EVENTTYPE_ALIAS(RoomMember, RoomMemberEvent) } // namespace QMatrixClient |