mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 12:38:48 +03:00
Allow sending custom msgtypes
This commit is contained in:
parent
296385e6fe
commit
44d4e6f9b5
4 changed files with 35 additions and 0 deletions
|
@ -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:
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
RainbowConfetti,
|
||||
Rainfall,
|
||||
RainbowRain,
|
||||
Msgtype,
|
||||
Goto,
|
||||
ConvertToDm,
|
||||
ConvertToRoom,
|
||||
|
|
|
@ -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<mtx::crypto::EncryptedFile> &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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue