diff options
-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() */ |