summary refs log tree commit diff
path: root/src/timeline/TimelineViewManager.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/timeline/TimelineViewManager.h')
-rw-r--r--src/timeline/TimelineViewManager.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h
index 303e2af2..a4bc6c41 100644
--- a/src/timeline/TimelineViewManager.h
+++ b/src/timeline/TimelineViewManager.h
@@ -34,6 +34,9 @@ class TimelineViewManager final : public QObject
 {
     Q_OBJECT
 
+    QML_NAMED_ELEMENT(TimelineManager)
+    QML_SINGLETON
+
     Q_PROPERTY(
       bool isInitialSync MEMBER isInitialSync_ READ isInitialSync NOTIFY initialSyncChanged)
     Q_PROPERTY(bool isConnected READ isConnected NOTIFY isConnectedChanged)
@@ -41,6 +44,25 @@ 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_;
+    }
+
     void sync(const mtx::responses::Sync &sync_);
 
     VerificationManager *verificationManager() { return verificationManager_; }
@@ -123,6 +145,7 @@ private:
     bool isConnected_   = true;
 
     RoomlistModel *rooms_          = nullptr;
+    FilteredRoomlistModel *frooms_ = nullptr;
     CommunitiesModel *communities_ = nullptr;
 
     // don't move this above the rooms_
@@ -130,4 +153,6 @@ private:
     PresenceEmitter *presenceEmitter          = nullptr;
 
     QHash<QPair<QString, quint64>, QColor> userColors;
+
+    inline static TimelineViewManager *instance_ = nullptr;
 };