libkazv
Loading...
Searching...
No Matches
old_sync.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
3 */
4
5#pragma once
6
7#include "basejob.hpp"
8
9
10namespace Kazv::Api {
11
22class GetEventsJob : public BaseJob {
23public:
24
25
26
27class JobResponse : public Response
28{
29
30public:
32 bool success() const;
33
34 // Result properties
35
36
37
38
41std::optional<std::string> start() const;
42
43
46std::optional<std::string> end() const;
47
48
50EventList chunk() const;
51
52};
53 static constexpr auto needsAuth() {
54 return true
55 ;
56 }
57
58
59// Construction/destruction
60
70 explicit GetEventsJob(std::string serverUrl
71 , std::string _accessToken
72 ,
73 std::optional<std::string> from = std::nullopt, std::optional<int> timeout = std::nullopt
74 );
75
76
78 std::optional<std::string> from, std::optional<int> timeout);
79
80 static BaseJob::Body buildBody(std::optional<std::string> from, std::optional<int> timeout);
81
82
83
84
85
88 };
90 }
91 namespace nlohmann
92 {
93 using namespace Kazv;
94 using namespace Kazv::Api;
95
96 }
97
98 namespace Kazv::Api
99 {
100
111class InitialSyncJob : public BaseJob {
112public:
113 // Inner data structures
114
117 {
122 std::string end;
136 std::optional<std::string> start;
137
138 };
139
147 struct RoomInfo
148 {
150 std::string roomId;
152 std::string membership;
156 std::optional<PaginationChunk> messages;
164 std::optional<std::string> visibility;
168
169 };
170
171
172
173class JobResponse : public Response
174{
175
176public:
178 bool success() const;
179
180 // Result properties
181
182
183
184
188std::string end() const;
189
190
192EventList presence() const;
193
194
202immer::array<RoomInfo> rooms() const;
203
204
206EventList accountData() const;
207
208};
209 static constexpr auto needsAuth() {
210 return true
211 ;
212 }
213
214
215// Construction/destruction
216
228 explicit InitialSyncJob(std::string serverUrl
229 , std::string _accessToken
230 ,
231 std::optional<int> limit = std::nullopt, std::optional<bool> archived = std::nullopt
232 );
233
234
236 std::optional<int> limit, std::optional<bool> archived);
237
238 static BaseJob::Body buildBody(std::optional<int> limit, std::optional<bool> archived);
239
240
241
242
243
246 };
248 }
249 namespace nlohmann
250 {
251 using namespace Kazv;
252 using namespace Kazv::Api;
253 template<>
254 struct adl_serializer<InitialSyncJob::PaginationChunk> {
255
256 static void to_json(json& jo, const InitialSyncJob::PaginationChunk &pod)
257 {
258 if (! jo.is_object()) { jo = json::object(); }
259
260
261 jo["end"s] = pod.end;
262
263 jo["chunk"s] = pod.chunk;
264
265
266 addToJsonIfNeeded(jo, "start"s, pod.start);
267 }
268
269 static void from_json(const json &jo, InitialSyncJob::PaginationChunk& result)
270 {
271
272 if (jo.contains("end"s)) {
273 result.end = jo.at("end"s);
274 }
275 if (jo.contains("chunk"s)) {
276 result.chunk = jo.at("chunk"s);
277 }
278 if (jo.contains("start"s)) {
279 result.start = jo.at("start"s);
280 }
281
282 }
283
284};
285 template<>
286 struct adl_serializer<InitialSyncJob::RoomInfo> {
287
288 static void to_json(json& jo, const InitialSyncJob::RoomInfo &pod)
289 {
290 if (! jo.is_object()) { jo = json::object(); }
291
292
293 jo["room_id"s] = pod.roomId;
294
295 jo["membership"s] = pod.membership;
296
297
298 addToJsonIfNeeded(jo, "invite"s, pod.invite);
299
300 addToJsonIfNeeded(jo, "messages"s, pod.messages);
301
302 addToJsonIfNeeded(jo, "state"s, pod.state);
303
304 addToJsonIfNeeded(jo, "visibility"s, pod.visibility);
305
306 addToJsonIfNeeded(jo, "account_data"s, pod.accountData);
307 }
308
309 static void from_json(const json &jo, InitialSyncJob::RoomInfo& result)
310 {
311
312 if (jo.contains("room_id"s)) {
313 result.roomId = jo.at("room_id"s);
314 }
315 if (jo.contains("membership"s)) {
316 result.membership = jo.at("membership"s);
317 }
318 if (jo.contains("invite"s)) {
319 result.invite = jo.at("invite"s);
320 }
321 if (jo.contains("messages"s)) {
322 result.messages = jo.at("messages"s);
323 }
324 if (jo.contains("state"s)) {
325 result.state = jo.at("state"s);
326 }
327 if (jo.contains("visibility"s)) {
328 result.visibility = jo.at("visibility"s);
329 }
330 if (jo.contains("account_data"s)) {
331 result.accountData = jo.at("account_data"s);
332 }
333
334 }
335
336};
337 }
338
339 namespace Kazv::Api
340 {
341
352class GetOneEventJob : public BaseJob {
353public:
354
355
356
357class JobResponse : public Response
358{
359
360public:
362 bool success() const;
363
364 // Result properties
365
366
368
370 {
371 return
372 std::move(jsonBody().get()).get<JsonWrap>()
373 ;
374 }
375
376
377};
378 static constexpr auto needsAuth() {
379 return true
380 ;
381 }
382
383
384// Construction/destruction
385
391 explicit GetOneEventJob(std::string serverUrl
392 , std::string _accessToken
393 ,
394 std::string eventId
395 );
396
397
399 );
400
401 static BaseJob::Body buildBody(std::string eventId);
402
403
404
405
406
409 };
411 }
412 namespace nlohmann
413 {
414 using namespace Kazv;
415 using namespace Kazv::Api;
416
417 }
418
419 namespace Kazv::Api
420 {
421
422} // namespace Kazv::Api
Definition old_sync.hpp:28
std::optional< std::string > end() const
A token which correlates to the end of chunk.
Definition old_sync.cpp:94
std::optional< std::string > start() const
A token which correlates to the start of chunk.
Definition old_sync.cpp:83
bool success() const
Definition old_sync.cpp:73
EventList chunk() const
An array of events.
Definition old_sync.cpp:105
Listen on the event stream.
Definition old_sync.hpp:22
static constexpr auto needsAuth()
Definition old_sync.hpp:53
static BaseJob::Query buildQuery(std::optional< std::string > from, std::optional< int > timeout)
Definition old_sync.cpp:13
static BaseJob::Body buildBody(std::optional< std::string > from, std::optional< int > timeout)
Definition old_sync.cpp:24
GetEventsJob withData(JsonWrap j) &&
Definition old_sync.cpp:56
Definition old_sync.hpp:358
bool success() const
Definition old_sync.cpp:292
JsonWrap data() const
The full event.
Definition old_sync.hpp:369
Get a single event by event ID.
Definition old_sync.hpp:352
static BaseJob::Query buildQuery()
Definition old_sync.cpp:235
static constexpr auto needsAuth()
Definition old_sync.hpp:378
static BaseJob::Body buildBody(std::string eventId)
Definition old_sync.cpp:243
GetOneEventJob withData(JsonWrap j) &&
Definition old_sync.cpp:275
Definition old_sync.hpp:174
EventList presence() const
A list of presence events.
Definition old_sync.cpp:201
std::string end() const
A token which correlates to the end of the timelines returned.
Definition old_sync.cpp:190
immer::array< RoomInfo > rooms() const
This returns the full state for this user, with an optional limit on the number of messages per room ...
Definition old_sync.cpp:212
EventList accountData() const
The global private data created by this user.
Definition old_sync.cpp:223
bool success() const
Definition old_sync.cpp:177
Get the user's current state.
Definition old_sync.hpp:111
static constexpr auto needsAuth()
Definition old_sync.hpp:209
static BaseJob::Body buildBody(std::optional< int > limit, std::optional< bool > archived)
Definition old_sync.cpp:128
static BaseJob::Query buildQuery(std::optional< int > limit, std::optional< bool > archived)
Definition old_sync.cpp:117
InitialSyncJob withData(JsonWrap j) &&
Definition old_sync.cpp:160
Definition basejob.hpp:94
Definition basejob.hpp:68
::Kazv::Body Body
Definition basejob.hpp:103
Definition jsonwrap.hpp:23
const json & get() const
Definition jsonwrap.hpp:40
Definition location.hpp:10
Definition location.hpp:10
void addToJsonIfNeeded(json &j, std::string name, T &&arg)
Definition types.hpp:80
nlohmann::json json
Definition jsonwrap.hpp:20
immer::flex_vector< Event > EventList
Definition types.hpp:107
Definition location.hpp:27
The pagination chunk for this room.
Definition old_sync.hpp:117
std::string end
A token which correlates to the end of chunk.
Definition old_sync.hpp:122
std::optional< std::string > start
A token which correlates to the start of chunk.
Definition old_sync.hpp:136
EventList chunk
If the user is a member of the room this will be a list of the most recent messages for this room.
Definition old_sync.hpp:128
This returns the full state for this user, with an optional limit on the number of messages per room ...
Definition old_sync.hpp:148
std::string roomId
The ID of this room.
Definition old_sync.hpp:150
std::optional< std::string > visibility
Whether this room is visible to the /publicRooms API or not.
Definition old_sync.hpp:164
EventList accountData
The private data that this user has attached to this room.
Definition old_sync.hpp:167
std::string membership
The user's membership state in this room.
Definition old_sync.hpp:152
EventList state
If the user is a member of the room this will be the current state of the room as a list of events.
Definition old_sync.hpp:161
std::optional< PaginationChunk > messages
The pagination chunk for this room.
Definition old_sync.hpp:156
JsonWrap invite
The invite event if membership is invite
Definition old_sync.hpp:154
Definition basejob.hpp:49
JsonWrap jsonBody() const
Definition basejob.cpp:141
static void from_json(const json &jo, InitialSyncJob::PaginationChunk &result)
Definition old_sync.hpp:269
static void to_json(json &jo, const InitialSyncJob::PaginationChunk &pod)
Definition old_sync.hpp:256
static void to_json(json &jo, const InitialSyncJob::RoomInfo &pod)
Definition old_sync.hpp:288
static void from_json(const json &jo, InitialSyncJob::RoomInfo &result)
Definition old_sync.hpp:309