summary refs log tree commit diff
path: root/src/timeline/TimelineViewManager.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-01-29 00:42:46 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2020-01-29 00:42:46 +0100
commit75c5c011891739d5223ca53193797dc47e0e2a0c (patch)
tree575511ace543a19f50c3fb4c4fda7e28718a7b95 /src/timeline/TimelineViewManager.cpp
parentMerge pull request #111 from Nheko-Reborn/better-build (diff)
parentAdd command for invite,kick,ban and unban (diff)
downloadnheko-75c5c011891739d5223ca53193797dc47e0e2a0c.tar.xz
Merge branch 'plain-text-messages' into 0.7.0-dev
Diffstat (limited to 'src/timeline/TimelineViewManager.cpp')
-rw-r--r--src/timeline/TimelineViewManager.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp

index b3fd65a1..a1f23cf5 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp
@@ -18,8 +18,7 @@ Q_DECLARE_METATYPE(mtx::events::collections::TimelineEvents) void TimelineViewManager::updateColorPalette() { - UserSettings settings; - if (settings.theme() == "light") { + if (settings->theme() == "light") { QPalette lightActive(/*windowText*/ QColor("#333"), /*button*/ QColor("#333"), /*light*/ QColor(), @@ -31,7 +30,7 @@ TimelineViewManager::updateColorPalette() /*window*/ QColor("white")); view->rootContext()->setContextProperty("currentActivePalette", lightActive); view->rootContext()->setContextProperty("currentInactivePalette", lightActive); - } else if (settings.theme() == "dark") { + } else if (settings->theme() == "dark") { QPalette darkActive(/*windowText*/ QColor("#caccd1"), /*button*/ QColor("#caccd1"), /*light*/ QColor(), @@ -50,9 +49,10 @@ TimelineViewManager::updateColorPalette() } } -TimelineViewManager::TimelineViewManager(QWidget *parent) +TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettings, QWidget *parent) : imgProvider(new MxcImageProvider()) , colorImgProvider(new ColorImageProvider()) + , settings(userSettings) { qmlRegisterUncreatableMetaObject(qml_mtx_events::staticMetaObject, "im.nheko", @@ -186,8 +186,16 @@ TimelineViewManager::queueTextMessage(const QString &msg, const std::optional<Re { mtx::events::msg::Text text = {}; text.body = msg.trimmed().toStdString(); - text.format = "org.matrix.custom.html"; - text.formatted_body = utils::markdownToHtml(msg).toStdString(); + + if (settings->isMarkdownEnabled()) { + text.formatted_body = utils::markdownToHtml(msg).toStdString(); + + // Don't send formatted_body, when we don't need to + if (text.formatted_body == text.body) + text.formatted_body = ""; + else + text.format = "org.matrix.custom.html"; + } if (related) { QString body; @@ -202,8 +210,17 @@ TimelineViewManager::queueTextMessage(const QString &msg, const std::optional<Re } text.body = QString("%1\n%2").arg(body).arg(msg).toStdString(); - text.formatted_body = - utils::getFormattedQuoteBody(*related, utils::markdownToHtml(msg)).toStdString(); + + // NOTE(Nico): rich replies always need a formatted_body! + text.format = "org.matrix.custom.html"; + if (settings->isMarkdownEnabled()) + text.formatted_body = + utils::getFormattedQuoteBody(*related, utils::markdownToHtml(msg)) + .toStdString(); + else + text.formatted_body = + utils::getFormattedQuoteBody(*related, msg.toHtmlEscaped()).toStdString(); + text.relates_to.in_reply_to.event_id = related->related_event; } @@ -219,8 +236,10 @@ TimelineViewManager::queueEmoteMessage(const QString &msg) mtx::events::msg::Emote emote; emote.body = msg.trimmed().toStdString(); - if (html != msg.trimmed().toHtmlEscaped()) + if (html != msg.trimmed().toHtmlEscaped() && settings->isMarkdownEnabled()) { emote.formatted_body = html.toStdString(); + emote.format = "org.matrix.custom.html"; + } if (timeline_) timeline_->sendMessage(emote);