aboutsummaryrefslogtreecommitdiff
path: root/lib/events/stateevent.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events/stateevent.h')
-rw-r--r--lib/events/stateevent.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/events/stateevent.h b/lib/events/stateevent.h
index 8a89c86c..d1b742ba 100644
--- a/lib/events/stateevent.h
+++ b/lib/events/stateevent.h
@@ -22,12 +22,29 @@
namespace QMatrixClient
{
+
+/// Make a minimal correct Matrix state event JSON
+template <typename StrT>
+inline QJsonObject basicStateEventJson(StrT matrixType,
+ const QJsonObject& content,
+ const QString& stateKey = {})
+{
+ return { { TypeKey, std::forward<StrT>(matrixType) },
+ { StateKeyKey, stateKey },
+ { ContentKey, content } };
+}
+
class StateEventBase : public RoomEvent
{
public:
using factory_t = EventFactory<StateEventBase>;
- using RoomEvent::RoomEvent;
+ StateEventBase(Type type, const QJsonObject& json)
+ : RoomEvent(type, json)
+ {}
+ StateEventBase(Type type, event_mtype_t matrixType,
+ const QString& stateKey = {},
+ const QJsonObject& contentJson = {});
~StateEventBase() override = default;
bool isStateEvent() const override { return true; }
@@ -87,8 +104,9 @@ public:
}
template <typename... ContentParamTs>
explicit StateEvent(Type type, event_mtype_t matrixType,
+ const QString& stateKey,
ContentParamTs&&... contentParams)
- : StateEventBase(type, matrixType)
+ : StateEventBase(type, matrixType, stateKey)
, _content(std::forward<ContentParamTs>(contentParams)...)
{
editJson().insert(ContentKey, _content.toJson());