mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Get rid of reply fallback in text messages since MSC2781 is merged
This commit is contained in:
parent
0b368827bf
commit
71651b81a8
3 changed files with 5 additions and 82 deletions
|
@ -42,6 +42,9 @@
|
||||||
#include "MatrixClient.h"
|
#include "MatrixClient.h"
|
||||||
#include "UserSettingsPage.h"
|
#include "UserSettingsPage.h"
|
||||||
|
|
||||||
|
static QString
|
||||||
|
getQuoteBody(const RelatedInfo &related);
|
||||||
|
|
||||||
//! Match widgets/events with a description message.
|
//! Match widgets/events with a description message.
|
||||||
namespace {
|
namespace {
|
||||||
template<class T>
|
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(mtx::accessors::body(event));
|
||||||
related.quoted_body =
|
related.quoted_body =
|
||||||
QString::fromStdString(stripReplyFromBody(related.quoted_body.toStdString()));
|
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
|
// get quoted body and strip reply fallback
|
||||||
related.quoted_formatted_body = mtx::accessors::formattedBodyWithFallback(event);
|
related.quoted_formatted_body = mtx::accessors::formattedBodyWithFallback(event);
|
||||||
|
@ -1149,44 +1152,7 @@ utils::markdownToHtml(const QString &text, bool rainbowify_, bool noExtensions)
|
||||||
}
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
utils::getFormattedQuoteBody(const RelatedInfo &related, const QString &html)
|
getQuoteBody(const RelatedInfo &related)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
using MsgType = mtx::events::MessageType;
|
using MsgType = mtx::events::MessageType;
|
||||||
|
|
||||||
|
|
|
@ -147,14 +147,6 @@ escapeMentionMarkdown(QString input);
|
||||||
QString
|
QString
|
||||||
escapeBlacklistedHtml(const QString &data);
|
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.
|
//! Retrieve the color of the links based on the current theme.
|
||||||
QString
|
QString
|
||||||
linkColor();
|
linkColor();
|
||||||
|
|
|
@ -560,41 +560,6 @@ InputBar::message(const QString &msg, MarkdownOverride useMarkdown, bool rainbow
|
||||||
|
|
||||||
text.mentions = generateMentions();
|
text.mentions = generateMentions();
|
||||||
text.relations = generateRelations();
|
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);
|
room->sendMessageEvent(text, mtx::events::EventType::RoomMessage);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue