diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-01 22:48:38 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-04 09:07:32 +0900 |
commit | f1ffe1e7a3e81c07a07a8416ce307e4413ec8fbc (patch) | |
tree | f2435183d11a4cea52a7532eb9ff3d4d837e1d22 /lib/events/roommemberevent.h | |
parent | d5397fe5ae2ca34d5cfb11394dac17728a2b50ce (diff) | |
download | libquotient-f1ffe1e7a3e81c07a07a8416ce307e4413ec8fbc.tar.gz libquotient-f1ffe1e7a3e81c07a07a8416ce307e4413ec8fbc.zip |
Event types system remade to be extensible
There were two common points that had to be updated every time a new event is introduced:
the EventType enumeration and one of 3 doMakeEvent<> specialisations. The new code
has a template class, EventFactory<>, that uses a list of static factory methods
to create events instead of typelists used in doMakeEvent<>(); the EventType enumeration
is replaced with a namespace populated with constants as necessary.
In general, EventType is considered a deprecated mechanism altogether; instead, a set
of facilities is provided: is<>() to check if an event has a certain type (to replace
comparison against an EventType value) and visit<>() to execute actions based on
the event type (replacing switch statements over EventType values).
Closes #129.
Diffstat (limited to 'lib/events/roommemberevent.h')
-rw-r--r-- | lib/events/roommemberevent.h | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/events/roommemberevent.h b/lib/events/roommemberevent.h index 8e0cc0a4..943d5ac6 100644 --- a/lib/events/roommemberevent.h +++ b/lib/events/roommemberevent.h @@ -22,8 +22,6 @@ #include "eventcontent.h" -#include <QtCore/QUrl> - namespace QMatrixClient { class MemberEventContent: public EventContent::Base @@ -36,6 +34,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 +53,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 +80,5 @@ namespace QMatrixClient private: REGISTER_ENUM(MembershipType) }; + DEFINE_EVENTTYPE_ALIAS(RoomMember, RoomMemberEvent) } // namespace QMatrixClient |