diff options
-rw-r--r-- | src/CommandCompleter.cpp | 6 | ||||
-rw-r--r-- | src/CommandCompleter.h | 1 | ||||
-rw-r--r-- | src/timeline/InputBar.cpp | 27 | ||||
-rw-r--r-- | src/timeline/InputBar.h | 1 |
4 files changed, 35 insertions, 0 deletions
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 <msgtype> [message]"); case Goto: return tr("/goto <message reference>"); 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")}; @@ -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 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<mtx::crypto::EncryptedFile> &file, |