From 71651b81a8649db49bf3541e1392094270b506fb Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Sun, 17 Nov 2024 20:17:39 +0100 Subject: [PATCH] Get rid of reply fallback in text messages since MSC2781 is merged --- src/Utils.cpp | 44 +++++---------------------------------- src/Utils.h | 8 ------- src/timeline/InputBar.cpp | 35 ------------------------------- 3 files changed, 5 insertions(+), 82 deletions(-) diff --git a/src/Utils.cpp b/src/Utils.cpp index 99d337c4..4838f4e1 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -42,6 +42,9 @@ #include "MatrixClient.h" #include "UserSettingsPage.h" +static QString +getQuoteBody(const RelatedInfo &related); + //! Match widgets/events with a description message. namespace { template @@ -267,7 +270,7 @@ utils::stripReplyFallbacks(const mtx::events::collections::TimelineEvents &event related.quoted_body = QString::fromStdString(mtx::accessors::body(event)); related.quoted_body = QString::fromStdString(stripReplyFromBody(related.quoted_body.toStdString())); - related.quoted_body = utils::getQuoteBody(related); + related.quoted_body = getQuoteBody(related); // get quoted body and strip reply fallback related.quoted_formatted_body = mtx::accessors::formattedBodyWithFallback(event); @@ -1149,44 +1152,7 @@ utils::markdownToHtml(const QString &text, bool rainbowify_, bool noExtensions) } QString -utils::getFormattedQuoteBody(const RelatedInfo &related, const QString &html) -{ - auto getFormattedBody = [related]() -> QString { - using MsgType = mtx::events::MessageType; - - switch (related.type) { - case MsgType::File: { - return QStringLiteral("sent a file."); - } - case MsgType::Image: { - return QStringLiteral("sent an image."); - } - case MsgType::Audio: { - return QStringLiteral("sent an audio file."); - } - case MsgType::Video: { - return QStringLiteral("sent a video"); - } - default: { - return escapeBlacklistedHtml(related.quoted_formatted_body); - } - } - }; - - return QStringLiteral("
In reply " - "to %4%5
") - .arg(related.room, - QString::fromStdString(related.related_event), - QUrl::toPercentEncoding(related.quoted_user), - related.quoted_user.toHtmlEscaped(), - getFormattedBody()) + - html; -} - -QString -utils::getQuoteBody(const RelatedInfo &related) +getQuoteBody(const RelatedInfo &related) { using MsgType = mtx::events::MessageType; diff --git a/src/Utils.h b/src/Utils.h index 9c5e4713..cf7e5a80 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -147,14 +147,6 @@ escapeMentionMarkdown(QString input); QString escapeBlacklistedHtml(const QString &data); -//! Generate a Rich Reply quote message -QString -getFormattedQuoteBody(const RelatedInfo &related, const QString &html); - -//! Get the body for the quote, depending on the event type. -QString -getQuoteBody(const RelatedInfo &related); - //! Retrieve the color of the links based on the current theme. QString linkColor(); diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index e967da8c..270e261e 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -560,41 +560,6 @@ InputBar::message(const QString &msg, MarkdownOverride useMarkdown, bool rainbow text.mentions = generateMentions(); text.relations = generateRelations(); - if (!room->reply().isEmpty() && room->thread().isEmpty() && room->edit().isEmpty()) { - auto related = room->relatedInfo(room->reply()); - - // Skip reply fallbacks to users who would cause a room ping with the fallback. - // This should be fine, since in some cases the reply fallback can be omitted now and the - // alternative is worse! On Element Android this applies to any substring, but that is their - // bug to fix. - if (!related.quoted_user.startsWith("@room:")) { - QString body; - bool firstLine = true; - auto lines = QStringView(related.quoted_body).split(u'\n'); - for (auto line : std::as_const(lines)) { - if (firstLine) { - firstLine = false; - body = QStringLiteral("> <%1> %2\n").arg(related.quoted_user, line); - } else { - body += QStringLiteral("> %1\n").arg(line); - } - } - - text.body = fmt::format("{}\n{}", body.toStdString(), text.body); - - // NOTE(Nico): rich replies always need a formatted_body! - text.format = "org.matrix.custom.html"; - if ((ChatPage::instance()->userSettings()->markdown() && - useMarkdown == MarkdownOverride::NOT_SPECIFIED) || - useMarkdown == MarkdownOverride::ON) - text.formatted_body = - utils::getFormattedQuoteBody(related, utils::markdownToHtml(msg, rainbowify)) - .toStdString(); - else - text.formatted_body = - utils::getFormattedQuoteBody(related, msg.toHtmlEscaped()).toStdString(); - } - } room->sendMessageEvent(text, mtx::events::EventType::RoomMessage); }