mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-29 06:08: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 ");
|
return QStringLiteral("/rainfall ");
|
||||||
case RainbowRain:
|
case RainbowRain:
|
||||||
return QStringLiteral("/rainbowrain ");
|
return QStringLiteral("/rainbowrain ");
|
||||||
|
case Msgtype:
|
||||||
|
return QStringLiteral("/msgtype ");
|
||||||
case Goto:
|
case Goto:
|
||||||
return QStringLiteral("/goto ");
|
return QStringLiteral("/goto ");
|
||||||
case ConvertToDm:
|
case ConvertToDm:
|
||||||
|
@ -164,6 +166,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const
|
||||||
return tr("/rainfall [message]");
|
return tr("/rainfall [message]");
|
||||||
case RainbowRain:
|
case RainbowRain:
|
||||||
return tr("/rainbowrain [message]");
|
return tr("/rainbowrain [message]");
|
||||||
|
case Msgtype:
|
||||||
|
return tr("/msgtype <msgtype> [message]");
|
||||||
case Goto:
|
case Goto:
|
||||||
return tr("/goto <message reference>");
|
return tr("/goto <message reference>");
|
||||||
case ConvertToDm:
|
case ConvertToDm:
|
||||||
|
@ -237,6 +241,8 @@ CommandCompleter::data(const QModelIndex &index, int role) const
|
||||||
return tr("Send a message with rain.");
|
return tr("Send a message with rain.");
|
||||||
case RainbowRain:
|
case RainbowRain:
|
||||||
return tr("Send a message in rainbow colors with rain.");
|
return tr("Send a message in rainbow colors with rain.");
|
||||||
|
case Msgtype:
|
||||||
|
return tr("Send a message with a custom message type.");
|
||||||
case Goto:
|
case Goto:
|
||||||
return tr("Go to a specific message using an event id, index or matrix: link");
|
return tr("Go to a specific message using an event id, index or matrix: link");
|
||||||
case ConvertToDm:
|
case ConvertToDm:
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
RainbowConfetti,
|
RainbowConfetti,
|
||||||
Rainfall,
|
Rainfall,
|
||||||
RainbowRain,
|
RainbowRain,
|
||||||
|
Msgtype,
|
||||||
Goto,
|
Goto,
|
||||||
ConvertToDm,
|
ConvertToDm,
|
||||||
ConvertToRoom,
|
ConvertToRoom,
|
||||||
|
|
|
@ -283,6 +283,7 @@ InputBar::updateTextContentProperties(const QString &t)
|
||||||
QStringLiteral("rainbowconfetti"),
|
QStringLiteral("rainbowconfetti"),
|
||||||
QStringLiteral("rain"),
|
QStringLiteral("rain"),
|
||||||
QStringLiteral("rainbowrain"),
|
QStringLiteral("rainbowrain"),
|
||||||
|
QStringLiteral("msgtype"),
|
||||||
QStringLiteral("goto"),
|
QStringLiteral("goto"),
|
||||||
QStringLiteral("converttodm"),
|
QStringLiteral("converttodm"),
|
||||||
QStringLiteral("converttoroom")};
|
QStringLiteral("converttoroom")};
|
||||||
|
@ -649,6 +650,30 @@ InputBar::rainfall(const QString &body, bool rainbowify)
|
||||||
room->sendMessageEvent(rain, mtx::events::EventType::RoomMessage);
|
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
|
void
|
||||||
InputBar::image(const QString &filename,
|
InputBar::image(const QString &filename,
|
||||||
const std::optional<mtx::crypto::EncryptedFile> &file,
|
const std::optional<mtx::crypto::EncryptedFile> &file,
|
||||||
|
@ -920,6 +945,8 @@ InputBar::command(const QString &command, QString args)
|
||||||
rainfall(args, false);
|
rainfall(args, false);
|
||||||
} else if (command == QLatin1String("rainbowrain")) {
|
} else if (command == QLatin1String("rainbowrain")) {
|
||||||
rainfall(args, true);
|
rainfall(args, true);
|
||||||
|
} else if (command == QLatin1String("msgtype")) {
|
||||||
|
customMsgtype(args.section(' ', 0, 0), args.section(' ', 1, -1), false);
|
||||||
} else if (command == QLatin1String("goto")) {
|
} else if (command == QLatin1String("goto")) {
|
||||||
// Goto has three different modes:
|
// Goto has three different modes:
|
||||||
// 1 - Going directly to a given event ID
|
// 1 - Going directly to a given event ID
|
||||||
|
|
|
@ -243,6 +243,7 @@ private:
|
||||||
void notice(const QString &body, bool rainbowify);
|
void notice(const QString &body, bool rainbowify);
|
||||||
void confetti(const QString &body, bool rainbowify);
|
void confetti(const QString &body, bool rainbowify);
|
||||||
void rainfall(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);
|
bool command(const QString &name, QString args);
|
||||||
void image(const QString &filename,
|
void image(const QString &filename,
|
||||||
const std::optional<mtx::crypto::EncryptedFile> &file,
|
const std::optional<mtx::crypto::EncryptedFile> &file,
|
||||||
|
|
Loading…
Reference in a new issue