diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index f66099a0..f34cb405 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -1,6 +1,7 @@
#include "TimelineModel.h"
#include <algorithm>
+#include <thread>
#include <type_traits>
#include <QFileDialog>
@@ -280,9 +281,26 @@ TimelineModel::data(const QString &id, int role) const
case FormattedBody: {
const static QRegularExpression replyFallback(
"<mx-reply>.*</mx-reply>", QRegularExpression::DotMatchesEverythingOption);
- return QVariant(
- utils::replaceEmoji(utils::linkifyMessage(utils::escapeBlacklistedHtml(
- formattedBodyWithFallback(event).remove(replyFallback)))));
+
+ bool isReply = !in_reply_to_event(event).empty();
+
+ auto formattedBody_ = QString::fromStdString(formatted_body(event));
+ if (formattedBody_.isEmpty()) {
+ auto body_ = QString::fromStdString(body(event));
+
+ if (isReply) {
+ while (body_.startsWith("> "))
+ body_ = body_.right(body_.size() - body_.indexOf('\n') - 1);
+ if (body_.startsWith('\n'))
+ body_ = body_.right(body_.size() - 1);
+ }
+ formattedBody_ = body_.toHtmlEscaped().replace('\n', "<br>");
+ } else {
+ if (isReply)
+ formattedBody_ = formattedBody_.remove(replyFallback);
+ }
+ return QVariant(utils::replaceEmoji(
+ utils::linkifyMessage(utils::escapeBlacklistedHtml(formattedBody_))));
}
case Url:
return QVariant(QString::fromStdString(url(event)));
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index 676f5ca5..33441a62 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(),
@@ -33,7 +32,7 @@ TimelineViewManager::updateColorPalette()
lightActive.setColor(QPalette::ToolTipText, lightActive.text().color());
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(),
@@ -54,9 +53,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",
@@ -190,8 +190,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;
@@ -206,8 +214,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;
}
@@ -223,8 +240,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);
diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h
index 3db55366..5880a382 100644
--- a/src/timeline/TimelineViewManager.h
+++ b/src/timeline/TimelineViewManager.h
@@ -15,6 +15,7 @@
class MxcImageProvider;
class ColorImageProvider;
+class UserSettings;
class TimelineViewManager : public QObject
{
@@ -28,7 +29,7 @@ class TimelineViewManager : public QObject
replyingEventChanged)
public:
- TimelineViewManager(QWidget *parent = 0);
+ TimelineViewManager(QSharedPointer<UserSettings> userSettings, QWidget *parent = 0);
QWidget *getWidget() const { return container; }
void sync(const mtx::responses::Rooms &rooms);
@@ -109,4 +110,6 @@ private:
TimelineModel *timeline_ = nullptr;
bool isInitialSync_ = true;
QString replyingEvent_;
+
+ QSharedPointer<UserSettings> settings;
};
|