diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-07-29 18:13:14 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2022-08-05 12:36:44 +0200 |
commit | 3214feeb031fa231c7c42c21c53410302966e32e (patch) | |
tree | 4ed144212698e5269be970bbffd459949ea5fd6e /lib/events | |
parent | deb6c1141af445de6f3f1fd5afc83ed2ac4def4b (diff) | |
download | libquotient-3214feeb031fa231c7c42c21c53410302966e32e.tar.gz libquotient-3214feeb031fa231c7c42c21c53410302966e32e.zip |
eventloader.h: use basicJson() in a uniform way
There's no particular reason the order of parameters in
StateEventBase::basicJson() should be as it was, and (the only)
loadStateEvent() usage in room.cpp suggests the unified order is more
convenient. Besides, this order is aligned with that in
the StateEventBase constructor.
Diffstat (limited to 'lib/events')
-rw-r--r-- | lib/events/eventloader.h | 35 | ||||
-rw-r--r-- | lib/events/stateevent.cpp | 2 | ||||
-rw-r--r-- | lib/events/stateevent.h | 8 |
3 files changed, 15 insertions, 30 deletions
diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h index 15271ab1..4c639efa 100644 --- a/lib/events/eventloader.h +++ b/lib/events/eventloader.h @@ -19,32 +19,17 @@ inline event_ptr_tt<BaseEventT> loadEvent(const QJsonObject& fullJson) return doLoadEvent<BaseEventT>(fullJson, fullJson[TypeKeyL].toString()); } -/*! Create an event from a type string and content JSON - * - * Use this factory template to resolve the C++ type from the Matrix - * type string in \p matrixType and create an event of that type that has - * its content part set to \p content. - */ -template <typename BaseEventT> -inline event_ptr_tt<BaseEventT> loadEvent(const QString& matrixType, - const QJsonObject& content) -{ - return doLoadEvent<BaseEventT>(Event::basicJson(matrixType, content), - matrixType); -} - -/*! Create a state event from a type string, content JSON and state key - * - * Use this factory to resolve the C++ type from the Matrix type string - * in \p matrixType and create a state event of that type with content part - * set to \p content and state key set to \p stateKey (empty by default). - */ -inline StateEventPtr loadStateEvent(const QString& matrixType, - const QJsonObject& content, - const QString& stateKey = {}) +//! \brief Create an event from a type string and content JSON +//! +//! Use this template to resolve the C++ type from the Matrix type string in +//! \p matrixType and create an event of that type by passing all parameters +//! to BaseEventT::basicJson(). +template <typename BaseEventT, typename... BasicJsonParamTs> +inline event_ptr_tt<BaseEventT> loadEvent( + const QString& matrixType, const BasicJsonParamTs&... basicJsonParams) { - return doLoadEvent<StateEventBase>( - StateEventBase::basicJson(matrixType, content, stateKey), matrixType); + return doLoadEvent<BaseEventT>( + BaseEventT::basicJson(matrixType, basicJsonParams...), matrixType); } template <typename EventT> diff --git a/lib/events/stateevent.cpp b/lib/events/stateevent.cpp index 43dfd6e8..1df24df0 100644 --- a/lib/events/stateevent.cpp +++ b/lib/events/stateevent.cpp @@ -16,7 +16,7 @@ StateEventBase::StateEventBase(Type type, const QJsonObject& json) StateEventBase::StateEventBase(Event::Type type, event_mtype_t matrixType, const QString& stateKey, const QJsonObject& contentJson) - : RoomEvent(type, basicJson(matrixType, contentJson, stateKey)) + : RoomEvent(type, basicJson(type, stateKey, contentJson)) {} bool StateEventBase::repeatsState() const diff --git a/lib/events/stateevent.h b/lib/events/stateevent.h index 343e87a5..9f1d7118 100644 --- a/lib/events/stateevent.h +++ b/lib/events/stateevent.h @@ -19,12 +19,12 @@ public: //! Make a minimal correct Matrix state event JSON static QJsonObject basicJson(const QString& matrixTypeId, - const QJsonObject& content, - const QString& stateKey = {}) + const QString& stateKey = {}, + const QJsonObject& contentJson = {}) { return { { TypeKey, matrixTypeId }, { StateKeyKey, stateKey }, - { ContentKey, content } }; + { ContentKey, contentJson } }; } bool isStateEvent() const override { return true; } @@ -41,7 +41,7 @@ inline QJsonObject basicStateEventJson(const QString& matrixTypeId, const QJsonObject& content, const QString& stateKey = {}) { - return StateEventBase::basicJson(matrixTypeId, content, stateKey); + return StateEventBase::basicJson(matrixTypeId, stateKey, content); } //! \brief Override RoomEvent factory with that from StateEventBase if JSON has |