summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-13 16:10:45 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-09-13 16:10:45 +0300
commit9f3de8679de1e6fba6d5f44231b9a623ff94f87f (patch)
tree3afe2e3c6a37b02af6680417e9385a3397a23445 /src
parentStrip paragraph tags (diff)
downloadnheko-9f3de8679de1e6fba6d5f44231b9a623ff94f87f.tar.xz
Temporary fix to work with mx-reply tags
Diffstat (limited to 'src')
-rw-r--r--src/Utils.cpp15
-rw-r--r--src/timeline/TimelineItem.cpp6
2 files changed, 15 insertions, 6 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 308c0af9..2bad72bf 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -285,7 +285,14 @@ utils::humanReadableFingerprint(const QString &ed25519)
 QString
 utils::linkifyMessage(const QString &body)
 {
-        QXmlStreamReader xml{"<html>" + body + "</html>"};
+        // Convert to valid XML.
+        auto doc = QString("<html>%1</html>").arg(body);
+
+        doc.replace("<mx-reply>", "");
+        doc.replace("</mx-reply>", "");
+        doc.replace("<br>", "<br></br>");
+
+        QXmlStreamReader xml{doc};
 
         QString textString;
         while (!xml.atEnd() && !xml.hasError()) {
@@ -330,8 +337,10 @@ utils::linkifyMessage(const QString &body)
         }
 
         if (xml.hasError()) {
-                // qWarning() << "error while parsing xml";
-                return body;
+                qWarning() << "error while parsing xml" << xml.errorString() << doc;
+                doc.replace("<html>", "");
+                doc.replace("</html>", "");
+                return doc;
         }
 
         return textString;
diff --git a/src/timeline/TimelineItem.cpp b/src/timeline/TimelineItem.cpp
index cd12207c..c2bd98d9 100644
--- a/src/timeline/TimelineItem.cpp
+++ b/src/timeline/TimelineItem.cpp
@@ -494,7 +494,7 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Notice
         const auto timestamp = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
 
         auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
-        auto body           = QString::fromStdString(event.content.body).trimmed();
+        auto body           = QString::fromStdString(event.content.body).trimmed().toHtmlEscaped();
 
         descriptionMsg_ = {Cache::displayName(room_id_, sender),
                            sender,
@@ -539,7 +539,7 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Emote>
         const auto sender = QString::fromStdString(event.sender);
 
         auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
-        auto body           = QString::fromStdString(event.content.body).trimmed();
+        auto body           = QString::fromStdString(event.content.body).trimmed().toHtmlEscaped();
 
         auto timestamp   = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
         auto displayName = Cache::displayName(room_id_, sender);
@@ -586,7 +586,7 @@ TimelineItem::TimelineItem(const mtx::events::RoomEvent<mtx::events::msg::Text>
         const auto sender = QString::fromStdString(event.sender);
 
         auto formatted_body = utils::linkifyMessage(utils::getMessageBody(event).trimmed());
-        auto body           = QString::fromStdString(event.content.body).trimmed();
+        auto body           = QString::fromStdString(event.content.body).trimmed().toHtmlEscaped();
 
         auto timestamp   = QDateTime::fromMSecsSinceEpoch(event.origin_server_ts);
         auto displayName = Cache::displayName(room_id_, sender);