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/timeline/InputBar.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index b27128e0..cb7c3919 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -281,6 +281,8 @@ InputBar::updateTextContentProperties(const QString &t) QStringLiteral("rainbownotice"), QStringLiteral("confetti"), QStringLiteral("rainbowconfetti"), + QStringLiteral("rain"), + QStringLiteral("rainbowrain"), QStringLiteral("goto"), QStringLiteral("converttodm"), QStringLiteral("converttoroom")}; @@ -623,6 +625,30 @@ InputBar::confetti(const QString &body, bool rainbowify) room->sendMessageEvent(confetti, mtx::events::EventType::RoomMessage); } +void +InputBar::rainfall(const QString &body, bool rainbowify) +{ + auto html = utils::markdownToHtml(body, rainbowify); + + mtx::events::msg::Unknown rain; + rain.msgtype = "io.element.effect.rainfall"; + rain.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"; + rain.content = j.dump(); + // Remove markdown links by completer + rain.body = replaceMatrixToMarkdownLink(body.trimmed()).toStdString(); + } + + rain.relations = generateRelations(); + + room->sendMessageEvent(rain, mtx::events::EventType::RoomMessage); +} + void InputBar::image(const QString &filename, const std::optional &file, @@ -890,6 +916,10 @@ InputBar::command(const QString &command, QString args) confetti(args, false); } else if (command == QLatin1String("rainbowconfetti")) { confetti(args, true); + } else if (command == QLatin1String("rainfall")) { + rainfall(args, false); + } else if (command == QLatin1String("rainbowrain")) { + rainfall(args, true); } else if (command == QLatin1String("goto")) { // Goto has three different modes: // 1 - Going directly to a given event ID -- 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/timeline/InputBar.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 0c1cd7a3595889abd338c98ecda9a1b010a2406a Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Sat, 25 Mar 2023 20:02:22 -0400 Subject: Fix command name --- src/timeline/InputBar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 23e94945..0fa5cff4 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -281,7 +281,7 @@ InputBar::updateTextContentProperties(const QString &t) QStringLiteral("rainbownotice"), QStringLiteral("confetti"), QStringLiteral("rainbowconfetti"), - QStringLiteral("rain"), + QStringLiteral("rainfall"), QStringLiteral("rainbowrain"), QStringLiteral("msgtype"), QStringLiteral("goto"), -- cgit 1.5.1 From b95388a5b9a546be4725d846ec62d120166cb357 Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Sat, 25 Mar 2023 20:02:50 -0400 Subject: Don't allow rainbowifying custom messages --- src/timeline/InputBar.cpp | 6 +++--- src/timeline/InputBar.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/timeline/InputBar.cpp') diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 0fa5cff4..3a14790c 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -651,9 +651,9 @@ InputBar::rainfall(const QString &body, bool rainbowify) } void -InputBar::customMsgtype(const QString &msgtype, const QString &body, bool rainbowify) +InputBar::customMsgtype(const QString &msgtype, const QString &body) { - auto html = utils::markdownToHtml(body, rainbowify); + auto html = utils::markdownToHtml(body); mtx::events::msg::Unknown msg; msg.msgtype = msgtype.toStdString(); @@ -946,7 +946,7 @@ InputBar::command(const QString &command, QString args) } else if (command == QLatin1String("rainbowrain")) { rainfall(args, true); } else if (command == QLatin1String("msgtype")) { - customMsgtype(args.section(' ', 0, 0), args.section(' ', 1, -1), false); + customMsgtype(args.section(' ', 0, 0), args.section(' ', 1, -1)); } 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 61ba9f12..4d836375 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -243,7 +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); + void customMsgtype(const QString &msgtype, const QString &body); 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/timeline/InputBar.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 From 138b0a6b8683a8e69a4d2fb92926e5a0645d4d5a Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Sat, 1 Apr 2023 15:41:49 -0400 Subject: Use the new mtxclient special effects refactoring --- CMakeLists.txt | 2 +- io.github.NhekoReborn.Nheko.yaml | 2 +- resources/qml/delegates/MessageDelegate.qml | 2 +- src/Utils.cpp | 32 +++++++++++----------- src/Utils.h | 37 ++++++++++++------------- src/timeline/InputBar.cpp | 5 ++-- src/timeline/TimelineModel.cpp | 42 ++++++++++++++++++----------- src/timeline/TimelineModel.h | 2 +- 8 files changed, 69 insertions(+), 55 deletions(-) (limited to 'src/timeline/InputBar.cpp') diff --git a/CMakeLists.txt b/CMakeLists.txt index 06af4bbe..146a3e25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -602,7 +602,7 @@ if(USE_BUNDLED_MTXCLIENT) FetchContent_Declare( MatrixClient GIT_REPOSITORY https://github.com/Nheko-Reborn/mtxclient.git - GIT_TAG c8849cd033bb59bee39f3fb2eaca953853731eb2 + GIT_TAG f8a9cbbb25ea145a23506c2f9386f6c61401bed0 ) set(BUILD_LIB_EXAMPLES OFF CACHE INTERNAL "") set(BUILD_LIB_TESTS OFF CACHE INTERNAL "") diff --git a/io.github.NhekoReborn.Nheko.yaml b/io.github.NhekoReborn.Nheko.yaml index 3bcfdf52..26c2020f 100644 --- a/io.github.NhekoReborn.Nheko.yaml +++ b/io.github.NhekoReborn.Nheko.yaml @@ -213,7 +213,7 @@ modules: buildsystem: cmake-ninja name: mtxclient sources: - - commit: c8849cd033bb59bee39f3fb2eaca953853731eb2 + - commit: f8a9cbbb25ea145a23506c2f9386f6c61401bed0 #tag: v0.9.2 type: git url: https://github.com/Nheko-Reborn/mtxclient.git diff --git a/resources/qml/delegates/MessageDelegate.qml b/resources/qml/delegates/MessageDelegate.qml index 9126186e..c0bcec0d 100644 --- a/resources/qml/delegates/MessageDelegate.qml +++ b/resources/qml/delegates/MessageDelegate.qml @@ -116,7 +116,7 @@ Item { } DelegateChoice { - roleValue: MtxEvent.ConfettiMessage + roleValue: MtxEvent.ElementEffectMessage TextMessage { formatted: d.formattedBody diff --git a/src/Utils.cpp b/src/Utils.cpp index eca5cb29..2bf8eb3b 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -215,20 +215,20 @@ utils::getMessageDescription(const TimelineEvent &event, const QString &localUser, const QString &displayName) { - using Audio = mtx::events::RoomEvent; - using Emote = mtx::events::RoomEvent; - using File = mtx::events::RoomEvent; - using Image = mtx::events::RoomEvent; - using Notice = mtx::events::RoomEvent; - using Text = mtx::events::RoomEvent; - using Unknown = mtx::events::RoomEvent; - using Video = mtx::events::RoomEvent; - using Confetti = mtx::events::RoomEvent; - using CallInvite = mtx::events::RoomEvent; - using CallAnswer = mtx::events::RoomEvent; - using CallHangUp = mtx::events::RoomEvent; - using CallReject = mtx::events::RoomEvent; - using Encrypted = mtx::events::EncryptedEvent; + using Audio = mtx::events::RoomEvent; + using Emote = mtx::events::RoomEvent; + using File = mtx::events::RoomEvent; + using Image = mtx::events::RoomEvent; + using Notice = mtx::events::RoomEvent; + using Text = mtx::events::RoomEvent; + using Unknown = mtx::events::RoomEvent; + using Video = mtx::events::RoomEvent; + using ElementEffect = mtx::events::RoomEvent; + using CallInvite = mtx::events::RoomEvent; + using CallAnswer = mtx::events::RoomEvent; + using CallHangUp = mtx::events::RoomEvent; + using CallReject = mtx::events::RoomEvent; + using Encrypted = mtx::events::EncryptedEvent; if (std::holds_alternative