summary refs log tree commit diff
path: root/src/timeline/InputBar.cpp
diff options
context:
space:
mode:
authorLoren Burkholder <computersemiexpert@outlook.com>2023-03-21 19:44:00 -0400
committerLoren Burkholder <computersemiexpert@outlook.com>2023-04-08 18:59:17 -0400
commit44d4e6f9b5881fdccdb1b08dc5a49d6ee8785c15 (patch)
tree568b95900fdadcd76af2e2e2ddcc136c091586c2 /src/timeline/InputBar.cpp
parentAdd rainfall effect (diff)
downloadnheko-44d4e6f9b5881fdccdb1b08dc5a49d6ee8785c15.tar.xz
Allow sending custom msgtypes
Diffstat (limited to 'src/timeline/InputBar.cpp')
-rw-r--r--src/timeline/InputBar.cpp27
1 files changed, 27 insertions, 0 deletions
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")}; @@ -650,6 +651,30 @@ InputBar::rainfall(const QString &body, bool rainbowify) } 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<mtx::crypto::EncryptedFile> &file, const QString &url, @@ -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