Debian Codegraph @

src/ChatPage.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 <atomic>
8 #include <optional>
9
10 #include <mtx/events.hpp>
11 #include <mtx/events/presence.hpp>
12 #include <mtx/secret_storage.hpp>
13
14 #include <QDateTime>
15 #include <QSharedPointer>
16 #include <QTimer>
17
18 #include "ui/RoomSummary.h"
19
20 class TimelineViewManager;
21 class UserSettings;
22 class NotificationsManager;
23 class TimelineModel;
24 class CallManager;
25
26 namespace mtx::requests {
27 struct CreateRoom;
28 }
29 namespace mtx::responses {
30 struct Notifications;
31 struct Sync;
32 struct Timeline;
33 struct Rooms;
34 }
35
36 using SecretsToDecrypt = std::map<std::string, mtx::secret_storage::AesHmacSha2EncryptedData>;
37
38 class ChatPage final : public QObject
39 {
40 Q_OBJECT
41
42 public:
43 ChatPage(QSharedPointer<UserSettings> userSettings, QObject *parent = nullptr);
44
45 // Initialize all the components of the UI.
46 void bootstrap(QString userid, QString homeserver, QString token);
47
48 static ChatPage *instance() { return instance_; }
49
50 QSharedPointer<UserSettings> userSettings() { return userSettings_; }
51 CallManager *callManager() { return callManager_; }
52 TimelineViewManager *timelineManager() { return view_manager_; }
53 void deleteConfigs();
54
55 void initiateLogout();
56
57 QString status() const;
58 void setStatus(const QString &status);
59
60 mtx::presence::PresenceState currentPresence() const;
61
62 void startChat(QString userid, std::optional<bool> encryptionEnabled);
63
64 //! Check if the given room is currently open.
65 bool isRoomActive(const QString &room_id);
66
67 const std::unique_ptr<mtx::pushrules::PushRuleEvaluator> &pushruleEvaluator() const
68 {
69 return pushrules;
70 }
71
72 void removeAllNotifications();
73
74 public slots:
75 bool handleMatrixUri(QString uri);
76 bool handleMatrixUri(const QUrl &uri);
77
78 void startChat(QString userid) { startChat(userid, std::nullopt); }
79 void leaveRoom(const QString &room_id, const QString &reason);
80 void createRoom(const mtx::requests::CreateRoom &req);
81 void joinRoom(const QString &room, const QString &reason = "");
82 void knockRoom(const QString &room, QString reason = "") { knockRoom(room, {}, reason, false); }
83 void knockRoom(const QString &room,
84 const std::vector<std::string> &via,
85 QString reason = "",
86 bool failedJoin = false,
87 bool promptForConfirmation = true);
88 void joinRoomVia(const std::string &room_id,
89 const std::vector<std::string> &via,
90 bool promptForConfirmation = true,
91 const QString &reason = "");
92
93 void inviteUser(const QString &room, QString userid, QString reason);
94 void kickUser(const QString &room, QString userid, QString reason);
95 void banUser(const QString &room, QString userid, QString reason);
96 void unbanUser(const QString &room, QString userid, QString reason);
97
98 void receivedSessionKey(const std::string &room_id, const std::string &session_id);
99 void decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescription keyDesc,
100 const SecretsToDecrypt &secrets);
101 void sendNotificationReply(const QString &roomid, const QString &eventid, const QString &body);
102 signals:
103 void connectionLost();
104 void connectionRestored();
105
106 void contentLoaded();
107 void closing();
108 void changeWindowTitle(const int);
109 void unreadMessages(int count);
110 void showNotification(const QString &msg);
111 void showLoginPage(const QString &msg);
112 void showUserSettingsPage();
113
114 void ownProfileOk();
115 void setUserDisplayName(const QString &name);
116 void setUserAvatar(const QString &avatar);
117 void loggedOut();
118
119 void trySyncCb();
120 void tryDelayedSyncCb();
121 void tryInitialSyncCb();
122 void newSyncResponse(const mtx::responses::Sync &res, const std::string &prev_batch_token);
123 void leftRoom(const QString &room_id);
124 void newRoom(const QString &room_id);
125 void changeToRoom(const QString &room_id);
126 void startRemoveFallbackKeyTimer();
127
128 void initializeViews(const mtx::responses::Sync &rooms);
129 void initializeEmptyViews();
130 void syncUI(const mtx::responses::Sync &sync);
131 void dropToLoginPageCb(const QString &msg);
132
133 void notifyMessage(const QString &roomid,
134 const QString &eventid,
135 const QString &roomname,
136 const QString &sender,
137 const QString &message,
138 const QImage &icon);
139
140 void retrievedPresence(const QString &statusMsg, mtx::presence::PresenceState state);
141 void themeChanged();
142 void decryptSidebarChanged();
143
144 //! Signals for device verificaiton
145 void receivedDeviceVerificationAccept(const mtx::events::msg::KeyVerificationAccept &message);
146 void receivedDeviceVerificationRequest(const mtx::events::msg::KeyVerificationRequest &message,
147 std::string sender);
148 void receivedRoomDeviceVerificationRequest(
149 const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> &message,
150 TimelineModel *model);
151 void receivedDeviceVerificationCancel(const mtx::events::msg::KeyVerificationCancel &message);
152 void receivedDeviceVerificationKey(const mtx::events::msg::KeyVerificationKey &message);
153 void receivedDeviceVerificationMac(const mtx::events::msg::KeyVerificationMac &message);
154 void receivedDeviceVerificationStart(const mtx::events::msg::KeyVerificationStart &message,
155 std::string sender);
156 void receivedDeviceVerificationReady(const mtx::events::msg::KeyVerificationReady &message);
157 void receivedDeviceVerificationDone(const mtx::events::msg::KeyVerificationDone &message);
158
159 void downloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescription keyDesc,
160 const SecretsToDecrypt &secrets);
161
162 void showRoomJoinPrompt(RoomSummary *);
163 void internalKnock(const QString &room,
164 const std::vector<std::string> &via,
165 QString reason = "",
166 bool failedJoin = false,
167 bool promptForConfirmation = true);
168 void newOnlineKeyBackupAvailable();
169
170 void callFunctionOnGuiThread(std::function<void()>);
171
172 private slots:
173 void logout();
174 void removeRoom(const QString &room_id);
175 void changeRoom(const QString &room_id);
176 void dropToLoginPage(const QString &msg);
177
178 void handleSyncResponse(const mtx::responses::Sync &res, const std::string &prev_batch_token);
179
180 private:
181 static ChatPage *instance_;
182
183 void startInitialSync();
184 void tryInitialSync();
185 void trySync();
186 void verifyOneTimeKeyCountAfterStartup();
187 void ensureOneTimeKeyCount(const std::map<std::string_view, uint16_t> &counts,
188 const std::optional<std::vector<std::string>> &fallback_keys);
189 void removeOldFallbackKey();
190 void getProfileInfo();
191 void getBackupVersion();
192
193 void loadStateFromCache();
194 void resetUI();
195
196 // returns if the user had no interaction with Nheko for quite a while, which means we set our
197 // presence to unavailable if automatic presence is enabled
198 bool shouldBeUnavailable() const;
199 // If we should throttle sync processing to reduce CPU load, if people are spamming messages and
200 // we aren't looking
201 bool shouldThrottleSync() const;
202
203 template<typename T>
204 void connectCallMessage();
205
206 TimelineViewManager *view_manager_;
207
208 QTimer connectivityTimer_;
209 std::atomic_bool isConnected_;
210
211 // Global user settings.
212 QSharedPointer<UserSettings> userSettings_;
213
214 NotificationsManager *notificationsManager;
215 CallManager *callManager_;
216
217 std::unique_ptr<mtx::pushrules::PushRuleEvaluator> pushrules;
218
219 QDateTime lastSpacesUpdate = QDateTime::currentDateTime();
220
221 // Stores when our windows lost focus. Invalid when our windows have focus.
222 QDateTime lastWindowActive;
223 };