libkazv
Loading...
Searching...
No Matches
verification-tracker.hpp
Go to the documentation of this file.
1/*
2 * This file is part of libkazv.
3 * SPDX-FileCopyrightText: 2026 tusooa <tusooa@kazv.moe>
4 * SPDX-License-Identifier: AGPL-3.0-or-later
5 */
6
7#pragma once
8#include <libkazv-config.hpp>
11
12namespace Kazv
13{
20 {
22 {
23 friend bool operator==(const ProcessTheyRequested &a, const ProcessTheyRequested &b) = default;
24 };
25
27 {
28 friend bool operator==(const ProcessWaiting &a, const ProcessWaiting &b) = default;
29 };
30
32 {
34 immer::array<int> emojiIndices;
35
37 immer::array<int> decimalCode;
38
39 friend bool operator==(const ProcessCodeDisplayed &a, const ProcessCodeDisplayed &b) = default;
40 };
41
43 {
44 friend bool operator==(const ProcessVerifiedThem &a, const ProcessVerifiedThem &b) = default;
45 };
46
48 {
49 friend bool operator==(const ProcessDone &a, const ProcessDone &b) = default;
50 };
51
53 {
54 std::string reasonCode;
55 std::string reasonString;
56 friend bool operator==(const ProcessCancelled &a, const ProcessCancelled &b) = default;
57 };
58
59 using ProcessState = std::variant<
66 >;
67
68 struct Process
69 {
70 std::string theirUserId;
71 std::string theirDeviceId;
74 friend bool operator==(const Process &a, const Process &b) = default;
75 };
76
77 immer::flex_vector<Process> processes;
78 };
79
98 {
100 {
102 std::string toUserId;
103 std::string toDeviceId;
104 };
105
106 using PendingEvents = immer::flex_vector<PendingEventDesc>;
107
109 std::unordered_map<
110 std::string /* userId */,
111 std::unordered_map<
112 std::string /* deviceId */,
114 >
120
122
123 // Change functions:
132
136 [[nodiscard]] PendingEvents processIncoming(Timestamp now, EventList toDevice);
137
145 [[nodiscard]] static bool isVerificationEvent(const Event &e);
146
156
160 void collect(Timestamp now);
161
165 [[nodiscard]] PendingEvents userReady(std::string userId, std::string deviceId);
166
170 [[nodiscard]] PendingEvents userCancel(std::string userId, std::string deviceId);
171
175 [[nodiscard]] PendingEvents userConfirmMatch(std::string userId, std::string deviceId);
176
180 [[nodiscard]] PendingEvents userDenyMatch(std::string userId, std::string deviceId);
181
182 private:
186 void updateModel();
187
188 [[nodiscard]] static bool isExpired(const VerificationProcess &process, Timestamp now);
189
190 [[nodiscard]] PendingEvents processOne(const Event &e, Timestamp now);
191 };
192}
Definition event.hpp:21
Definition location.hpp:10
std::int_fast64_t Timestamp
Definition event.hpp:18
immer::flex_vector< Event > EventList
Definition types.hpp:107
Definition verification-process.hpp:80
Definition verification-tracker.hpp:53
friend bool operator==(const ProcessCancelled &a, const ProcessCancelled &b)=default
std::string reasonString
Definition verification-tracker.hpp:55
std::string reasonCode
Definition verification-tracker.hpp:54
Definition verification-tracker.hpp:32
friend bool operator==(const ProcessCodeDisplayed &a, const ProcessCodeDisplayed &b)=default
immer::array< int > emojiIndices
The indices of emojis to display.
Definition verification-tracker.hpp:34
immer::array< int > decimalCode
The numbers to display.
Definition verification-tracker.hpp:37
Definition verification-tracker.hpp:48
friend bool operator==(const ProcessDone &a, const ProcessDone &b)=default
Definition verification-tracker.hpp:22
friend bool operator==(const ProcessTheyRequested &a, const ProcessTheyRequested &b)=default
Definition verification-tracker.hpp:43
friend bool operator==(const ProcessVerifiedThem &a, const ProcessVerifiedThem &b)=default
Definition verification-tracker.hpp:27
friend bool operator==(const ProcessWaiting &a, const ProcessWaiting &b)=default
Definition verification-tracker.hpp:69
friend bool operator==(const Process &a, const Process &b)=default
std::string theirDeviceId
Definition verification-tracker.hpp:71
std::string theirUserId
Definition verification-tracker.hpp:70
ProcessState state
Definition verification-tracker.hpp:73
Timestamp requestedTs
Definition verification-tracker.hpp:72
A model that is suitable for displaying to the user.
Definition verification-tracker.hpp:20
std::variant< ProcessTheyRequested, ProcessWaiting, ProcessCodeDisplayed, ProcessVerifiedThem, ProcessDone, ProcessCancelled > ProcessState
Definition verification-tracker.hpp:66
immer::flex_vector< Process > processes
Definition verification-tracker.hpp:77
Definition verification-tracker.hpp:100
std::string toUserId
Definition verification-tracker.hpp:102
Event event
Definition verification-tracker.hpp:101
std::string toDeviceId
Definition verification-tracker.hpp:103
A stateful tracker for all verification processes.
Definition verification-tracker.hpp:98
PendingEvents userConfirmMatch(std::string userId, std::string deviceId)
Confirm an sas match for a process.
Definition verification-tracker.cpp:240
immer::flex_vector< PendingEventDesc > PendingEvents
Definition verification-tracker.hpp:106
void collect(Timestamp now)
Clean up all expired verification processes.
Definition verification-tracker.cpp:264
VerificationTrackerModel model
The model that library user should subscribe to using lager::sensor.
Definition verification-tracker.hpp:119
PendingEvents processIncoming(Timestamp now, EventList toDevice)
Process incoming verification events.
Definition verification-tracker.cpp:85
static bool isVerificationEvent(const Event &e)
Check if the event is an verification event.
Definition verification-tracker.cpp:200
PendingEvents userReady(std::string userId, std::string deviceId)
Mark ourselves ready for a process.
Definition verification-tracker.cpp:216
PendingEvents userCancel(std::string userId, std::string deviceId)
Cancel a verification process.
Definition verification-tracker.cpp:228
VerificationUtils::DeviceIdentity identity
Definition verification-tracker.hpp:108
PendingEvents requestOutgoingToDevice(VerificationUtils::DeviceIdentity theirIdentity, Timestamp now)
Request an outgoing verification for a device using to-device message.
Definition verification-tracker.cpp:41
void setTheirIdentity(VerificationUtils::DeviceIdentity theirId)
Set the key(s) for the other party in a process.
Definition verification-tracker.cpp:206
std::unordered_map< std::string, std::unordered_map< std::string, VerificationProcess > > processes
Definition verification-tracker.hpp:115
PendingEvents userDenyMatch(std::string userId, std::string deviceId)
Deny an sas match for a process.
Definition verification-tracker.cpp:252
Definition verification-utils.hpp:28