summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2024-03-16 03:55:57 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2024-03-16 11:50:39 +0100
commitaef9617d1ec7f73a394ed4bb43b4436e27225176 (patch)
treecd34e86e42c22b8ab3f8c93b0098645fcce9acca /src/timeline
parentInclude moc files for a tiny speedup on incremental builds (diff)
downloadnheko-aef9617d1ec7f73a394ed4bb43b4436e27225176.tar.xz
Make a few headers forward declarations
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/EventDelegateChooser.h2
-rw-r--r--src/timeline/InputBar.cpp1
-rw-r--r--src/timeline/RoomlistModel.cpp28
-rw-r--r--src/timeline/RoomlistModel.h29
-rw-r--r--src/timeline/TimelineFilter.cpp1
-rw-r--r--src/timeline/TimelineFilter.h2
-rw-r--r--src/timeline/TimelineModel.cpp6
-rw-r--r--src/timeline/TimelineModel.h5
-rw-r--r--src/timeline/TimelineViewManager.cpp63
-rw-r--r--src/timeline/TimelineViewManager.h61
10 files changed, 134 insertions, 64 deletions
diff --git a/src/timeline/EventDelegateChooser.h b/src/timeline/EventDelegateChooser.h

index 139b143a..f5c683e1 100644 --- a/src/timeline/EventDelegateChooser.h +++ b/src/timeline/EventDelegateChooser.h
@@ -12,7 +12,7 @@ #include <QtCore/QObject> #include <QtCore/QVariant> -#include "TimelineModel.h" +class TimelineModel; class EventDelegateChooserAttachedType : public QObject { diff --git a/src/timeline/InputBar.cpp b/src/timeline/InputBar.cpp
index afb4585a..e0dfe9b9 100644 --- a/src/timeline/InputBar.cpp +++ b/src/timeline/InputBar.cpp
@@ -36,6 +36,7 @@ #include "TimelineViewManager.h" #include "UserSettingsPage.h" #include "Utils.h" +#include "ui/UserProfile.h" #include "blurhash.hpp" diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp
index 898e6e83..4cc50fee 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp
@@ -945,6 +945,34 @@ FilteredRoomlistModel::FilteredRoomlistModel(RoomlistModel *model, QObject *pare sort(0); } +FilteredRoomlistModel * +FilteredRoomlistModel::create(QQmlEngine *qmlEngine, QJSEngine *) +{ + // The instance has to exist before it is used. We cannot replace it. + Q_ASSERT(instance_); + + // The engine has to have the same thread affinity as the singleton. + Q_ASSERT(qmlEngine->thread() == instance_->thread()); + + // There can only be one engine accessing the singleton. + static QJSEngine *s_engine = nullptr; + if (s_engine) + Q_ASSERT(qmlEngine == s_engine); + else + s_engine = qmlEngine; + + QJSEngine::setObjectOwnership(instance_, QJSEngine::CppOwnership); + return instance_; +} + +TimelineModel * +FilteredRoomlistModel::getRoomById(const QString &id) const +{ + auto r = roomlistmodel->getRoomById(id).data(); + QQmlEngine::setObjectOwnership(r, QQmlEngine::CppOwnership); + return r; +} + void FilteredRoomlistModel::updateHiddenTagsAndSpaces() { diff --git a/src/timeline/RoomlistModel.h b/src/timeline/RoomlistModel.h
index 2294864f..c3f485ef 100644 --- a/src/timeline/RoomlistModel.h +++ b/src/timeline/RoomlistModel.h
@@ -15,12 +15,11 @@ #include <mtx/responses/sync.hpp> -#include "TimelineModel.h" - #ifdef NHEKO_DBUS_SYS #include "dbus/NhekoDBusBackend.h" #endif +class TimelineModel; class TimelineViewManager; class RoomPreview @@ -178,24 +177,7 @@ class FilteredRoomlistModel final : public QSortFilterProxyModel public: FilteredRoomlistModel(RoomlistModel *model, QObject *parent = nullptr); - static FilteredRoomlistModel *create(QQmlEngine *qmlEngine, QJSEngine *) - { - // The instance has to exist before it is used. We cannot replace it. - Q_ASSERT(instance_); - - // The engine has to have the same thread affinity as the singleton. - Q_ASSERT(qmlEngine->thread() == instance_->thread()); - - // There can only be one engine accessing the singleton. - static QJSEngine *s_engine = nullptr; - if (s_engine) - Q_ASSERT(qmlEngine == s_engine); - else - s_engine = qmlEngine; - - QJSEngine::setObjectOwnership(instance_, QJSEngine::CppOwnership); - return instance_; - } + static FilteredRoomlistModel *create(QQmlEngine *qmlEngine, QJSEngine *); static FilteredRoomlistModel *instance() { return instance_; } @@ -218,12 +200,7 @@ public slots: RoomPreview currentRoomPreview() const { return roomlistmodel->currentRoomPreview(); } void setCurrentRoom(QString roomid) { roomlistmodel->setCurrentRoom(std::move(roomid)); } void resetCurrentRoom() { roomlistmodel->resetCurrentRoom(); } - TimelineModel *getRoomById(const QString &id) const - { - auto r = roomlistmodel->getRoomById(id).data(); - QQmlEngine::setObjectOwnership(r, QQmlEngine::CppOwnership); - return r; - } + TimelineModel *getRoomById(const QString &id) const; RoomPreview getRoomPreviewById(QString roomid) const { return roomlistmodel->getRoomPreviewById(roomid); diff --git a/src/timeline/TimelineFilter.cpp b/src/timeline/TimelineFilter.cpp
index a92dfb13..0833900e 100644 --- a/src/timeline/TimelineFilter.cpp +++ b/src/timeline/TimelineFilter.cpp
@@ -8,6 +8,7 @@ #include <QEvent> #include "Logging.h" +#include "TimelineModel.h" /// Searching currently can be done incrementally. For that we define a specific role to filter on /// and then process that role in chunk. This is the `FilterRole`. Of course we need to then also diff --git a/src/timeline/TimelineFilter.h b/src/timeline/TimelineFilter.h
index 658a8c57..336339e2 100644 --- a/src/timeline/TimelineFilter.h +++ b/src/timeline/TimelineFilter.h
@@ -10,7 +10,7 @@ #include <mtx/events/power_levels.hpp> -#include "TimelineModel.h" +class TimelineModel; class TimelineFilter : public QSortFilterProxyModel { diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 92a37aa1..b41d1e0c 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -29,9 +29,12 @@ #include "Logging.h" #include "MainWindow.h" #include "MatrixClient.h" +#include "ReadReceiptsModel.h" +#include "RoomlistModel.h" #include "TimelineViewManager.h" #include "Utils.h" #include "encryption/Olm.h" +#include "ui/UserProfile.h" namespace std { inline uint // clazy:exclude=qhash-namespace @@ -1703,7 +1706,8 @@ TimelineModel::checkAfterFetch() template<typename T> void -TimelineModel::sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::EventType eventType) +TimelineModel::sendEncryptedMessage(const mtx::events::RoomEvent<T> &msg, + mtx::events::EventType eventType) { const auto room_id = room_id_.toStdString(); diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index c7f3ebb6..3a189e39 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h
@@ -20,7 +20,6 @@ #include "InputBar.h" #include "Permissions.h" #include "Reaction.h" -#include "ReadReceiptsModel.h" #include "ui/RoomSummary.h" namespace mtx::http { @@ -33,6 +32,7 @@ struct ClaimKeys; struct StateEvents; } struct RelatedInfo; +class ReadReceiptsProxy; namespace qml_mtx_events { Q_NAMESPACE @@ -516,7 +516,8 @@ signals: private: template<typename T> - void sendEncryptedMessage(mtx::events::RoomEvent<T> msg, mtx::events::EventType eventType); + void + sendEncryptedMessage(const mtx::events::RoomEvent<T> &msg, mtx::events::EventType eventType); void readEvent(const std::string &id); void setPaginationInProgress(const bool paginationInProgress); diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index 9ea8dc77..479fe7e1 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp
@@ -8,6 +8,8 @@ #include <QClipboard> #include <QFileDialog> #include <QMimeData> +#include <QQuickItem> +#include <QQuickTextDocument> #include <QStandardPaths> #include <QString> @@ -24,17 +26,48 @@ #include "Logging.h" #include "MainWindow.h" #include "MatrixClient.h" +#include "MemberList.h" #include "RoomsModel.h" +#include "TimelineModel.h" #include "UserSettingsPage.h" #include "UsersModel.h" #include "Utils.h" #include "encryption/VerificationManager.h" +#include "timeline/CommunitiesModel.h" +#include "timeline/PresenceEmitter.h" +#include "timeline/RoomlistModel.h" +#include "ui/RoomSettings.h" +#include "ui/UserProfile.h" #include "voip/CallManager.h" #include "voip/WebRTCSession.h" 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 nheko::detail::detector<nheko::nonesuch, void, Op, Args...>::value_t; +using is_detected = typename detail::detector<nonesuch, void, Op, Args...>::value_t; template<class Content> using file_t = decltype(Content::file); @@ -88,7 +121,7 @@ TimelineViewManager::updateColorPalette() QColor TimelineViewManager::userColor(QString id, QColor background) { - QPair<QString, quint64> idx{id, background.rgba64()}; + std::pair<QString, quint64> idx{id, background.rgba64()}; if (!userColors.contains(idx)) userColors.insert(idx, QColor(utils::generateContrastingHexColor(id, background))); return userColors.value(idx); @@ -148,6 +181,32 @@ TimelineViewManager::TimelineViewManager(CallManager *, ChatPage *parent) }); } +TimelineViewManager * +TimelineViewManager::create(QQmlEngine *qmlEngine, QJSEngine *) +{ + // The instance has to exist before it is used. We cannot replace it. + Q_ASSERT(instance_); + + // The engine has to have the same thread affinity as the singleton. + Q_ASSERT(qmlEngine->thread() == instance_->thread()); + + // There can only be one engine accessing the singleton. + static QJSEngine *s_engine = nullptr; + if (s_engine) + Q_ASSERT(qmlEngine == s_engine); + else + s_engine = qmlEngine; + + QJSEngine::setObjectOwnership(instance_, QJSEngine::CppOwnership); + return instance_; +} + +void +TimelineViewManager::clearAll() +{ + rooms_->clear(); +} + void TimelineViewManager::openRoomMembers(TimelineModel *room) { diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h
index b4e176cd..b116402b 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h
@@ -5,19 +5,12 @@ #pragma once #include <QHash> -#include <QQuickItem> -#include <QQuickTextDocument> +#include <QQmlEngine> -#include <mtx/common.hpp> -#include <mtx/responses/messages.hpp> +#include <unordered_map> -#include "InviteesModel.h" -#include "MemberList.h" -#include "timeline/CommunitiesModel.h" -#include "timeline/PresenceEmitter.h" -#include "timeline/RoomlistModel.h" -#include "ui/RoomSettings.h" -#include "ui/UserProfile.h" +class QQuickItem; +class QQuickTextDocument; class UserSettings; class ChatPage; @@ -25,9 +18,32 @@ class ImagePackListModel; class TimelineModel; class CallManager; class VerificationManager; +class InviteesModel; +class MemberList; +class CommunitiesModel; +class RoomlistModel; +class PresenceEmitter; +class UserProfile; +class RoomSettings; +class FilteredRoomlistModel; +class QAbstractItemModel; namespace mtx::responses { struct Sync; +struct AccountData; +} + +namespace mtx::events::voip { +struct CallInvite; +struct CallCandidates; +struct CallAnswer; +struct CallHangUp; +struct CallSelectAnswer; +struct CallReject; +struct CallNegotiate; +} +namespace mtx::events::collections { +struct TimelineEvents; } class TimelineViewManager final : public QObject @@ -45,24 +61,7 @@ class TimelineViewManager final : public QObject public: TimelineViewManager(CallManager *callManager, ChatPage *parent = nullptr); - static TimelineViewManager *create(QQmlEngine *qmlEngine, QJSEngine *) - { - // The instance has to exist before it is used. We cannot replace it. - Q_ASSERT(instance_); - - // The engine has to have the same thread affinity as the singleton. - Q_ASSERT(qmlEngine->thread() == instance_->thread()); - - // There can only be one engine accessing the singleton. - static QJSEngine *s_engine = nullptr; - if (s_engine) - Q_ASSERT(qmlEngine == s_engine); - else - s_engine = qmlEngine; - - QJSEngine::setObjectOwnership(instance_, QJSEngine::CppOwnership); - return instance_; - } + static TimelineViewManager *create(QQmlEngine *qmlEngine, QJSEngine *); static TimelineViewManager *instance() { return TimelineViewManager::instance_; } @@ -72,7 +71,7 @@ public: VerificationManager *verificationManager() { return verificationManager_; } - void clearAll() { rooms_->clear(); } + void clearAll(); Q_INVOKABLE bool isInitialSync() const { return isInitialSync_; } bool isConnected() const { return isConnected_; } @@ -158,7 +157,7 @@ private: VerificationManager *verificationManager_ = nullptr; PresenceEmitter *presenceEmitter = nullptr; - QHash<QPair<QString, quint64>, QColor> userColors; + QHash<std::pair<QString, quint64>, QColor> userColors; inline static TimelineViewManager *instance_ = nullptr;