move detection code to nheko namespace and fix a few other bugs
This commit is contained in:
parent
eb13f7c169
commit
06e12a0a16
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -621,18 +621,14 @@ 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);
|
||||
std::optional<mtx::crypto::EncryptedFile> encryptionInfo = mtx::accessors::file(elem);
|
||||
|
||||
if (sentFromEncrypted) {
|
||||
std::optional<mtx::crypto::EncryptedFile> encryptionInfo =
|
||||
mtx::accessors::file(elem);
|
||||
|
||||
if (encryptionInfo) {
|
||||
http::client()->download(
|
||||
content,
|
||||
[this, roomId, e, encryptionInfo](const std::string &res,
|
||||
|
@ -643,8 +639,6 @@ TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEven
|
|||
return;
|
||||
}
|
||||
|
||||
assert(encryptionInfo);
|
||||
|
||||
auto data = mtx::crypto::to_string(
|
||||
mtx::crypto::decrypt_file(res, encryptionInfo.value()));
|
||||
|
||||
|
@ -668,16 +662,17 @@ TimelineViewManager::forwardMessageToRoom(mtx::events::collections::TimelineEven
|
|||
decltype(ev.content)> ==
|
||||
mtx::events::EventType::RoomMessage) {
|
||||
if constexpr (messageWithFileAndUrl(ev)) {
|
||||
ev.content.relations.relations.clear();
|
||||
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);
|
||||
});
|
||||
|
|
|
@ -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,14 +148,16 @@ 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<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);
|
||||
|
||||
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue