diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-10 20:18:21 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-07-10 20:18:21 +0900 |
commit | e66cae5fd3e74c5839804e560332e5690709931a (patch) | |
tree | afdef32c421200cd669991d1db05167b9e8d7b36 /lib | |
parent | a0f49a396c9bd2a9f65df2682f8a6618e79c5dc7 (diff) | |
download | libquotient-e66cae5fd3e74c5839804e560332e5690709931a.tar.gz libquotient-e66cae5fd3e74c5839804e560332e5690709931a.zip |
Room::postHtmlMessage() - a facility method to send HTML messages
Diffstat (limited to 'lib')
-rw-r--r-- | lib/events/roommessageevent.cpp | 14 | ||||
-rw-r--r-- | lib/room.cpp | 8 | ||||
-rw-r--r-- | lib/room.h | 2 |
3 files changed, 20 insertions, 4 deletions
diff --git a/lib/events/roommessageevent.cpp b/lib/events/roommessageevent.cpp index e07054a4..1c5cf058 100644 --- a/lib/events/roommessageevent.cpp +++ b/lib/events/roommessageevent.cpp @@ -164,7 +164,10 @@ bool RoomMessageEvent::hasThumbnail() const TextContent::TextContent(const QString& text, const QString& contentType) : mimeType(QMimeDatabase().mimeTypeForName(contentType)), body(text) -{ } +{ + if (contentType == "org.matrix.custom.html") + mimeType = QMimeDatabase().mimeTypeForName("text/html"); +} TextContent::TextContent(const QJsonObject& json) { @@ -189,9 +192,12 @@ TextContent::TextContent(const QJsonObject& json) void TextContent::fillJson(QJsonObject* json) const { Q_ASSERT(json); - json->insert(QStringLiteral("format"), - QStringLiteral("org.matrix.custom.html")); - json->insert(QStringLiteral("formatted_body"), body); + if (mimeType.inherits("text/html")) + { + json->insert(QStringLiteral("format"), + QStringLiteral("org.matrix.custom.html")); + json->insert(QStringLiteral("formatted_body"), body); + } } LocationContent::LocationContent(const QString& geoUri, const ImageInfo& thumbnail) diff --git a/lib/room.cpp b/lib/room.cpp index 06a0a380..b4d0f47c 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -1076,6 +1076,14 @@ void Room::postMessage(const QString& plainText, MessageEventType type) postMessage(RoomMessageEvent { plainText, type }); } +void Room::postHtmlMessage(const QString& plainText, const QString& htmlText, + MessageEventType type) +{ + postMessage(RoomMessageEvent { plainText, type, + new EventContent::TextContent(htmlText, QStringLiteral("text/html")) }); + +} + void Room::postMessage(const RoomMessageEvent& event) { if (usesEncryption()) @@ -347,6 +347,8 @@ namespace QMatrixClient public slots: void postMessage(const QString& plainText, MessageEventType type = MessageEventType::Text); + void postHtmlMessage(const QString& plainText, const QString& htmlText, + MessageEventType type = MessageEventType::Text); void postMessage(const RoomMessageEvent& event); /** @deprecated If you have a custom event type, construct the event * and pass it as a whole to postMessage() */ |