aboutsummaryrefslogtreecommitdiff
path: root/lib/events/eventloader.h
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-08-24 09:41:51 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2022-08-24 09:41:51 +0200
commit82f4efb0227e7e22e831733fae3952818b063ac2 (patch)
tree3b154a16f9d355996a59c611230d0e010edab57f /lib/events/eventloader.h
parent16d4f4e48304543a0ab59b235edba07f5f2c2204 (diff)
parent6308bff3336ca7680eee54d9bd125f780fa9f033 (diff)
downloadlibquotient-82f4efb0227e7e22e831733fae3952818b063ac2.tar.gz
libquotient-82f4efb0227e7e22e831733fae3952818b063ac2.zip
Merge branch 'dev' into device-verification
# Conflicts: # autotests/testfilecrypto.cpp # lib/connection.cpp # lib/connection.h # lib/database.cpp # lib/database.h # lib/e2ee/qolmoutboundsession.cpp # lib/e2ee/qolmoutboundsession.h # lib/eventitem.h # lib/events/encryptedevent.cpp # lib/events/encryptedevent.h # lib/events/encryptedfile.cpp # lib/events/encryptedfile.h # lib/events/keyverificationevent.cpp # lib/events/keyverificationevent.h # lib/events/roomkeyevent.h # lib/room.cpp # lib/room.h
Diffstat (limited to 'lib/events/eventloader.h')
-rw-r--r--lib/events/eventloader.h48
1 files changed, 16 insertions, 32 deletions
diff --git a/lib/events/eventloader.h b/lib/events/eventloader.h
index fe624d70..4c639efa 100644
--- a/lib/events/eventloader.h
+++ b/lib/events/eventloader.h
@@ -19,43 +19,27 @@ 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)
+//! \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<BaseEventT>(basicEventJson(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 = {})
-{
- return doLoadEvent<StateEventBase>(
- basicStateEventJson(matrixType, content, stateKey), matrixType);
+ return doLoadEvent<BaseEventT>(
+ BaseEventT::basicJson(matrixType, basicJsonParams...), matrixType);
}
template <typename EventT>
-struct JsonConverter<event_ptr_tt<EventT>> {
- static auto load(const QJsonValue& jv)
+struct JsonConverter<event_ptr_tt<EventT>>
+ : JsonObjectUnpacker<event_ptr_tt<EventT>> {
+ using JsonObjectUnpacker<event_ptr_tt<EventT>>::load;
+ static auto load(const QJsonObject& jo)
{
- return loadEvent<EventT>(jv.toObject());
- }
- static auto load(const QJsonDocument& jd)
- {
- return loadEvent<EventT>(jd.object());
+ return loadEvent<EventT>(jo);
}
};
+
} // namespace Quotient