Merge pull request #393 from LorenDB/mdCommands

Markdown setting override commands
This commit is contained in:
DeepBlueV7.X 2021-01-23 02:02:59 +01:00 committed by GitHub
commit a082a98ede
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -251,12 +251,14 @@ InputBar::openFileSelection()
} }
void void
InputBar::message(QString msg) InputBar::message(QString msg, MarkdownOverride useMarkdown)
{ {
mtx::events::msg::Text text = {}; mtx::events::msg::Text text = {};
text.body = msg.trimmed().toStdString(); text.body = msg.trimmed().toStdString();
if (ChatPage::instance()->userSettings()->markdown()) { if ((ChatPage::instance()->userSettings()->markdown() &&
useMarkdown == MarkdownOverride::NOT_SPECIFIED) ||
useMarkdown == MarkdownOverride::ON) {
text.formatted_body = utils::markdownToHtml(msg).toStdString(); text.formatted_body = utils::markdownToHtml(msg).toStdString();
// Don't send formatted_body, when we don't need to // Don't send formatted_body, when we don't need to
@ -477,6 +479,10 @@ InputBar::command(QString command, QString args)
room->clearTimeline(); room->clearTimeline();
} else if (command == "rotate-megolm-session") { } else if (command == "rotate-megolm-session") {
cache::dropOutboundMegolmSession(room->roomId().toStdString()); cache::dropOutboundMegolmSession(room->roomId().toStdString());
} else if (command == "md") {
message(args, MarkdownOverride::ON);
} else if (command == "plain") {
message(args, MarkdownOverride::OFF);
} }
} }

View file

@ -12,6 +12,13 @@ class QMimeData;
class QDropEvent; class QDropEvent;
class QStringList; class QStringList;
enum class MarkdownOverride
{
NOT_SPECIFIED, // no override set
ON,
OFF,
};
class InputBar : public QObject class InputBar : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -41,7 +48,7 @@ public slots:
void updateState(int selectionStart, int selectionEnd, int cursorPosition, QString text); void updateState(int selectionStart, int selectionEnd, int cursorPosition, QString text);
void openFileSelection(); void openFileSelection();
bool uploading() const { return uploading_; } bool uploading() const { return uploading_; }
void message(QString body); void message(QString body, MarkdownOverride useMarkdown = MarkdownOverride::NOT_SPECIFIED);
QObject *completerFor(QString completerName); QObject *completerFor(QString completerName);