summary refs log tree commit diff
path: root/src/timeline/InputBar.cpp
diff options
context:
space:
mode:
authorLoren Burkholder <computersemiexpert@outlook.com>2023-03-07 13:11:00 -0500
committerLoren Burkholder <computersemiexpert@outlook.com>2023-04-08 18:59:17 -0400
commit296385e6fe6f9ec543d96ba7ed068e793a12c3f3 (patch)
treec3ed93aad6abca94f22de1f50d6db1f165ca9812 /src/timeline/InputBar.cpp
parentImplement unknown msgtype functionality (diff)
downloadnheko-296385e6fe6f9ec543d96ba7ed068e793a12c3f3.tar.xz
Add rainfall effect
This is a proof-of-concept example of inplementing a msgtype not found
in the spec.
Diffstat (limited to 'src/timeline/InputBar.cpp')
-rw-r--r--src/timeline/InputBar.cpp30
1 files changed, 30 insertions, 0 deletions
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")}; @@ -624,6 +626,30 @@ InputBar::confetti(const QString &body, bool rainbowify) } 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<mtx::crypto::EncryptedFile> &file, const QString &url, @@ -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