summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authortargetakhil <targetakhil@gmail.com>2021-04-18 11:22:44 +0530
committertargetakhil <targetakhil@gmail.com>2021-04-18 11:22:44 +0530
commit2dfa40e017c9880164936b50a0ab698dd83a125b (patch)
tree1532ef861f3fb0c3ddcee3a5fbcbdab6b11fd420 /src/timeline
parentmove detection code to nheko namespace and fix a few other bugs (diff)
downloadnheko-2dfa40e017c9880164936b50a0ab698dd83a125b.tar.xz
strip reply fallbacks from forwarded message
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/TimelineViewManager.cpp12
-rw-r--r--src/timeline/TimelineViewManager.h45
2 files changed, 46 insertions, 11 deletions
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 <QBuffer> #include <QDesktopServices> #include <QDropEvent> #include <QMetaType> @@ -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<mtx::crypto::EncryptedFile> encryptionInfo = mtx::accessors::file(elem); + auto content = mtx::accessors::url(*e); + std::optional<mtx::crypto::EncryptedFile> 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<decltype(e.content)> == 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 <mtx/common.hpp> #include <mtx/responses/messages.hpp> #include <mtx/responses/sync.hpp> -#include <type_traits> #include "Cache.h" #include "CallManager.h" @@ -159,15 +158,51 @@ private: typename nheko::detail::detector<nheko::nonesuch, void, Op, Args...>::value_t; template<class Content> - using f_t = decltype(Content::file); + using file_t = decltype(Content::file); template<class Content> - using u_t = decltype(Content::url); + using url_t = decltype(Content::url); + + template<class Content> + using body_t = decltype(Content::body); + + template<class Content> + using formatted_body_t = decltype(Content::formatted_body); template<typename T> - static constexpr bool messageWithFileAndUrl(const mtx::events::Event<T> &e) + static constexpr bool messageWithFileAndUrl(const mtx::events::Event<T> &) { - return is_detected<f_t, T>::value && is_detected<u_t, T>::value; + return is_detected<file_t, T>::value && is_detected<url_t, T>::value; + } + + template<typename T> + static constexpr void removeReplyFallback(mtx::events::Event<T> &e) + { + if constexpr (is_detected<body_t, T>::value) { + if constexpr (std::is_same_v<std::optional<std::string>, + std::remove_cv_t<decltype(e.content.body)>>) { + 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<decltype(e.content.body)>>) { + QString body = QString::fromStdString(e.content.body); + utils::stripReplyFromBody(body); + e.content.body = body.toStdString(); + } + } + + if constexpr (is_detected<formatted_body_t, T>::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: