From 2b253ead9e9cf0dc3ab49b2ef2be43c199fd312a Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 27 Apr 2021 11:33:46 +0200 Subject: Make forward messages a bit more readable --- src/timeline/TimelineViewManager.cpp | 51 +++++++++++++++++++++++++++++++++++- src/timeline/TimelineViewManager.h | 48 --------------------------------- 2 files changed, 50 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index 518ccaf1..9d12825f 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -18,6 +18,7 @@ #include "CompletionProxyModel.h" #include "DelegateChooser.h" #include "DeviceVerificationFlow.h" +#include "EventAccessors.h" #include "Logging.h" #include "MainWindow.h" #include "MatrixClient.h" @@ -36,6 +37,54 @@ Q_DECLARE_METATYPE(std::vector) namespace msgs = mtx::events::msg; +namespace { +template class Op, class... Args> +using is_detected = typename nheko::detail::detector::value_t; + +template +using file_t = decltype(Content::file); + +template +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 &) +{ + 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) { + e.content.body = utils::stripReplyFromBody(e.content.body); + } + } else if constexpr (std::is_same_v>) { + e.content.body = utils::stripReplyFromBody(e.content.body); + } + } + + if constexpr (is_detected::value) { + if (e.content.format == "org.matrix.custom.html") { + e.content.formatted_body = + utils::stripReplyFromFormattedBody(e.content.formatted_body); + } + } +} +} + void TimelineViewManager::updateEncryptedDescriptions() { @@ -694,4 +743,4 @@ TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEven } }, *e); -} \ No newline at end of file +} diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index 809b286e..9703ee56 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -16,7 +16,6 @@ #include "Cache.h" #include "CallManager.h" -#include "EventAccessors.h" #include "Logging.h" #include "TimelineModel.h" #include "Utils.h" @@ -152,53 +151,6 @@ public slots: private slots: void openImageOverlayInternal(QString eventId, QImage img); -private: - template class Op, class... Args> - using is_detected = - typename nheko::detail::detector::value_t; - - template - using file_t = decltype(Content::file); - - template - 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 &) - { - 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) { - e.content.body = utils::stripReplyFromBody(e.content.body); - } - } else if constexpr (std::is_same_v< - std::string, - std::remove_cv_t>) { - e.content.body = utils::stripReplyFromBody(e.content.body); - } - } - - if constexpr (is_detected::value) { - if (e.content.format == "org.matrix.custom.html") { - e.content.formatted_body = - utils::stripReplyFromFormattedBody(e.content.formatted_body); - } - } - } - private: #ifdef USE_QUICK_VIEW QQuickView *view; -- cgit 1.5.1