From 296385e6fe6f9ec543d96ba7ed068e793a12c3f3 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Tue, 7 Mar 2023 13:11:00 -0500 Subject: Add rainfall effect This is a proof-of-concept example of inplementing a msgtype not found in the spec. --- src/CommandCompleter.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/CommandCompleter.cpp') diff --git a/src/CommandCompleter.cpp b/src/CommandCompleter.cpp index 2ec427d6..a0fb101d 100644 --- a/src/CommandCompleter.cpp +++ b/src/CommandCompleter.cpp @@ -87,6 +87,10 @@ CommandCompleter::data(const QModelIndex &index, int role) const return QStringLiteral("/confetti "); case RainbowConfetti: return QStringLiteral("/rainbowconfetti "); + case Rainfall: + return QStringLiteral("/rainfall "); + case RainbowRain: + return QStringLiteral("/rainbowrain "); case Goto: return QStringLiteral("/goto "); case ConvertToDm: @@ -156,6 +160,10 @@ CommandCompleter::data(const QModelIndex &index, int role) const return tr("/confetti [message]"); case RainbowConfetti: return tr("/rainbowconfetti [message]"); + case Rainfall: + return tr("/rainfall [message]"); + case RainbowRain: + return tr("/rainbowrain [message]"); case Goto: return tr("/goto "); case ConvertToDm: @@ -225,6 +233,10 @@ CommandCompleter::data(const QModelIndex &index, int role) const return tr("Send a message with confetti."); case RainbowConfetti: return tr("Send a message in rainbow colors with confetti."); + case Rainfall: + return tr("Send a message with rain."); + case RainbowRain: + return tr("Send a message in rainbow colors with rain."); case Goto: return tr("Go to a specific message using an event id, index or matrix: link"); case ConvertToDm: -- cgit 1.5.1 From 44d4e6f9b5881fdccdb1b08dc5a49d6ee8785c15 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Tue, 21 Mar 2023 19:44:00 -0400 Subject: Allow sending custom msgtypes --- src/CommandCompleter.cpp | 6 ++++++ src/CommandCompleter.h | 1 + src/timeline/InputBar.cpp | 27 +++++++++++++++++++++++++++ src/timeline/InputBar.h | 1 + 4 files changed, 35 insertions(+) (limited to 'src/CommandCompleter.cpp') diff --git a/src/CommandCompleter.cpp b/src/CommandCompleter.cpp index a0fb101d..c4674315 100644 --- a/src/CommandCompleter.cpp +++ b/src/CommandCompleter.cpp @@ -91,6 +91,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const return QStringLiteral("/rainfall "); case RainbowRain: return QStringLiteral("/rainbowrain "); + case Msgtype: + return QStringLiteral("/msgtype "); case Goto: return QStringLiteral("/goto "); case ConvertToDm: @@ -164,6 +166,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const return tr("/rainfall [message]"); case RainbowRain: return tr("/rainbowrain [message]"); + case Msgtype: + return tr("/msgtype [message]"); case Goto: return tr("/goto "); case ConvertToDm: @@ -237,6 +241,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const return tr("Send a message with rain."); case RainbowRain: return tr("Send a message in rainbow colors with rain."); + case Msgtype: + return tr("Send a message with a custom message type."); case Goto: return tr("Go to a specific message using an event id, index or matrix: link"); case ConvertToDm: diff --git a/src/CommandCompleter.h b/src/CommandCompleter.h index be5250b8..dda3bb55 100644 --- a/src/CommandCompleter.h +++ b/src/CommandCompleter.h @@ -48,6 +48,7 @@ public: RainbowConfetti, Rainfall, RainbowRain, + Msgtype, Goto, ConvertToDm, ConvertToRoom, diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index cb7c3919..23e94945 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -283,6 +283,7 @@ InputBar::updateTextContentProperties(const QString &t) QStringLiteral("rainbowconfetti"), QStringLiteral("rain"), QStringLiteral("rainbowrain"), + QStringLiteral("msgtype"), QStringLiteral("goto"), QStringLiteral("converttodm"), QStringLiteral("converttoroom")}; @@ -649,6 +650,30 @@ InputBar::rainfall(const QString &body, bool rainbowify) room->sendMessageEvent(rain, mtx::events::EventType::RoomMessage); } +void +InputBar::customMsgtype(const QString &msgtype, const QString &body, bool rainbowify) +{ + auto html = utils::markdownToHtml(body, rainbowify); + + mtx::events::msg::Unknown msg; + msg.msgtype = msgtype.toStdString(); + msg.body = body.trimmed().toStdString(); + + if (html != body.trimmed().toHtmlEscaped() && + ChatPage::instance()->userSettings()->markdown()) { + nlohmann::json j; + j["formatted_body"] = html.toStdString(); + j["format"] = "org.matrix.custom.html"; + msg.content = j.dump(); + // Remove markdown links by completer + msg.body = replaceMatrixToMarkdownLink(body.trimmed()).toStdString(); + } + + msg.relations = generateRelations(); + + room->sendMessageEvent(msg, mtx::events::EventType::RoomMessage); +} + void InputBar::image(const QString &filename, const std::optional &file, @@ -920,6 +945,8 @@ InputBar::command(const QString &command, QString args) rainfall(args, false); } else if (command == QLatin1String("rainbowrain")) { rainfall(args, true); + } else if (command == QLatin1String("msgtype")) { + customMsgtype(args.section(' ', 0, 0), args.section(' ', 1, -1), false); } else if (command == QLatin1String("goto")) { // Goto has three different modes: // 1 - Going directly to a given event ID diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index a34427ba..61ba9f12 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -243,6 +243,7 @@ private: void notice(const QString &body, bool rainbowify); void confetti(const QString &body, bool rainbowify); void rainfall(const QString &body, bool rainbowify); + void customMsgtype(const QString &msgtype, const QString &body, bool rainbowify); bool command(const QString &name, QString args); void image(const QString &filename, const std::optional &file, -- cgit 1.5.1 From e026242a62aad2036e9f72c6f0048811e3dc1a2b Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Sat, 1 Apr 2023 15:40:58 -0400 Subject: Don't bother with rainbow rain --- src/CommandCompleter.cpp | 6 ------ src/CommandCompleter.h | 1 - src/timeline/InputBar.cpp | 9 +++------ src/timeline/InputBar.h | 2 +- 4 files changed, 4 insertions(+), 14 deletions(-) (limited to 'src/CommandCompleter.cpp') diff --git a/src/CommandCompleter.cpp b/src/CommandCompleter.cpp index c4674315..8123b8e6 100644 --- a/src/CommandCompleter.cpp +++ b/src/CommandCompleter.cpp @@ -89,8 +89,6 @@ CommandCompleter::data(const QModelIndex &index, int role) const return QStringLiteral("/rainbowconfetti "); case Rainfall: return QStringLiteral("/rainfall "); - case RainbowRain: - return QStringLiteral("/rainbowrain "); case Msgtype: return QStringLiteral("/msgtype "); case Goto: @@ -164,8 +162,6 @@ CommandCompleter::data(const QModelIndex &index, int role) const return tr("/rainbowconfetti [message]"); case Rainfall: return tr("/rainfall [message]"); - case RainbowRain: - return tr("/rainbowrain [message]"); case Msgtype: return tr("/msgtype [message]"); case Goto: @@ -239,8 +235,6 @@ CommandCompleter::data(const QModelIndex &index, int role) const return tr("Send a message in rainbow colors with confetti."); case Rainfall: return tr("Send a message with rain."); - case RainbowRain: - return tr("Send a message in rainbow colors with rain."); case Msgtype: return tr("Send a message with a custom message type."); case Goto: diff --git a/src/CommandCompleter.h b/src/CommandCompleter.h index dda3bb55..4f27fe29 100644 --- a/src/CommandCompleter.h +++ b/src/CommandCompleter.h @@ -47,7 +47,6 @@ public: Confetti, RainbowConfetti, Rainfall, - RainbowRain, Msgtype, Goto, ConvertToDm, diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 3a14790c..d3810cf8 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -282,7 +282,6 @@ InputBar::updateTextContentProperties(const QString &t) QStringLiteral("confetti"), QStringLiteral("rainbowconfetti"), QStringLiteral("rainfall"), - QStringLiteral("rainbowrain"), QStringLiteral("msgtype"), QStringLiteral("goto"), QStringLiteral("converttodm"), @@ -627,9 +626,9 @@ InputBar::confetti(const QString &body, bool rainbowify) } void -InputBar::rainfall(const QString &body, bool rainbowify) +InputBar::rainfall(const QString &body) { - auto html = utils::markdownToHtml(body, rainbowify); + auto html = utils::markdownToHtml(body); mtx::events::msg::Unknown rain; rain.msgtype = "io.element.effect.rainfall"; @@ -942,9 +941,7 @@ InputBar::command(const QString &command, QString args) } else if (command == QLatin1String("rainbowconfetti")) { confetti(args, true); } else if (command == QLatin1String("rainfall")) { - rainfall(args, false); - } else if (command == QLatin1String("rainbowrain")) { - rainfall(args, true); + rainfall(args); } else if (command == QLatin1String("msgtype")) { customMsgtype(args.section(' ', 0, 0), args.section(' ', 1, -1)); } else if (command == QLatin1String("goto")) { diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index 4d836375..b2db377f 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -242,7 +242,7 @@ private: void emote(const QString &body, bool rainbowify); void notice(const QString &body, bool rainbowify); void confetti(const QString &body, bool rainbowify); - void rainfall(const QString &body, bool rainbowify); + void rainfall(const QString &body); void customMsgtype(const QString &msgtype, const QString &body); bool command(const QString &name, QString args); void image(const QString &filename, -- cgit 1.5.1