Remove NeoChatUser and just use Quotient::User this simplifies things and avoids casting from one to the other which address santizer didn't like

This commit is contained in:
James Graham
2023-07-30 15:34:12 +01:00
parent 403c1ed391
commit 25e0e3fa8e
19 changed files with 110 additions and 163 deletions

View File

@@ -4,8 +4,9 @@
#include "texthandler.h"
#include <QDebug>
#include <QUrl>
#include <QGuiApplication>
#include <QStringLiteral>
#include <QUrl>
#include <Quotient/events/roommessageevent.h>
#include <Quotient/util.h>
@@ -76,6 +77,13 @@ QString TextHandler::handleSendText()
return outputString;
}
static QColor polishColor(qreal hueF)
{
const auto lightness = static_cast<QGuiApplication *>(QGuiApplication::instance())->palette().color(QPalette::Active, QPalette::Window).lightnessF();
// https://github.com/quotient-im/libQuotient/wiki/User-color-coding-standard-draft-proposal
return QColor::fromHslF(hueF, 1, -0.7 * lightness + 0.9, 1);
}
QString TextHandler::handleRecieveRichText(Qt::TextFormat inputFormat, const NeoChatRoom *room, const Quotient::RoomEvent *event, bool stripNewlines)
{
m_pos = 0;
@@ -135,9 +143,9 @@ QString TextHandler::handleRecieveRichText(Qt::TextFormat inputFormat, const Neo
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()));
auto author = 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> ");
+ polishColor(author->hueF()).name() + QStringLiteral("\">") + author->displayname(room) + QStringLiteral("</a> ");
if (outputString.startsWith(QStringLiteral("<p>"))) {
outputString.insert(3, emoteString);
} else {