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:
@@ -59,6 +59,7 @@ private Q_SLOTS:
|
||||
void receiveRichtextIn();
|
||||
void receiveRichMxcUrl();
|
||||
void receiveRichPlainUrl();
|
||||
void receiveRichEmote();
|
||||
};
|
||||
|
||||
#ifdef QUOTIENT_07
|
||||
@@ -148,6 +149,22 @@ void TextHandlerTest::initTestCase()
|
||||
"unsigned": {
|
||||
"age": 1235
|
||||
}
|
||||
},
|
||||
{
|
||||
"content": {
|
||||
"body": "/me This is an emote.",
|
||||
"format": "org.matrix.custom.html",
|
||||
"formatted_body": "This is an emote.",
|
||||
"msgtype": "m.emote"
|
||||
},
|
||||
"event_id": "$153273582443PhrSn:example.org",
|
||||
"origin_server_ts": 1532735824654,
|
||||
"room_id": "!jEsUZKDJdhlrceRyVU:example.org",
|
||||
"sender": "@example:example.org",
|
||||
"type": "m.room.message",
|
||||
"unsigned": {
|
||||
"age": 1236
|
||||
}
|
||||
}
|
||||
],
|
||||
"limited": true,
|
||||
@@ -439,7 +456,7 @@ void TextHandlerTest::receiveRichMxcUrl()
|
||||
TextHandler testTextHandler;
|
||||
testTextHandler.setData(testInputString);
|
||||
|
||||
QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText, room, room->messageEvents().back().get()), testOutputString);
|
||||
QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText, room, room->messageEvents().at(0).get()), testOutputString);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -498,5 +515,19 @@ void TextHandlerTest::receiveRichPlainUrl()
|
||||
QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText), testOutputStringMxId);
|
||||
}
|
||||
|
||||
// Test that user pill is add to an emote message.
|
||||
// N.B. The second message in the test timeline is marked as an emote.
|
||||
void TextHandlerTest::receiveRichEmote()
|
||||
{
|
||||
const QString testInputString = QStringLiteral("This is an emote.");
|
||||
const QString testOutputString =
|
||||
QStringLiteral("* <a href=\"https://matrix.to/#/@example:example.org\" style=\"color:#000000\">@example:example.org</a> This is an emote.");
|
||||
|
||||
TextHandler testTextHandler;
|
||||
testTextHandler.setData(testInputString);
|
||||
|
||||
QCOMPARE(testTextHandler.handleRecieveRichText(Qt::RichText, room, room->messageEvents().at(1).get()), testOutputString);
|
||||
}
|
||||
|
||||
QTEST_MAIN(TextHandlerTest)
|
||||
#include "texthandlertest.moc"
|
||||
|
||||
@@ -20,9 +20,7 @@ DelegateChooser {
|
||||
|
||||
DelegateChoice {
|
||||
roleValue: MessageEventModel.Emote
|
||||
delegate: MessageDelegate {
|
||||
isEmote: true
|
||||
}
|
||||
delegate: MessageDelegate {}
|
||||
}
|
||||
|
||||
DelegateChoice {
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.kde.neochat 1.0
|
||||
TimelineContainer {
|
||||
id: messageDelegate
|
||||
|
||||
property bool isEmote: false
|
||||
onOpenContextMenu: openMessageContext(model, label.selectedText, Controller.plainText(label.textDocument))
|
||||
|
||||
innerObject: ColumnLayout {
|
||||
@@ -22,7 +21,6 @@ TimelineContainer {
|
||||
id: label
|
||||
Layout.fillWidth: true
|
||||
visible: currentRoom.chatBoxEditId !== model.eventId
|
||||
isEmote: messageDelegate.isEmote
|
||||
}
|
||||
Loader {
|
||||
Layout.fillWidth: true
|
||||
|
||||
@@ -14,7 +14,6 @@ TextEdit {
|
||||
readonly property var isEmoji: /^(<span style='.*'>)?(\u00a9|\u00ae|[\u20D0-\u2fff]|[\u3190-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])+(<\/span>)?$/
|
||||
readonly property var hasSpoiler: /data-mx-spoiler/g
|
||||
|
||||
property bool isEmote: false
|
||||
property bool isReplyLabel: false
|
||||
property string textMessage: model.display
|
||||
property bool spoilerRevealed: !hasSpoiler.test(textMessage)
|
||||
@@ -60,7 +59,7 @@ a{
|
||||
background: " + Kirigami.Theme.textColor + ";
|
||||
}
|
||||
" : "") + "
|
||||
</style>" + (isEmote ? "* <a href='https://matrix.to/#/" + author.id + "' style='color: " + author.color + "'>" + author.displayName + "</a> " : "") + textMessage + (isEdited && !contentLabel.isReplyLabel ? (" <span style=\"color: " + Kirigami.Theme.disabledTextColor + "\">" + "<span style='font-size: " + Kirigami.Theme.defaultFont.pixelSize +"px'>" + i18n(" (edited)") + "</span>") : "")
|
||||
</style>" + textMessage + (isEdited && !contentLabel.isReplyLabel ? (" <span style=\"color: " + Kirigami.Theme.disabledTextColor + "\">" + "<span style='font-size: " + Kirigami.Theme.defaultFont.pixelSize +"px'>" + i18n(" (edited)") + "</span>") : "")
|
||||
|
||||
color: Kirigami.Theme.textColor
|
||||
selectedTextColor: Kirigami.Theme.highlightedTextColor
|
||||
|
||||
@@ -21,7 +21,6 @@ ColumnLayout {
|
||||
default property alias innerObject : column.children
|
||||
|
||||
property Item hoverComponent: hoverActions ?? null
|
||||
property bool isEmote: false
|
||||
property bool cardBackground: true
|
||||
property bool showUserMessageOnRight: Config.showLocalMessagesOnRight && model.author.isLocalUser && !Config.compactLayout
|
||||
property bool isHighlighted: model.isHighlighted || isTemporaryHighlighted
|
||||
@@ -212,7 +211,7 @@ ColumnLayout {
|
||||
id: rowLayout
|
||||
|
||||
spacing: Kirigami.Units.smallSpacing
|
||||
visible: model.showAuthor && !isEmote
|
||||
visible: model.showAuthor
|
||||
|
||||
QQC2.Label {
|
||||
id: nameLabel
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user