From f1ffe1e7a3e81c07a07a8416ce307e4413ec8fbc Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 1 Jul 2018 22:48:38 +0900 Subject: 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. --- lib/events/redactionevent.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'lib/events/redactionevent.h') diff --git a/lib/events/redactionevent.h b/lib/events/redactionevent.h index dad54788..8c6cbeff 100644 --- a/lib/events/redactionevent.h +++ b/lib/events/redactionevent.h @@ -25,19 +25,16 @@ namespace QMatrixClient class RedactionEvent : public RoomEvent { public: - static constexpr const char* typeId() { return "m.room.redaction"; } + DEFINE_EVENT_TYPEID("m.room.redaction", RedactionEvent) explicit RedactionEvent(const QJsonObject& obj) - : RoomEvent(Type::Redaction, obj) - , _redactedEvent(obj.value("redacts").toString()) - , _reason(contentJson().value("reason").toString()) + : RoomEvent(typeId(), obj) { } - const QString& redactedEvent() const { return _redactedEvent; } - const QString& reason() const { return _reason; } - - private: - QString _redactedEvent; - QString _reason; + QString redactedEvent() const + { return fullJson()["redacts"_ls].toString(); } + QString reason() const + { return contentJson()["reason"_ls].toString(); } }; + DEFINE_EVENTTYPE_ALIAS(Redaction, RedactionEvent) } // namespace QMatrixClient -- cgit v1.2.3