aboutsummaryrefslogtreecommitdiff
path: root/lib/events/roommessageevent.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-06-24 07:21:13 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-06-24 07:21:13 +0900
commit63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408 (patch)
tree2552f5049a6ef7ba0034483b25ca4ab33d1fcb13 /lib/events/roommessageevent.h
parente083d327e6f6581210f8d077d8bbe1151e81e82c (diff)
parent93f0c8fe89f448d1d58caa757573f17102369471 (diff)
downloadlibquotient-63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408.tar.gz
libquotient-63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408.zip
Merge branch 'master' into clang-format
# Conflicts: # CMakeLists.txt # lib/avatar.cpp # lib/connection.cpp # lib/connection.h # lib/connectiondata.cpp # lib/csapi/account-data.cpp # lib/csapi/account-data.h # lib/csapi/capabilities.cpp # lib/csapi/capabilities.h # lib/csapi/content-repo.cpp # lib/csapi/create_room.cpp # lib/csapi/filter.cpp # lib/csapi/joining.cpp # lib/csapi/keys.cpp # lib/csapi/list_joined_rooms.cpp # lib/csapi/notifications.cpp # lib/csapi/openid.cpp # lib/csapi/presence.cpp # lib/csapi/pushrules.cpp # lib/csapi/registration.cpp # lib/csapi/room_upgrades.cpp # lib/csapi/room_upgrades.h # lib/csapi/search.cpp # lib/csapi/users.cpp # lib/csapi/versions.cpp # lib/csapi/whoami.cpp # lib/csapi/{{base}}.cpp.mustache # lib/events/accountdataevents.h # lib/events/eventcontent.h # lib/events/roommemberevent.cpp # lib/events/stateevent.cpp # lib/jobs/basejob.cpp # lib/jobs/basejob.h # lib/networkaccessmanager.cpp # lib/networksettings.cpp # lib/room.cpp # lib/room.h # lib/settings.cpp # lib/settings.h # lib/syncdata.cpp # lib/user.cpp # lib/user.h # lib/util.cpp
Diffstat (limited to 'lib/events/roommessageevent.h')
-rw-r--r--lib/events/roommessageevent.h372
1 files changed, 185 insertions, 187 deletions
diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h
index bd1b7c83..eabb21e3 100644
--- a/lib/events/roommessageevent.h
+++ b/lib/events/roommessageevent.h
@@ -23,205 +23,203 @@
class QFileInfo;
-namespace QMatrixClient {
- namespace MessageEventContent = EventContent; // Back-compatibility
+namespace QMatrixClient
+{
+namespace MessageEventContent = EventContent; // Back-compatibility
+
+/**
+ * The event class corresponding to m.room.message events
+ */
+class RoomMessageEvent : public RoomEvent
+{
+ Q_GADGET
+ Q_PROPERTY(QString msgType READ rawMsgtype CONSTANT)
+ Q_PROPERTY(QString plainBody READ plainBody CONSTANT)
+ Q_PROPERTY(QMimeType mimeType READ mimeType STORED false CONSTANT)
+ Q_PROPERTY(EventContent::TypedBase* content READ content CONSTANT)
+public:
+ DEFINE_EVENT_TYPEID("m.room.message", RoomMessageEvent)
+
+ enum class MsgType
+ {
+ Text,
+ Emote,
+ Notice,
+ Image,
+ File,
+ Location,
+ Video,
+ Audio,
+ Unknown
+ };
+
+ RoomMessageEvent(const QString& plainBody, const QString& jsonMsgType,
+ EventContent::TypedBase* content = nullptr);
+ explicit RoomMessageEvent(const QString& plainBody,
+ MsgType msgType = MsgType::Text,
+ EventContent::TypedBase* content = nullptr);
+ explicit RoomMessageEvent(const QString& plainBody, const QFileInfo& file,
+ bool asGenericFile = false);
+ explicit RoomMessageEvent(const QJsonObject& obj);
+
+ MsgType msgtype() const;
+ QString rawMsgtype() const;
+ QString plainBody() const;
+ EventContent::TypedBase* content() const { return _content.data(); }
+ template <typename VisitorT>
+ void editContent(VisitorT visitor)
+ {
+ visitor(*_content);
+ editJson()[ContentKeyL] = assembleContentJson(plainBody(), rawMsgtype(),
+ content());
+ }
+ QMimeType mimeType() const;
+ bool hasTextContent() const;
+ bool hasFileContent() const;
+ bool hasThumbnail() const;
+
+ static QString rawMsgTypeForUrl(const QUrl& url);
+ static QString rawMsgTypeForFile(const QFileInfo& fi);
+
+private:
+ QScopedPointer<EventContent::TypedBase> _content;
+
+ static QJsonObject assembleContentJson(const QString& plainBody,
+ const QString& jsonMsgType,
+ EventContent::TypedBase* content);
+
+ REGISTER_ENUM(MsgType)
+};
+REGISTER_EVENT_TYPE(RoomMessageEvent)
+DEFINE_EVENTTYPE_ALIAS(RoomMessage, RoomMessageEvent)
+using MessageEventType = RoomMessageEvent::MsgType;
+
+namespace EventContent
+{
+ // Additional event content types
+
+ struct RelatesTo
+ {
+ static constexpr const char* ReplyTypeId() { return "m.in_reply_to"; }
+ QString type; // The only supported relation so far
+ QString eventId;
+ };
+ inline RelatesTo replyTo(QString eventId)
+ {
+ return { RelatesTo::ReplyTypeId(), std::move(eventId) };
+ }
/**
- * The event class corresponding to m.room.message events
+ * Rich text content for m.text, m.emote, m.notice
+ *
+ * Available fields: mimeType, body. The body can be either rich text
+ * or plain text, depending on what mimeType specifies.
*/
- class RoomMessageEvent : public RoomEvent
+ class TextContent : public TypedBase
{
- Q_GADGET
- Q_PROPERTY(QString msgType READ rawMsgtype CONSTANT)
- Q_PROPERTY(QString plainBody READ plainBody CONSTANT)
- Q_PROPERTY(QMimeType mimeType READ mimeType STORED false CONSTANT)
- Q_PROPERTY(EventContent::TypedBase* content READ content CONSTANT)
- public:
- DEFINE_EVENT_TYPEID("m.room.message", RoomMessageEvent)
-
- enum class MsgType {
- Text,
- Emote,
- Notice,
- Image,
- File,
- Location,
- Video,
- Audio,
- Unknown
- };
-
- RoomMessageEvent(const QString& plainBody, const QString& jsonMsgType,
- EventContent::TypedBase* content = nullptr);
- explicit RoomMessageEvent(const QString& plainBody,
- MsgType msgType = MsgType::Text,
- EventContent::TypedBase* content = nullptr);
- explicit RoomMessageEvent(const QString& plainBody,
- const QFileInfo& file,
- bool asGenericFile = false);
- explicit RoomMessageEvent(const QJsonObject& obj);
-
- MsgType msgtype() const;
- QString rawMsgtype() const;
- QString plainBody() const;
- EventContent::TypedBase* content() const { return _content.data(); }
- template <typename VisitorT> void editContent(VisitorT visitor)
- {
- visitor(*_content);
- editJson()[ContentKeyL] =
- assembleContentJson(plainBody(), rawMsgtype(), content());
- }
- QMimeType mimeType() const;
- bool hasTextContent() const;
- bool hasFileContent() const;
- bool hasThumbnail() const;
-
- static QString rawMsgTypeForUrl(const QUrl& url);
- static QString rawMsgTypeForFile(const QFileInfo& fi);
+ public:
+ TextContent(const QString& text, const QString& contentType,
+ Omittable<RelatesTo> relatesTo = none);
+ explicit TextContent(const QJsonObject& json);
- private:
- QScopedPointer<EventContent::TypedBase> _content;
+ QMimeType type() const override { return mimeType; }
- static QJsonObject
- assembleContentJson(const QString& plainBody,
- const QString& jsonMsgType,
- EventContent::TypedBase* content);
+ QMimeType mimeType;
+ QString body;
+ Omittable<RelatesTo> relatesTo;
- REGISTER_ENUM(MsgType)
+ protected:
+ void fillJson(QJsonObject* json) const override;
};
- REGISTER_EVENT_TYPE(RoomMessageEvent)
- DEFINE_EVENTTYPE_ALIAS(RoomMessage, RoomMessageEvent)
- using MessageEventType = RoomMessageEvent::MsgType;
-
- namespace EventContent {
- // Additional event content types
-
- struct RelatesTo {
- static constexpr const char* ReplyTypeId()
- {
- return "m.in_reply_to";
- }
- QString type; // The only supported relation so far
- QString eventId;
- };
- inline RelatesTo replyTo(QString eventId)
- {
- return { RelatesTo::ReplyTypeId(), std::move(eventId) };
- }
- /**
- * Rich text content for m.text, m.emote, m.notice
- *
- * Available fields: mimeType, body. The body can be either rich text
- * or plain text, depending on what mimeType specifies.
- */
- class TextContent : public TypedBase
- {
- public:
- TextContent(const QString& text, const QString& contentType,
- Omittable<RelatesTo> relatesTo = none);
- explicit TextContent(const QJsonObject& json);
-
- QMimeType type() const override { return mimeType; }
-
- QMimeType mimeType;
- QString body;
- Omittable<RelatesTo> relatesTo;
-
- protected:
- void fillJson(QJsonObject* json) const override;
- };
-
- /**
- * Content class for m.location
- *
- * Available fields:
- * - corresponding to the top-level JSON:
- * - geoUri ("geo_uri" in JSON)
- * - corresponding to the "info" subobject:
- * - thumbnail.url ("thumbnail_url" in JSON)
- * - corresponding to the "info/thumbnail_info" subobject:
- * - thumbnail.payloadSize
- * - thumbnail.mimeType
- * - thumbnail.imageSize
- */
- class LocationContent : public TypedBase
- {
- public:
- LocationContent(const QString& geoUri,
- const Thumbnail& thumbnail = {});
- explicit LocationContent(const QJsonObject& json);
+ /**
+ * Content class for m.location
+ *
+ * Available fields:
+ * - corresponding to the top-level JSON:
+ * - geoUri ("geo_uri" in JSON)
+ * - corresponding to the "info" subobject:
+ * - thumbnail.url ("thumbnail_url" in JSON)
+ * - corresponding to the "info/thumbnail_info" subobject:
+ * - thumbnail.payloadSize
+ * - thumbnail.mimeType
+ * - thumbnail.imageSize
+ */
+ class LocationContent : public TypedBase
+ {
+ public:
+ LocationContent(const QString& geoUri, const Thumbnail& thumbnail = {});
+ explicit LocationContent(const QJsonObject& json);
- QMimeType type() const override;
+ QMimeType type() const override;
- public:
- QString geoUri;
- Thumbnail thumbnail;
+ public:
+ QString geoUri;
+ Thumbnail thumbnail;
- protected:
- void fillJson(QJsonObject* o) const override;
- };
+ protected:
+ void fillJson(QJsonObject* o) const override;
+ };
- /**
- * A base class for info types that include duration: audio and video
- */
- template <typename ContentT> class PlayableContent : public ContentT
+ /**
+ * A base class for info types that include duration: audio and video
+ */
+ template <typename ContentT>
+ class PlayableContent : public ContentT
+ {
+ public:
+ using ContentT::ContentT;
+ PlayableContent(const QJsonObject& json)
+ : ContentT(json)
+ , duration(ContentT::originalInfoJson["duration"_ls].toInt())
+ {}
+
+ protected:
+ void fillJson(QJsonObject* json) const override
{
- public:
- using ContentT::ContentT;
- PlayableContent(const QJsonObject& json)
- : ContentT(json),
- duration(ContentT::originalInfoJson["duration"_ls].toInt())
- {
- }
-
- protected:
- void fillJson(QJsonObject* json) const override
- {
- ContentT::fillJson(json);
- auto infoJson = json->take("info"_ls).toObject();
- infoJson.insert(QStringLiteral("duration"), duration);
- json->insert(QStringLiteral("info"), infoJson);
- }
-
- public:
- int duration;
- };
-
- /**
- * Content class for m.video
- *
- * Available fields:
- * - corresponding to the top-level JSON:
- * - url
- * - filename (extension to the CS API spec)
- * - corresponding to the "info" subobject:
- * - payloadSize ("size" in JSON)
- * - mimeType ("mimetype" in JSON)
- * - duration
- * - imageSize (QSize for a combination of "h" and "w" in JSON)
- * - thumbnail.url ("thumbnail_url" in JSON)
- * - corresponding to the "info/thumbnail_info" subobject: contents of
- * thumbnail field, in the same vein as for "info":
- * - payloadSize
- * - mimeType
- * - imageSize
- */
- using VideoContent =
- PlayableContent<UrlWithThumbnailContent<ImageInfo>>;
-
- /**
- * Content class for m.audio
- *
- * Available fields:
- * - corresponding to the top-level JSON:
- * - url
- * - filename (extension to the CS API spec)
- * - corresponding to the "info" subobject:
- * - payloadSize ("size" in JSON)
- * - mimeType ("mimetype" in JSON)
- * - duration
- */
- using AudioContent = PlayableContent<UrlBasedContent<FileInfo>>;
- } // namespace EventContent
+ ContentT::fillJson(json);
+ auto infoJson = json->take("info"_ls).toObject();
+ infoJson.insert(QStringLiteral("duration"), duration);
+ json->insert(QStringLiteral("info"), infoJson);
+ }
+
+ public:
+ int duration;
+ };
+
+ /**
+ * Content class for m.video
+ *
+ * Available fields:
+ * - corresponding to the top-level JSON:
+ * - url
+ * - filename (extension to the CS API spec)
+ * - corresponding to the "info" subobject:
+ * - payloadSize ("size" in JSON)
+ * - mimeType ("mimetype" in JSON)
+ * - duration
+ * - imageSize (QSize for a combination of "h" and "w" in JSON)
+ * - thumbnail.url ("thumbnail_url" in JSON)
+ * - corresponding to the "info/thumbnail_info" subobject: contents of
+ * thumbnail field, in the same vein as for "info":
+ * - payloadSize
+ * - mimeType
+ * - imageSize
+ */
+ using VideoContent = PlayableContent<UrlWithThumbnailContent<ImageInfo>>;
+
+ /**
+ * Content class for m.audio
+ *
+ * Available fields:
+ * - corresponding to the top-level JSON:
+ * - url
+ * - filename (extension to the CS API spec)
+ * - corresponding to the "info" subobject:
+ * - payloadSize ("size" in JSON)
+ * - mimeType ("mimetype" in JSON)
+ * - duration
+ */
+ using AudioContent = PlayableContent<UrlBasedContent<FileInfo>>;
+} // namespace EventContent
} // namespace QMatrixClient