Debian Codegraph @

mtxclient/include/mtx/responses/sync.hpp

raw symbols SCIP
1 #pragma once
2
3 /// @file
4 /// @brief Response from the /sync API.
5
6 #include <map>
7 #include <string>
8 #include <vector>
9
10 #include "mtx/events/collections.hpp"
11 #include "mtx/events/presence.hpp"
12
13 #if __has_include(<nlohmann/json_fwd.hpp>)
14 #include <nlohmann/json_fwd.hpp>
15 #else
16 #include <nlohmann/json.hpp>
17 #endif
18
19 namespace mtx {
20 namespace responses {
21
22 //! Room specific Account Data events.
23 struct AccountData
24 {
25 //! List of events.
26 std::vector<events::collections::RoomAccountDataEvents> events;
27
28 friend void from_json(const nlohmann::json &obj, AccountData &account_data);
29 };
30
31 //! State events.
32 struct State
33 {
34 //! List of events.
35 std::vector<events::collections::StateEvents> events;
36
37 friend void from_json(const nlohmann::json &obj, State &state);
38 };
39
40 //! State and Room events.
41 struct Timeline
42 {
43 //! List of events.
44 std::vector<events::collections::TimelineEvents> events;
45 //! A token that can be supplied to to the from parameter of
46 //! the rooms/{roomId}/messages endpoint.
47 std::string prev_batch;
48 //! **true** if the number of events returned was limited by the
49 //! limit on the filter.
50 bool limited = false;
51
52 friend void from_json(const nlohmann::json &obj, Timeline &timeline);
53 };
54
55 //! Counts of unread notifications for this room
56 struct UnreadNotifications
57 {
58 //! The number of unread notifications for this room with the
59 //! highlight flag set.
60 uint64_t highlight_count = 0;
61 //! The total number of unread notifications for this room.
62 uint64_t notification_count = 0;
63
64 friend void from_json(const nlohmann::json &obj, UnreadNotifications &notifications);
65 };
66
67 //! The ephemeral events in the room that aren't recorded in
68 //! the timeline or state of the room. e.g. typing.
69 struct Ephemeral
70 {
71 //! A list of ephemeral events like typing and read notifications.
72 std::vector<events::collections::EphemeralEvents> events;
73
74 friend void from_json(const nlohmann::json &obj, Ephemeral &ephemeral);
75 };
76
77 //! A room that the user has joined.
78 struct JoinedRoom
79 {
80 //! Updates to the state, between the time indicated by the since parameter,
81 //! and the start of the timeline (or all state up to the start of the timeline,
82 //! if since is not given, or full_state is true)
83 State state;
84 //! The timeline of messages and state changes in the room.
85 Timeline timeline;
86 //! Counts of unread notifications for this room.
87 UnreadNotifications unread_notifications;
88 //! The ephemeral events in the room that aren't recorded in the
89 //! timeline or state of the room. e.g. typing.
90 Ephemeral ephemeral;
91 //! The account_data events associated with this room.
92 AccountData account_data;
93
94 friend void from_json(const nlohmann::json &obj, JoinedRoom &room);
95 };
96
97 //! A room that the user has left or been banned from.
98 struct LeftRoom
99 {
100 //! The state updates for the room up to the start of the timeline.
101 State state;
102 //! The timeline of messages and state changes in the room
103 //! up to the point when the user left.
104 Timeline timeline;
105
106 friend void from_json(const nlohmann::json &obj, LeftRoom &room);
107 };
108
109 //! A room that the user has been invited to.
110 struct InvitedRoom
111 {
112 //! The state of a room that the user has been invited to.
113 //! These state events may only have the `sender`, `type`,
114 //! `state_key` and `content` keys present.
115 std::vector<events::collections::StrippedEvents> invite_state;
116 //! Returns the name of the room.
117 std::string name() const;
118 //! Returns the URL for the avatar of the room.
119 std::string avatar() const;
120
121 friend void from_json(const nlohmann::json &obj, InvitedRoom &room);
122 };
123
124 //! A room that the user has knocked on.
125 struct KnockedRoom
126 {
127 //! The state of a room that the user has knocked on.
128 //! These state events may only have the `sender`, `type`,
129 //! `state_key` and `content` keys present.
130 std::vector<events::collections::StrippedEvents> knock_state;
131 //! Returns the name of the room.
132 std::string name() const;
133 //! Returns the URL for the avatar of the room.
134 std::string avatar() const;
135
136 friend void from_json(const nlohmann::json &obj, KnockedRoom &room);
137 };
138
139 //! Room updates.
140 struct Rooms
141 {
142 //! The rooms that the user has joined.
143 std::map<std::string, JoinedRoom> join;
144 //! The rooms that the user has left or been banned from.
145 std::map<std::string, LeftRoom> leave;
146 //! The rooms that the user has been invited to.
147 std::map<std::string, InvitedRoom> invite;
148
149 //! The rooms that the user has knocked on.
150 std::map<std::string, KnockedRoom> knock;
151
152 friend void from_json(const nlohmann::json &obj, Rooms &rooms);
153 };
154
155 //! Information on e2e device updates.
156 struct DeviceLists
157 {
158 //! List of users who have updated their device identity keys
159 //! since the previous sync response.
160 std::vector<std::string> changed;
161 //! List of users who may have left all the end-to-end encrypted
162 //! rooms they previously shared with the user.
163 std::vector<std::string> left;
164
165 friend void from_json(const nlohmann::json &obj, DeviceLists &device_lists);
166 };
167
168 //! Information on to_device events in sync.
169 struct ToDevice
170 {
171 //! Information on the send-to-device messages for the client device.
172 std::vector<events::collections::DeviceEvents> events;
173
174 friend void from_json(const nlohmann::json &obj, ToDevice &to_device);
175 };
176
177 //! Response from the `GET /_matrix/client/r0/sync` endpoint.
178 struct Sync
179 {
180 //! The batch token to supply in the since param of the next /sync request.
181 std::string next_batch;
182 //! Updates to rooms.
183 Rooms rooms;
184 //! Information on the send-to-device messages for the client device.
185 ToDevice to_device;
186 //! Information about presence of other users
187 std::vector<mtx::events::Event<mtx::events::presence::Presence>> presence;
188 //! Information on end-to-end device updates,
189 DeviceLists device_lists;
190 //! A mapping from algorithm to the number of one time keys
191 //! the server has for the current device.
192 std::map<std::string, uint16_t> device_one_time_keys_count;
193 //! Required. The unused fallback key algorithms. Absence can be used to detect server support
194 std::optional<std::vector<std::string>> device_unused_fallback_key_types;
195
196 //! global account data
197 AccountData account_data;
198
199 friend void from_json(const nlohmann::json &obj, Sync &response);
200 };
201 }
202 }