Implement text reactions

Makes reacting with text possible by adding a /react command
This commit is contained in:
Tobias Fella
2021-04-02 23:46:12 +02:00
parent 868d8108ac
commit 44a7b3c700

View File

@@ -121,6 +121,11 @@ QVariantList ActionsHandler::commands() const
QStringLiteral("parameter"), i18nc("@label Parameter of a command", "<user-id>"),
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", "<reaction text>"),
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;