Get rid of reply fallback in text messages since MSC2781 is merged

This commit is contained in:
Nicolas Werner 2024-11-17 20:17:39 +01:00
parent 0b368827bf
commit 71651b81a8
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
3 changed files with 5 additions and 82 deletions

View file

@ -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<class T>
@ -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("<mx-reply><blockquote><a "
"href=\"https://matrix.to/#/%1/%2\">In reply "
"to</a> <a href=\"https://matrix.to/#/%3\">%4</a><br"
"/>%5</blockquote></mx-reply>")
.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;

View file

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

View file

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