diff --git a/src/encryption/Olm.h b/src/encryption/Olm.h
index f0e51070..726b9590 100644
--- a/src/encryption/Olm.h
+++ b/src/encryption/Olm.h
@@ -9,10 +9,13 @@
#include <mtx/events/encrypted.hpp>
#include <mtxclient/crypto/client.hpp>
+#include <QQmlEngine>
+
#include <CacheCryptoStructs.h>
namespace olm {
Q_NAMESPACE
+QML_NAMED_ELEMENT(Olm)
enum DecryptionErrorCode
{
diff --git a/src/encryption/SelfVerificationStatus.cpp b/src/encryption/SelfVerificationStatus.cpp
index 6fa737d4..d9d3d787 100644
--- a/src/encryption/SelfVerificationStatus.cpp
+++ b/src/encryption/SelfVerificationStatus.cpp
@@ -29,6 +29,11 @@ SelfVerificationStatus::SelfVerificationStatus(QObject *o)
Qt::UniqueConnection);
cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()});
});
+
+ connect(ChatPage::instance(),
+ &ChatPage::initializeEmptyViews,
+ this,
+ &SelfVerificationStatus::invalidate);
}
void
diff --git a/src/encryption/SelfVerificationStatus.h b/src/encryption/SelfVerificationStatus.h
index ea790c8b..c65fffd0 100644
--- a/src/encryption/SelfVerificationStatus.h
+++ b/src/encryption/SelfVerificationStatus.h
@@ -5,11 +5,15 @@
#pragma once
#include <QObject>
+#include <QQmlEngine>
class SelfVerificationStatus final : public QObject
{
Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+
Q_PROPERTY(Status status READ status NOTIFY statusChanged)
Q_PROPERTY(bool hasSSSS READ hasSSSS NOTIFY hasSSSSChanged)
diff --git a/src/encryption/VerificationManager.cpp b/src/encryption/VerificationManager.cpp
index 802a8177..d1248755 100644
--- a/src/encryption/VerificationManager.cpp
+++ b/src/encryption/VerificationManager.cpp
@@ -15,6 +15,7 @@ VerificationManager::VerificationManager(TimelineViewManager *o)
: QObject(o)
, rooms_(o->rooms())
{
+ instance_ = this;
}
static bool
diff --git a/src/encryption/VerificationManager.h b/src/encryption/VerificationManager.h
index 7b32bc98..cdc8af30 100644
--- a/src/encryption/VerificationManager.h
+++ b/src/encryption/VerificationManager.h
@@ -6,6 +6,7 @@
#include <QHash>
#include <QObject>
+#include <QQmlEngine>
#include <QSharedPointer>
#include <mtx/events.hpp>
@@ -21,8 +22,30 @@ class VerificationManager final : public QObject
{
Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+
public:
- VerificationManager(TimelineViewManager *o = nullptr);
+ VerificationManager(TimelineViewManager *o);
+
+ static VerificationManager *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_;
+ }
Q_INVOKABLE void removeVerificationFlow(DeviceVerificationFlow *flow);
void verifyUser(QString userid);
@@ -45,4 +68,6 @@ private:
QHash<QString, QSharedPointer<DeviceVerificationFlow>> dvList;
bool isInitialSync_ = false;
RoomlistModel *rooms_;
+
+ inline static VerificationManager *instance_ = nullptr;
};
|