Debian Codegraph @

src/encryption/VerificationManager.h

raw symbols SCIP
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 #pragma once
6
7 #include <QHash>
8 #include <QObject>
9 #include <QQmlEngine>
10 #include <QSharedPointer>
11
12 #include <mtx/events.hpp>
13 #include <mtx/events/encrypted.hpp>
14
15 class DeviceVerificationFlow;
16 class TimelineModel;
17 class TimelineViewManager;
18 class RoomlistModel;
19
20 class VerificationManager final : public QObject
21 {
22 Q_OBJECT
23
24 QML_ELEMENT
25 QML_SINGLETON
26
27 public:
28 VerificationManager(TimelineViewManager *o);
29
30 static VerificationManager *create(QQmlEngine *qmlEngine, QJSEngine *)
31 {
32 // The instance has to exist before it is used. We cannot replace it.
33 Q_ASSERT(instance_);
34
35 // The engine has to have the same thread affinity as the singleton.
36 Q_ASSERT(qmlEngine->thread() == instance_->thread());
37
38 // There can only be one engine accessing the singleton.
39 static QJSEngine *s_engine = nullptr;
40 if (s_engine)
41 Q_ASSERT(qmlEngine == s_engine);
42 else
43 s_engine = qmlEngine;
44
45 QJSEngine::setObjectOwnership(instance_, QJSEngine::CppOwnership);
46 return instance_;
47 }
48
49 Q_INVOKABLE void removeVerificationFlow(DeviceVerificationFlow *flow);
50 void verifyUser(QString userid);
51 void verifyDevice(QString userid, QString deviceid);
52 void verifyOneOfDevices(QString userid, std::vector<QString> deviceids);
53
54 signals:
55 void newDeviceVerificationRequest(DeviceVerificationFlow *flow);
56
57 public slots:
58 void receivedRoomDeviceVerificationRequest(
59 const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> &message,
60 TimelineModel *model);
61 void receivedDeviceVerificationRequest(const mtx::events::msg::KeyVerificationRequest &msg,
62 std::string sender);
63 void receivedDeviceVerificationStart(const mtx::events::msg::KeyVerificationStart &msg,
64 std::string sender);
65
66 private:
67 QHash<QString, QSharedPointer<DeviceVerificationFlow>> dvList;
68 bool isInitialSync_ = false;
69 RoomlistModel *rooms_;
70
71 inline static VerificationManager *instance_ = nullptr;
72 };