aboutsummaryrefslogtreecommitdiff
path: root/events/eventcontent.h
diff options
context:
space:
mode:
Diffstat (limited to 'events/eventcontent.h')
-rw-r--r--events/eventcontent.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/events/eventcontent.h b/events/eventcontent.h
index f9cdaf11..60437995 100644
--- a/events/eventcontent.h
+++ b/events/eventcontent.h
@@ -21,6 +21,8 @@
// This file contains generic event content definitions, applicable to room
// message events as well as other events (e.g., avatars).
+#include "converters.h"
+
#include <QtCore/QJsonObject>
#include <QtCore/QMimeType>
#include <QtCore/QUrl>
@@ -60,6 +62,35 @@ namespace QMatrixClient
virtual QMimeType type() const = 0;
};
+ template <typename T = QString>
+ class SimpleContent: public Base
+ {
+ public:
+ using value_type = T;
+
+ // The constructor is templated to enable perfect forwarding
+ template <typename TT>
+ SimpleContent(QString keyName, TT&& value)
+ : value(std::forward<TT>(value)), key(std::move(keyName))
+ { }
+ SimpleContent(const QJsonObject& json, QString keyName)
+ : value(QMatrixClient::fromJson<T>(json[keyName]))
+ , key(std::move(keyName))
+ { }
+
+ T value;
+
+ protected:
+ QString key;
+
+ private:
+ void fillJson(QJsonObject* json) const override
+ {
+ Q_ASSERT(json);
+ json->insert(key, QMatrixClient::toJson(value));
+ }
+ };
+
/**
* A base class for content types that have an "info" object in their
* JSON representation