Temporary fix to work with mx-reply tags

This commit is contained in:
Konstantinos Sideris 2018-09-13 16:10:45 +03:00
parent bf4d559523
commit 9f3de8679d
2 changed files with 15 additions and 6 deletions

View file

@ -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;

View file

@ -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);