Handle emotes in texthander

This moves the code to add the emote user pill into texthandler removing the now redundant checks from the message delegates.
This commit is contained in:
James Graham
2023-04-07 19:03:04 +00:00
parent abd56baa51
commit be3b5cdb8a
6 changed files with 51 additions and 10 deletions

View File

@@ -6,6 +6,7 @@
#include <QDebug>
#include <QUrl>
#include <events/roommessageevent.h>
#include <util.h>
#include <cmark.h>
@@ -134,6 +135,21 @@ QString TextHandler::handleRecieveRichText(Qt::TextFormat inputFormat, const Neo
nextTokenType();
}
// If the message is an emote add the user pill to the front of the message.
if (event != nullptr) {
auto e = eventCast<const Quotient::RoomMessageEvent>(event);
if (e->msgtype() == Quotient::MessageEventType::Emote) {
auto author = static_cast<NeoChatUser *>(room->user(e->senderId()));
QString emoteString = QStringLiteral("* <a href=\"https://matrix.to/#/") + e->senderId() + QStringLiteral("\" style=\"color:")
+ author->color().name() + QStringLiteral("\">") + author->displayname(room) + QStringLiteral("</a> ");
if (outputString.startsWith(QStringLiteral("<p>"))) {
outputString.insert(3, emoteString);
} else {
outputString.prepend(emoteString);
}
}
}
/**
* Replace <del> with <s>
* Note: <s> is still not a valid tag for the message from the server. We