From 2e597263a22b9dc3916d75839746bdd81a39a329 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Sun, 11 Apr 2021 21:47:20 +0200 Subject: [PATCH] add notice and rainbownotice commands --- src/timeline/InputBar.cpp | 33 +++++++++++++++++++++++++++++++++ src/timeline/InputBar.h | 1 + 2 files changed, 34 insertions(+) diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp index 38c08d1c..cda38b75 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp @@ -349,6 +349,35 @@ InputBar::emote(QString msg, bool rainbowify) room->sendMessageEvent(emote, mtx::events::EventType::RoomMessage); } +void +InputBar::notice(QString msg, bool rainbowify) +{ + auto html = utils::markdownToHtml(msg, rainbowify); + + mtx::events::msg::Notice notice; + notice.body = msg.trimmed().toStdString(); + + if (html != msg.trimmed().toHtmlEscaped() && + ChatPage::instance()->userSettings()->markdown()) { + notice.formatted_body = html.toStdString(); + notice.format = "org.matrix.custom.html"; + // Remove markdown links by completer + notice.body = + msg.trimmed().replace(conf::strings::matrixToMarkdownLink, "\\1").toStdString(); + } + + if (!room->reply().isEmpty()) { + notice.relations.relations.push_back( + {mtx::common::RelationType::InReplyTo, room->reply().toStdString()}); + } + if (!room->edit().isEmpty()) { + notice.relations.relations.push_back( + {mtx::common::RelationType::Replace, room->edit().toStdString()}); + } + + room->sendMessageEvent(notice, mtx::events::EventType::RoomMessage); +} + void InputBar::image(const QString &filename, const std::optional &file, @@ -531,6 +560,10 @@ InputBar::command(QString command, QString args) message(args, MarkdownOverride::ON, true); } else if (command == "rainbowme") { emote(args, true); + } else if (command == "notice") { + notice(args, false); + } else if (command == "rainbownotice") { + notice(args, true); } } diff --git a/src/timeline/InputBar.h b/src/timeline/InputBar.h index 613b5f9a..9db16bae 100644 --- a/src/timeline/InputBar.h +++ b/src/timeline/InputBar.h @@ -68,6 +68,7 @@ signals: private: void emote(QString body, bool rainbowify); + void notice(QString body, bool rainbowify); void command(QString name, QString args); void image(const QString &filename, const std::optional &file,