diff --git a/src/EventAccessors.cpp b/src/EventAccessors.cpp
index cfc41a98..362bf4e9 100644
--- a/src/EventAccessors.cpp
+++ b/src/EventAccessors.cpp
@@ -11,32 +11,8 @@
#include <type_traits>
namespace {
-struct nonesuch
-{
- ~nonesuch() = delete;
- nonesuch(nonesuch const &) = delete;
- void operator=(nonesuch const &) = delete;
-};
-
-namespace detail {
-template<class Default, class AlwaysVoid, template<class...> class Op, class... Args>
-struct detector
-{
- using value_t = std::false_type;
- using type = Default;
-};
-
-template<class Default, template<class...> class Op, class... Args>
-struct detector<Default, std::void_t<Op<Args...>>, Op, Args...>
-{
- using value_t = std::true_type;
- using type = Op<Args...>;
-};
-
-} // namespace detail
-
template<template<class...> class Op, class... Args>
-using is_detected = typename detail::detector<nonesuch, void, Op, Args...>::value_t;
+using is_detected = typename nheko::detail::detector<nheko::nonesuch, void, Op, Args...>::value_t;
struct IsStateEvent
{
diff --git a/src/EventAccessors.h b/src/EventAccessors.h
index ced159c1..a58c7de0 100644
--- a/src/EventAccessors.h
+++ b/src/EventAccessors.h
@@ -11,6 +11,32 @@
#include <mtx/events/collections.hpp>
+namespace nheko {
+struct nonesuch
+{
+ ~nonesuch() = delete;
+ nonesuch(nonesuch const &) = delete;
+ void operator=(nonesuch const &) = delete;
+};
+
+namespace detail {
+template<class Default, class AlwaysVoid, template<class...> class Op, class... Args>
+struct detector
+{
+ using value_t = std::false_type;
+ using type = Default;
+};
+
+template<class Default, template<class...> class Op, class... Args>
+struct detector<Default, std::void_t<Op<Args...>>, Op, Args...>
+{
+ using value_t = std::true_type;
+ using type = Op<Args...>;
+};
+
+} // namespace detail
+}
+
namespace mtx::accessors {
std::string
event_id(const mtx::events::collections::TimelineEvents &event);
diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index e3efe5ad..2e83b831 100644
--- a/src/timeline/TimelineModel.cpp
+++ b/src/timeline/TimelineModel.cpp
@@ -829,7 +829,7 @@ TimelineModel::forwardMessage(QString eventId, QString roomId)
if (!e)
return;
- emit forwardToRoom(e, roomId, cache::isRoomEncrypted(room_id_.toStdString()));
+ emit forwardToRoom(e, roomId);
}
void
diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 3e6f6f15..fbe963d2 100644
--- a/src/timeline/TimelineModel.h
+++ b/src/timeline/TimelineModel.h
@@ -323,9 +323,7 @@ signals:
void roomNameChanged();
void roomTopicChanged();
void roomAvatarUrlChanged();
- void forwardToRoom(mtx::events::collections::TimelineEvents *e,
- QString roomId,
- bool sentFromEncrypted);
+ void forwardToRoom(mtx::events::collections::TimelineEvents *e, QString roomId);
private:
template<typename T>
diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index f71fd42b..a3d19950 100644
--- a/src/timeline/TimelineViewManager.cpp
+++ b/src/timeline/TimelineViewManager.cpp
@@ -621,68 +621,63 @@ TimelineViewManager::focusTimeline()
void
TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEvents *e,
- QString roomId,
- bool sentFromEncrypted)
+ QString roomId)
{
- auto elem = *e;
- auto room = models.find(roomId);
- auto messageType = mtx::accessors::msg_type(elem);
- auto content = mtx::accessors::url(elem);
-
- if (sentFromEncrypted) {
- std::optional<mtx::crypto::EncryptedFile> encryptionInfo =
- mtx::accessors::file(elem);
+ auto elem = *e;
+ auto room = models.find(roomId);
+ auto content = mtx::accessors::url(elem);
+ std::optional<mtx::crypto::EncryptedFile> encryptionInfo = mtx::accessors::file(elem);
+ if (encryptionInfo) {
http::client()->download(
content,
[this, roomId, e, encryptionInfo](const std::string &res,
- const std::string &content_type,
- const std::string &originalFilename,
- mtx::http::RequestErr err) {
+ const std::string &content_type,
+ const std::string &originalFilename,
+ mtx::http::RequestErr err) {
if (err) {
return;
}
- assert(encryptionInfo);
-
- auto data = mtx::crypto::to_string(
- mtx::crypto::decrypt_file(res, encryptionInfo.value()));
-
- http::client()->upload(
- data,
- content_type,
- originalFilename,
- [this, roomId, e](const mtx::responses::ContentURI &res,
- mtx::http::RequestErr err) mutable {
- if (err) {
- nhlog::net()->warn("failed to upload media: {} {} ({})",
- err->matrix_error.error,
- to_string(err->matrix_error.errcode),
- static_cast<int>(err->status_code));
- return;
- }
-
- std::visit(
- [this, roomId, e, url = res.content_uri](auto ev) {
- if constexpr (mtx::events::message_content_to_type<
- decltype(ev.content)> ==
- mtx::events::EventType::RoomMessage) {
- if constexpr (messageWithFileAndUrl(ev)) {
- ev.content.relations.relations.clear();
- ev.content.file.reset();
- ev.content.url = url;
-
- auto room = models.find(roomId);
- room.value()->sendMessageEvent(
- ev.content,
- mtx::events::EventType::RoomMessage);
- }
- }
- },
- *e);
- });
+ auto data = mtx::crypto::to_string(
+ mtx::crypto::decrypt_file(res, encryptionInfo.value()));
+
+ http::client()->upload(
+ data,
+ content_type,
+ originalFilename,
+ [this, roomId, e](const mtx::responses::ContentURI &res,
+ mtx::http::RequestErr err) mutable {
+ if (err) {
+ nhlog::net()->warn("failed to upload media: {} {} ({})",
+ err->matrix_error.error,
+ to_string(err->matrix_error.errcode),
+ static_cast<int>(err->status_code));
+ return;
+ }
+
+ std::visit(
+ [this, roomId, e, url = res.content_uri](auto ev) {
+ if constexpr (mtx::events::message_content_to_type<
+ decltype(ev.content)> ==
+ mtx::events::EventType::RoomMessage) {
+ if constexpr (messageWithFileAndUrl(ev)) {
+ ev.content.relations.relations
+ .clear();
+ ev.content.file.reset();
+ ev.content.url = url;
+ }
+
+ auto room = models.find(roomId);
+ room.value()->sendMessageEvent(
+ ev.content,
+ mtx::events::EventType::RoomMessage);
+ }
+ },
+ *e);
+ });
- return;
+ return;
});
return;
diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h
index 9d1b4b1d..e5dea7ce 100644
--- a/src/timeline/TimelineViewManager.h
+++ b/src/timeline/TimelineViewManager.h
@@ -32,33 +32,6 @@ class UserSettings;
class ChatPage;
class DeviceVerificationFlow;
-struct nonesuch
-{
- ~nonesuch() = delete;
- nonesuch(nonesuch const &) = delete;
- void operator=(nonesuch const &) = delete;
-};
-
-namespace detail {
-template<class Default, class AlwaysVoid, template<class...> class Op, class... Args>
-struct detector
-{
- using value_t = std::false_type;
- using type = Default;
-};
-
-template<class Default, template<class...> class Op, class... Args>
-struct detector<Default, std::void_t<Op<Args...>>, Op, Args...>
-{
- using value_t = std::true_type;
- using type = Op<Args...>;
-};
-
-} // namespace detail
-
-template<template<class...> class Op, class... Args>
-using is_detected = typename detail::detector<nonesuch, void, Op, Args...>::value_t;
-
class TimelineViewManager : public QObject
{
Q_OBJECT
@@ -175,15 +148,17 @@ public slots:
void backToRooms() { emit showRoomList(); }
QObject *completerFor(QString completerName, QString roomId = "");
- void forwardMessageToRoom(mtx::events::collections::TimelineEvents *e,
- QString roomId,
- bool sentFromEncrypted);
+ void forwardMessageToRoom(mtx::events::collections::TimelineEvents *e, QString roomId);
private slots:
void openImageOverlayInternal(QString eventId, QImage img);
private:
- template<class Content>
+ template<template<class...> class Op, class... Args>
+ using is_detected =
+ typename nheko::detail::detector<nheko::nonesuch, void, Op, Args...>::value_t;
+
+ template<class Content>
using f_t = decltype(Content::file);
template<class Content>
@@ -192,11 +167,7 @@ private:
template<typename T>
static constexpr bool messageWithFileAndUrl(const mtx::events::Event<T> &e)
{
- if constexpr (is_detected<f_t, T>::value && is_detected<u_t, T>::value) {
- return true;
- }
-
- return false;
+ return is_detected<f_t, T>::value && is_detected<u_t, T>::value;
}
private:
|