aboutsummaryrefslogtreecommitdiff
path: root/lib/events
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events')
-rw-r--r--lib/events/eventloader.h35
-rw-r--r--lib/events/stateevent.cpp2
-rw-r--r--lib/events/stateevent.h8
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