From 42d728ac4b5d5a4523ea83ff9a1c0bace926fdd4 Mon Sep 17 00:00:00 2001 From: James Graham Date: Mon, 21 Nov 2022 18:43:29 +0000 Subject: [PATCH] Fix /me giving extra newline Make sure that the emote name is added inside the first paragraph rather than as an additional one. Note alternate to network/neochat!632 because I didn'y realise @tfella had done a patch CCBUG: 461837 --- src/neochatroom.cpp | 25 +++++++++++++++++------- src/qml/Component/Timeline/RichLabel.qml | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index 5065b65e7..98c3d7726 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -460,6 +460,13 @@ QString NeoChatRoom::eventToString(const RoomEvent &evt, Qt::TextFormat format, auto base = url.scheme() + QStringLiteral("://") + url.host() + (url.port() != -1 ? ':' + QString::number(url.port()) : QString()); htmlBody.replace(utils::mxcImageRegExp, QStringLiteral(R"( )").arg(base)); + if (e.msgtype() == MessageEventType::Emote) { + auto author = static_cast(user(e.senderId())); + int firstPara = htmlBody.indexOf("

"); + htmlBody.insert(firstPara == -1 ? 0 : firstPara + 3, + "* " + + author->displayname(this) + " "); + } return htmlBody; } @@ -481,14 +488,18 @@ QString NeoChatRoom::eventToString(const RoomEvent &evt, Qt::TextFormat format, plainBody = e.plainBody(); } - if (prettyPrint) { - if (removeReply) { - plainBody.remove(utils::removeReplyRegex); - } - return Quotient::prettyPrint(plainBody); - } if (removeReply) { - return plainBody.remove(utils::removeReplyRegex); + plainBody = plainBody.remove(utils::removeReplyRegex); + } + if (prettyPrint) { + plainBody = Quotient::prettyPrint(plainBody); + } + if (e.msgtype() == MessageEventType::Emote) { + auto author = static_cast(user(e.senderId())); + plainBody.remove("/me"); + plainBody.insert(0, + "* " + + author->displayname(this) + " "); } return plainBody; }, diff --git a/src/qml/Component/Timeline/RichLabel.qml b/src/qml/Component/Timeline/RichLabel.qml index 3c512a14a..baf7c2a8c 100644 --- a/src/qml/Component/Timeline/RichLabel.qml +++ b/src/qml/Component/Timeline/RichLabel.qml @@ -74,7 +74,7 @@ a{ background: " + Kirigami.Theme.textColor + "; } " : "") + " -" + (isEmote ? "* " + author.displayName + " " : "") + textMessage + (isEdited ? (" " + "" + i18n(" (edited)") + "") : "") +" + textMessage + (isEdited ? (" " + "" + i18n(" (edited)") + "") : "") color: Kirigami.Theme.textColor selectedTextColor: Kirigami.Theme.highlightedTextColor