diff options
Diffstat (limited to 'lib/events')
-rw-r--r-- | lib/events/event.cpp | 2 | ||||
-rw-r--r-- | lib/events/event.h | 4 | ||||
-rw-r--r-- | lib/events/roomcreateevent.h | 4 | ||||
-rw-r--r-- | lib/events/roomtombstoneevent.h | 4 | ||||
-rw-r--r-- | lib/events/stateevent.cpp | 13 | ||||
-rw-r--r-- | lib/events/stateevent.h | 42 |
6 files changed, 35 insertions, 34 deletions
diff --git a/lib/events/event.cpp b/lib/events/event.cpp index ca751081..da7de919 100644 --- a/lib/events/event.cpp +++ b/lib/events/event.cpp @@ -73,7 +73,7 @@ const QJsonObject Event::unsignedJson() const return fullJson()[UnsignedKeyL].toObject(); } -bool Event::isStateEvent() const { return is<StateEventBase>(); } +bool Event::isStateEvent() const { return is<StateEvent>(); } bool Event::isCallEvent() const { return is<CallEvent>(); } diff --git a/lib/events/event.h b/lib/events/event.h index d0b63085..c8ef5acb 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -125,7 +125,7 @@ inline bool operator==(const AbstractEventMetaType& lhs, //! //! TL;DR for the loadFrom() story: //! - for base event types, use QUO_BASE_EVENT and, if you have additional -//! validation (e.g., JSON has to contain a certain key - see StateEventBase +//! validation (e.g., JSON has to contain a certain key - see StateEvent //! for a real example), define it in the static EventT::isValid() member //! function accepting QJsonObject and returning bool. //! - for leaf (specific) event types - simply use QUO_EVENT and it will do @@ -153,7 +153,7 @@ public: //! any of its base event types) has a static isValid() predicate and //! the event JSON does not satisfy it, nullptr is immediately returned //! to the upper level or to the loadFrom() caller. This is how existence - //! of `state_key` is checked in any type derived from StateEventBase. + //! of `state_key` is checked in any type derived from StateEvent. //! 3. If step 1b above returned non-nullptr, immediately return it. //! 4. //! a. If EventT::isValid() or EventT::TypeId (either, or both) exist and diff --git a/lib/events/roomcreateevent.h b/lib/events/roomcreateevent.h index 2709258f..5968e187 100644 --- a/lib/events/roomcreateevent.h +++ b/lib/events/roomcreateevent.h @@ -7,11 +7,11 @@ #include "quotient_common.h" namespace Quotient { -class QUOTIENT_API RoomCreateEvent : public StateEventBase { +class QUOTIENT_API RoomCreateEvent : public StateEvent { public: QUO_EVENT(RoomCreateEvent, "m.room.create") - using StateEventBase::StateEventBase; + using StateEvent::StateEvent; struct Predecessor { QString roomId; diff --git a/lib/events/roomtombstoneevent.h b/lib/events/roomtombstoneevent.h index 95743e32..c85b4dfd 100644 --- a/lib/events/roomtombstoneevent.h +++ b/lib/events/roomtombstoneevent.h @@ -6,11 +6,11 @@ #include "stateevent.h" namespace Quotient { -class QUOTIENT_API RoomTombstoneEvent : public StateEventBase { +class QUOTIENT_API RoomTombstoneEvent : public StateEvent { public: QUO_EVENT(RoomTombstoneEvent, "m.room.tombstone") - using StateEventBase::StateEventBase; + using StateEvent::StateEvent; QString serverMessage() const; QString successorRoomId() const; diff --git a/lib/events/stateevent.cpp b/lib/events/stateevent.cpp index 204044bb..72ecd5ad 100644 --- a/lib/events/stateevent.cpp +++ b/lib/events/stateevent.cpp @@ -6,30 +6,29 @@ using namespace Quotient; -StateEventBase::StateEventBase(const QJsonObject& json) +StateEvent::StateEvent(const QJsonObject& json) : RoomEvent(json) { Q_ASSERT_X(json.contains(StateKeyKeyL), __FUNCTION__, "Attempt to create a state event without state key"); } -StateEventBase::StateEventBase(Event::Type type, const QString& stateKey, +StateEvent::StateEvent(Event::Type type, const QString& stateKey, const QJsonObject& contentJson) : RoomEvent(basicJson(type, stateKey, contentJson)) {} -bool StateEventBase::repeatsState() const +bool StateEvent::repeatsState() const { - const auto prevContentJson = unsignedPart<QJsonObject>(PrevContentKeyL); - return fullJson().value(ContentKeyL) == prevContentJson; + return contentJson() == unsignedPart<QJsonObject>(PrevContentKeyL); } -QString StateEventBase::replacedState() const +QString StateEvent::replacedState() const { return unsignedPart<QString>("replaces_state"_ls); } -void StateEventBase::dumpTo(QDebug dbg) const +void StateEvent::dumpTo(QDebug dbg) const { if (!stateKey().isEmpty()) dbg << '<' << stateKey() << "> "; diff --git a/lib/events/stateevent.h b/lib/events/stateevent.h index ffbce76e..992ec2e2 100644 --- a/lib/events/stateevent.h +++ b/lib/events/stateevent.h @@ -7,10 +7,10 @@ namespace Quotient { -class QUOTIENT_API StateEventBase : public RoomEvent { +class QUOTIENT_API StateEvent : public RoomEvent { public: - QUO_BASE_EVENT(StateEventBase, "json.contains('state_key')"_ls, - RoomEvent::BaseMetaType) + QUO_BASE_EVENT(StateEvent, "json.contains('state_key')"_ls, + RoomEvent::BaseMetaType) static bool isValid(const QJsonObject& fullJson) { return fullJson.contains(StateKeyKeyL); @@ -24,8 +24,8 @@ public: //! constructors and calls in, e.g., RoomStateView don't include it. static constexpr auto needsStateKey = false; - explicit StateEventBase(Type type, const QString& stateKey = {}, - const QJsonObject& contentJson = {}); + explicit StateEvent(Type type, const QString& stateKey = {}, + const QJsonObject& contentJson = {}); //! Make a minimal correct Matrix state event JSON static QJsonObject basicJson(const QString& matrixTypeId, @@ -41,18 +41,20 @@ public: virtual bool repeatsState() const; protected: - explicit StateEventBase(const QJsonObject& json); + explicit StateEvent(const QJsonObject& json); void dumpTo(QDebug dbg) const override; }; -using StateEventPtr = event_ptr_tt<StateEventBase>; -using StateEvents = EventsArray<StateEventBase>; +using StateEventBase + [[deprecated("StateEventBase is StateEvent now")]] = StateEvent; +using StateEventPtr = event_ptr_tt<StateEvent>; +using StateEvents = EventsArray<StateEvent>; -[[deprecated("Use StateEventBase::basicJson() instead")]] +[[deprecated("Use StateEvent::basicJson() instead")]] inline QJsonObject basicStateEventJson(const QString& matrixTypeId, const QJsonObject& content, const QString& stateKey = {}) { - return StateEventBase::basicJson(matrixTypeId, stateKey, content); + return StateEvent::basicJson(matrixTypeId, stateKey, content); } /** @@ -64,8 +66,8 @@ inline QJsonObject basicStateEventJson(const QString& matrixTypeId, using StateEventKey = std::pair<QString, QString>; template <typename EventT, typename ContentT> -class EventTemplate<EventT, StateEventBase, ContentT> - : public StateEventBase { +class EventTemplate<EventT, StateEvent, ContentT> + : public StateEvent { public: using content_type = ContentT; @@ -82,14 +84,14 @@ public: }; explicit EventTemplate(const QJsonObject& fullJson) - : StateEventBase(fullJson) + : StateEvent(fullJson) , _content(fromJson<ContentT>(Event::contentJson())) , _prev(unsignedJson()) {} template <typename... ContentParamTs> explicit EventTemplate(const QString& stateKey, ContentParamTs&&... contentParams) - : StateEventBase(EventT::TypeId, stateKey) + : StateEvent(EventT::TypeId, stateKey) , _content { std::forward<ContentParamTs>(contentParams)... } { editJson().insert(ContentKey, toJson(_content)); @@ -113,11 +115,11 @@ private: template <typename EventT, typename ContentT> class KeyedStateEventBase - : public EventTemplate<EventT, StateEventBase, ContentT> { + : public EventTemplate<EventT, StateEvent, ContentT> { public: static constexpr auto needsStateKey = true; - using EventTemplate<EventT, StateEventBase, ContentT>::EventTemplate; + using EventTemplate<EventT, StateEvent, ContentT>::EventTemplate; }; template <typename EvT> @@ -125,9 +127,9 @@ concept Keyed_State_Event = EvT::needsStateKey; template <typename EventT, typename ContentT> class KeylessStateEventBase - : public EventTemplate<EventT, StateEventBase, ContentT> { + : public EventTemplate<EventT, StateEvent, ContentT> { private: - using base_type = EventTemplate<EventT, StateEventBase, ContentT>; + using base_type = EventTemplate<EventT, StateEvent, ContentT>; public: template <typename... ContentParamTs> @@ -145,5 +147,5 @@ template <typename EvT> concept Keyless_State_Event = !EvT::needsStateKey; } // namespace Quotient -Q_DECLARE_METATYPE(Quotient::StateEventBase*) -Q_DECLARE_METATYPE(const Quotient::StateEventBase*) +Q_DECLARE_METATYPE(Quotient::StateEvent*) +Q_DECLARE_METATYPE(const Quotient::StateEvent*) |