From 44a7b3c70041fbbcec30bc6e714ac14accad5be9 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Fri, 2 Apr 2021 23:46:12 +0200 Subject: [PATCH] Implement text reactions Makes reacting with text possible by adding a /react command --- src/actionshandler.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/actionshandler.cpp b/src/actionshandler.cpp index e197e5266..c3d97f85c 100644 --- a/src/actionshandler.cpp +++ b/src/actionshandler.cpp @@ -121,6 +121,11 @@ QVariantList ActionsHandler::commands() const QStringLiteral("parameter"), i18nc("@label Parameter of a command", ""), QStringLiteral("help"), i18n("Invites user with given id to current room") }); + commands.append({ + QStringLiteral("prefix"), QStringLiteral("/react "), + QStringLiteral("parameter"), i18nc("@label Parameter of a command", ""), + QStringLiteral("help"), i18n("React to this message with a text") + }); // TODO more see elements /help action @@ -204,6 +209,7 @@ void ActionsHandler::postMessage(const QString &text, static const QString unignorePrefix = QStringLiteral("/unignore "); static const QString queryPrefix = QStringLiteral("/query "); // TODO static const QString msgPrefix = QStringLiteral("/msg "); // TODO + static const QString reactPrefix = QStringLiteral("/react "); // Admin commands @@ -324,6 +330,15 @@ void ActionsHandler::postMessage(const QString &text, return; } + if(rawText.indexOf(reactPrefix) == 0) { + if(replyEventId.isEmpty()) { + return; + } + rawText = rawText.remove(0, reactPrefix.length()); + m_room->toggleReaction(replyEventId, rawText); + return; + } + if (cleanedText.indexOf(mePrefix) == 0) { cleanedText = cleanedText.remove(0, mePrefix.length()); messageEventType = RoomMessageEvent::MsgType::Emote;