summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-01-27 17:05:40 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2020-01-27 17:05:40 +0100
commit9c368fa7f448715c2ce04c61097e0cb18091774b (patch)
tree7279170a5fe98b45ae55a7e885c78c50afbb698b /src
parentAllow sending messages as plain text (diff)
downloadnheko-9c368fa7f448715c2ce04c61097e0cb18091774b.tar.xz
Fix reply rendering without markdown in riot
Diffstat (limited to 'src')
-rw-r--r--src/timeline/TimelineModel.cpp23
-rw-r--r--src/timeline/TimelineViewManager.cpp25
2 files changed, 36 insertions, 12 deletions
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp

index fb8c0095..03b7d6a7 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -281,9 +281,26 @@ TimelineModel::data(const QString &id, int role) const case FormattedBody: { const static QRegularExpression replyFallback( "<mx-reply>.*</mx-reply>", QRegularExpression::DotMatchesEverythingOption); - return QVariant( - utils::replaceEmoji(utils::linkifyMessage(utils::escapeBlacklistedHtml( - formattedBodyWithFallback(event).remove(replyFallback))))); + + bool isReply = !in_reply_to_event(event).empty(); + + auto formattedBody_ = QString::fromStdString(formatted_body(event)); + if (formattedBody_.isEmpty()) { + auto body_ = QString::fromStdString(body(event)); + + if (isReply) { + while (body_.startsWith("> ")) + body_ = body_.right(body_.size() - body_.indexOf('\n') - 1); + if (body_.startsWith('\n')) + body_ = body_.right(body_.size() - 1); + } + formattedBody_ = body_.toHtmlEscaped(); + } else { + if (isReply) + formattedBody_ = formattedBody_.remove(replyFallback); + } + return QVariant(utils::replaceEmoji( + utils::linkifyMessage(utils::escapeBlacklistedHtml(formattedBody_)))); } case Url: return QVariant(QString::fromStdString(url(event))); diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index 578d075f..9008d9d2 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp
@@ -186,8 +186,11 @@ TimelineViewManager::queueTextMessage(const QString &msg, const std::optional<Re { mtx::events::msg::Text text = {}; text.body = msg.trimmed().toStdString(); - text.format = "org.matrix.custom.html"; - text.formatted_body = utils::markdownToHtml(msg).toStdString(); + + if (settings->isMarkdownEnabled()) { + text.format = "org.matrix.custom.html"; + text.formatted_body = utils::markdownToHtml(msg).toStdString(); + } if (related) { QString body; @@ -202,14 +205,18 @@ TimelineViewManager::queueTextMessage(const QString &msg, const std::optional<Re } text.body = QString("%1\n%2").arg(body).arg(msg).toStdString(); - text.formatted_body = - utils::getFormattedQuoteBody(*related, utils::markdownToHtml(msg)).toStdString(); - text.relates_to.in_reply_to.event_id = related->related_event; - } - if (!settings->isMarkdownEnabled()) { - text.format = ""; - text.formatted_body = ""; + // NOTE(Nico): rich replies always need a formatted_body! + text.format = "org.matrix.custom.html"; + if (settings->isMarkdownEnabled()) + text.formatted_body = + utils::getFormattedQuoteBody(*related, utils::markdownToHtml(msg)) + .toStdString(); + else + text.formatted_body = + utils::getFormattedQuoteBody(*related, msg.toHtmlEscaped()).toStdString(); + + text.relates_to.in_reply_to.event_id = related->related_event; } if (timeline_)