From 4ec3dd92d2cb5af4cf4893770e29db51d23e0e67 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 26 Dec 2018 19:31:11 +0900 Subject: Make content in events editable --- lib/events/roommessageevent.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index 4c29a93e..a4ba6e65 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -56,6 +56,13 @@ namespace QMatrixClient QString plainBody() const; EventContent::TypedBase* content() const { return _content.data(); } + template + void editContent(VisitorT visitor) + { + visitor(*_content); + editJson()[ContentKeyL] = + assembleContentJson(plainBody(), rawMsgtype(), content()); + } QMimeType mimeType() const; bool hasTextContent() const; bool hasFileContent() const; @@ -64,6 +71,9 @@ namespace QMatrixClient private: QScopedPointer _content; + static QJsonObject assembleContentJson(const QString& plainBody, + const QString& jsonMsgType, EventContent::TypedBase* content); + REGISTER_ENUM(MsgType) }; REGISTER_EVENT_TYPE(RoomMessageEvent) -- cgit v1.2.3 From 816377ea3c204f22698e1458b815fdd3c3837adc Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 3 Jan 2019 17:57:42 +0900 Subject: More defaults to construct LocationContent and PlayableContent --- lib/events/roommessageevent.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index a4ba6e65..5657135b 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -122,7 +122,7 @@ namespace QMatrixClient { public: LocationContent(const QString& geoUri, - const ImageInfo& thumbnail); + const Thumbnail& thumbnail = {}); explicit LocationContent(const QJsonObject& json); QMimeType type() const override; @@ -142,6 +142,7 @@ namespace QMatrixClient class PlayableContent : public ContentT { public: + using ContentT::ContentT; PlayableContent(const QJsonObject& json) : ContentT(json) , duration(ContentT::originalInfoJson["duration"_ls].toInt()) -- cgit v1.2.3 From 2a6cbbff8246dd2f682624d1551facb2813394ad Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 3 Jan 2019 21:08:40 +0900 Subject: RoomMessageEvent: easier creation of file-based events --- lib/events/roommessageevent.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/events/roommessageevent.h') diff --git a/lib/events/roommessageevent.h b/lib/events/roommessageevent.h index 5657135b..d5b570f5 100644 --- a/lib/events/roommessageevent.h +++ b/lib/events/roommessageevent.h @@ -21,6 +21,8 @@ #include "roomevent.h" #include "eventcontent.h" +class QFileInfo; + namespace QMatrixClient { namespace MessageEventContent = EventContent; // Back-compatibility @@ -49,6 +51,9 @@ namespace QMatrixClient 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; @@ -68,6 +73,9 @@ namespace QMatrixClient bool hasFileContent() const; bool hasThumbnail() const; + static QString rawMsgTypeForUrl(const QUrl& url); + static QString rawMsgTypeForFile(const QFileInfo& fi); + private: QScopedPointer _content; -- cgit v1.2.3