diff --git a/src/Utils.cpp b/src/Utils.cpp
index ca2d3adc..11e7b1af 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -63,19 +63,13 @@ utils::stripReplyFallbacks(const TimelineEvent &event, std::string id, QString r
// get body, strip reply fallback, then transform the event to text, if it is a media event
// etc
related.quoted_body = QString::fromStdString(mtx::accessors::body(event));
- QRegularExpression plainQuote("^>.*?$\n?", QRegularExpression::MultilineOption);
- while (related.quoted_body.startsWith(">"))
- related.quoted_body.remove(plainQuote);
- if (related.quoted_body.startsWith("\n"))
- related.quoted_body.remove(0, 1);
+ stripReplyFromBody(related.quoted_body);
related.quoted_body = utils::getQuoteBody(related);
related.quoted_body.replace("@room", QString::fromUtf8("@\u2060room"));
// get quoted body and strip reply fallback
related.quoted_formatted_body = mtx::accessors::formattedBodyWithFallback(event);
- related.quoted_formatted_body.remove(QRegularExpression(
- ".*", QRegularExpression::DotMatchesEverythingOption));
- related.quoted_formatted_body.replace("@room", "@\u2060aroom");
+ stripReplyFromFormattedBody(related.quoted_formatted_body);
related.room = room_id_;
return related;
diff --git a/src/Utils.h b/src/Utils.h
index 7a9eb777..e62b2d34 100644
--- a/src/Utils.h
+++ b/src/Utils.h
@@ -9,6 +9,7 @@
#include
#include
#include
+#include
#include
#include
@@ -40,6 +41,26 @@ namespace utils {
using TimelineEvent = mtx::events::collections::TimelineEvents;
+//! Helper function to remove reply fallback from body
+static void
+stripReplyFromBody(QString &body)
+{
+ QRegularExpression plainQuote("^>.*?$\n?", QRegularExpression::MultilineOption);
+ while (body.startsWith(">"))
+ body.remove(plainQuote);
+ if (body.startsWith("\n"))
+ body.remove(0, 1);
+}
+
+//! Helper function to remove reply fallback from formatted body
+static void
+stripReplyFromFormattedBody(QString &formatted_body)
+{
+ formatted_body.remove(QRegularExpression(".*",
+ QRegularExpression::DotMatchesEverythingOption));
+ formatted_body.replace("@room", "@\u2060aroom");
+}
+
RelatedInfo
stripReplyFallbacks(const TimelineEvent &event, std::string id, QString room_id_);
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index a3d19950..ff759625 100644
--- a/src/timeline/TimelineViewManager.cpp
+++ b/src/timeline/TimelineViewManager.cpp
@@ -4,7 +4,6 @@
#include "TimelineViewManager.h"
-#include
#include
#include
#include
@@ -26,7 +25,6 @@
#include "RoomsModel.h"
#include "UserSettingsPage.h"
#include "UsersModel.h"
-#include "blurhash.hpp"
#include "dialogs/ImageOverlay.h"
#include "emoji/EmojiModel.h"
#include "emoji/Provider.h"
@@ -623,10 +621,9 @@ void
TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEvents *e,
QString roomId)
{
- auto elem = *e;
auto room = models.find(roomId);
- auto content = mtx::accessors::url(elem);
- std::optional encryptionInfo = mtx::accessors::file(elem);
+ auto content = mtx::accessors::url(*e);
+ std::optional encryptionInfo = mtx::accessors::file(*e);
if (encryptionInfo) {
http::client()->download(
@@ -669,6 +666,8 @@ TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEven
}
auto room = models.find(roomId);
+ removeReplyFallback(ev);
+ ev.content.relations.relations.clear();
room.value()->sendMessageEvent(
ev.content,
mtx::events::EventType::RoomMessage);
@@ -688,9 +687,10 @@ TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEven
if constexpr (mtx::events::message_content_to_type ==
mtx::events::EventType::RoomMessage) {
e.content.relations.relations.clear();
+ removeReplyFallback(e);
room.value()->sendMessageEvent(e.content,
mtx::events::EventType::RoomMessage);
}
},
- elem);
+ *e);
}
\ No newline at end of file
diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h
index e5dea7ce..7e9632de 100644
--- a/src/timeline/TimelineViewManager.h
+++ b/src/timeline/TimelineViewManager.h
@@ -13,7 +13,6 @@
#include
#include
#include
-#include
#include "Cache.h"
#include "CallManager.h"
@@ -159,15 +158,51 @@ private:
typename nheko::detail::detector::value_t;
template
- using f_t = decltype(Content::file);
+ using file_t = decltype(Content::file);
template
- using u_t = decltype(Content::url);
+ using url_t = decltype(Content::url);
+
+ template
+ using body_t = decltype(Content::body);
+
+ template
+ using formatted_body_t = decltype(Content::formatted_body);
template
- static constexpr bool messageWithFileAndUrl(const mtx::events::Event &e)
+ static constexpr bool messageWithFileAndUrl(const mtx::events::Event &)
{
- return is_detected::value && is_detected::value;
+ return is_detected::value && is_detected::value;
+ }
+
+ template
+ static constexpr void removeReplyFallback(mtx::events::Event &e)
+ {
+ if constexpr (is_detected::value) {
+ if constexpr (std::is_same_v,
+ std::remove_cv_t>) {
+ if (e.content.body) {
+ QString body = QString::fromStdString(e.content.body);
+ utils::stripReplyFromBody(body);
+ e.content.body = body.toStdString();
+ }
+ } else if constexpr (std::is_same_v<
+ std::string,
+ std::remove_cv_t>) {
+ QString body = QString::fromStdString(e.content.body);
+ utils::stripReplyFromBody(body);
+ e.content.body = body.toStdString();
+ }
+ }
+
+ if constexpr (is_detected::value) {
+ if (e.content.format == "org.matrix.custom.html") {
+ QString formattedBody =
+ QString::fromStdString(e.content.formatted_body);
+ utils::stripReplyFromFormattedBody(formattedBody);
+ e.content.formatted_body = formattedBody.toStdString();
+ }
+ }
}
private: