libkazv
Loading...
Searching...
No Matches
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#include "event.hpp"
12
13namespace Kazv::Api {
14
39class SyncJob : public BaseJob {
40public:
41 // Inner data structures
42
46 {
66 immer::array<std::string> mHeroes;
71 std::optional<int> mJoinedMemberCount;
75 std::optional<int> mInvitedMemberCount;
76
77 };
78
83 {
85 std::optional<int> highlightCount;
87 std::optional<int> notificationCount;
88
89 };
90
113 {
116 std::optional<RoomSummary> summary;
128 std::optional<StateEventBatch> state;
135 std::optional<EventBatch> ephemeral;
138 std::optional<EventBatch> accountData;
142 std::optional<UnreadNotificationCounts> unreadNotifications;
143
144 };
145
149 {
152
153 };
154
177 {
180 std::optional<InviteState> inviteState;
181
182 };
183
186 {
189
190 };
191
214 {
216 std::optional<KnockState> knockState;
217
218 };
219
241 struct LeftRoom
242 {
244 std::optional<StateEventBatch> state;
250 std::optional<EventBatch> accountData;
251
252 };
253
255 struct Rooms
256 {
259 immer::map<std::string, JoinedRoom> join;
262 immer::map<std::string, InvitedRoom> invite;
264 immer::map<std::string, KnockedRoom> knock;
267 immer::map<std::string, LeftRoom> leave;
268
269 };
270
271
272
273class JobResponse : public Response
274{
275
276public:
278 bool success() const;
279
280 // Result properties
281
282
283
284
287std::string nextBatch() const;
288
289
291std::optional<Rooms> rooms() const;
292
293
295std::optional<EventBatch> presence() const;
296
297
299std::optional<EventBatch> accountData() const;
300
301
304JsonWrap toDevice() const;
305
306
309JsonWrap deviceLists() const;
310
311
314immer::map<std::string, int> deviceOneTimeKeysCount() const;
315
316};
317 static constexpr auto needsAuth() {
318 return true
319 ;
320 }
321
322
323// Construction/destruction
324
373 explicit SyncJob(std::string serverUrl
374 , std::string _accessToken
375 ,
376 std::optional<std::string> filter = std::nullopt, std::optional<std::string> since = std::nullopt, std::optional<bool> fullState = std::nullopt, std::optional<std::string> setPresence = std::nullopt, std::optional<int> timeout = std::nullopt
377 );
378
379
381 std::optional<std::string> filter, std::optional<std::string> since, std::optional<bool> fullState, std::optional<std::string> setPresence, std::optional<int> timeout);
382
383 static BaseJob::Body buildBody(std::optional<std::string> filter, std::optional<std::string> since, std::optional<bool> fullState, std::optional<std::string> setPresence, std::optional<int> timeout);
384
385
386
387
388
390 SyncJob withData(JsonWrap j) const &;
391 };
393 }
394 namespace nlohmann
395 {
396 using namespace Kazv;
397 using namespace Kazv::Api;
398 template<>
399 struct adl_serializer<SyncJob::RoomSummary> {
400
401 static void to_json(json& jo, const SyncJob::RoomSummary &pod)
402 {
403 if (! jo.is_object()) { jo = json::object(); }
404
405
406
407 addToJsonIfNeeded(jo, "m.heroes"s, pod.mHeroes);
408
409 addToJsonIfNeeded(jo, "m.joined_member_count"s, pod.mJoinedMemberCount);
410
411 addToJsonIfNeeded(jo, "m.invited_member_count"s, pod.mInvitedMemberCount);
412 }
413
414 static void from_json(const json &jo, SyncJob::RoomSummary& result)
415 {
416
417 if (jo.contains("m.heroes"s)) {
418 result.mHeroes = jo.at("m.heroes"s);
419 }
420 if (jo.contains("m.joined_member_count"s)) {
421 result.mJoinedMemberCount = jo.at("m.joined_member_count"s);
422 }
423 if (jo.contains("m.invited_member_count"s)) {
424 result.mInvitedMemberCount = jo.at("m.invited_member_count"s);
425 }
426
427 }
428
429};
430 template<>
431 struct adl_serializer<SyncJob::UnreadNotificationCounts> {
432
433 static void to_json(json& jo, const SyncJob::UnreadNotificationCounts &pod)
434 {
435 if (! jo.is_object()) { jo = json::object(); }
436
437
438
439 addToJsonIfNeeded(jo, "highlight_count"s, pod.highlightCount);
440
441 addToJsonIfNeeded(jo, "notification_count"s, pod.notificationCount);
442 }
443
444 static void from_json(const json &jo, SyncJob::UnreadNotificationCounts& result)
445 {
446
447 if (jo.contains("highlight_count"s)) {
448 result.highlightCount = jo.at("highlight_count"s);
449 }
450 if (jo.contains("notification_count"s)) {
451 result.notificationCount = jo.at("notification_count"s);
452 }
453
454 }
455
456};
457 template<>
458 struct adl_serializer<SyncJob::JoinedRoom> {
459
460 static void to_json(json& jo, const SyncJob::JoinedRoom &pod)
461 {
462 if (! jo.is_object()) { jo = json::object(); }
463
464
465
466 addToJsonIfNeeded(jo, "summary"s, pod.summary);
467
468 addToJsonIfNeeded(jo, "state"s, pod.state);
469
470 addToJsonIfNeeded(jo, "timeline"s, pod.timeline);
471
472 addToJsonIfNeeded(jo, "ephemeral"s, pod.ephemeral);
473
474 addToJsonIfNeeded(jo, "account_data"s, pod.accountData);
475
476 addToJsonIfNeeded(jo, "unread_notifications"s, pod.unreadNotifications);
477 }
478
479 static void from_json(const json &jo, SyncJob::JoinedRoom& result)
480 {
481
482 if (jo.contains("summary"s)) {
483 result.summary = jo.at("summary"s);
484 }
485 if (jo.contains("state"s)) {
486 result.state = jo.at("state"s);
487 }
488 if (jo.contains("timeline"s)) {
489 result.timeline = jo.at("timeline"s);
490 }
491 if (jo.contains("ephemeral"s)) {
492 result.ephemeral = jo.at("ephemeral"s);
493 }
494 if (jo.contains("account_data"s)) {
495 result.accountData = jo.at("account_data"s);
496 }
497 if (jo.contains("unread_notifications"s)) {
498 result.unreadNotifications = jo.at("unread_notifications"s);
499 }
500
501 }
502
503};
504 template<>
505 struct adl_serializer<SyncJob::InviteState> {
506
507 static void to_json(json& jo, const SyncJob::InviteState &pod)
508 {
509 if (! jo.is_object()) { jo = json::object(); }
510
511
512
513 addToJsonIfNeeded(jo, "events"s, pod.events);
514 }
515
516 static void from_json(const json &jo, SyncJob::InviteState& result)
517 {
518
519 if (jo.contains("events"s)) {
520 result.events = jo.at("events"s);
521 }
522
523 }
524
525};
526 template<>
527 struct adl_serializer<SyncJob::InvitedRoom> {
528
529 static void to_json(json& jo, const SyncJob::InvitedRoom &pod)
530 {
531 if (! jo.is_object()) { jo = json::object(); }
532
533
534
535 addToJsonIfNeeded(jo, "invite_state"s, pod.inviteState);
536 }
537
538 static void from_json(const json &jo, SyncJob::InvitedRoom& result)
539 {
540
541 if (jo.contains("invite_state"s)) {
542 result.inviteState = jo.at("invite_state"s);
543 }
544
545 }
546
547};
548 template<>
549 struct adl_serializer<SyncJob::KnockState> {
550
551 static void to_json(json& jo, const SyncJob::KnockState &pod)
552 {
553 if (! jo.is_object()) { jo = json::object(); }
554
555
556
557 addToJsonIfNeeded(jo, "events"s, pod.events);
558 }
559
560 static void from_json(const json &jo, SyncJob::KnockState& result)
561 {
562
563 if (jo.contains("events"s)) {
564 result.events = jo.at("events"s);
565 }
566
567 }
568
569};
570 template<>
571 struct adl_serializer<SyncJob::KnockedRoom> {
572
573 static void to_json(json& jo, const SyncJob::KnockedRoom &pod)
574 {
575 if (! jo.is_object()) { jo = json::object(); }
576
577
578
579 addToJsonIfNeeded(jo, "knock_state"s, pod.knockState);
580 }
581
582 static void from_json(const json &jo, SyncJob::KnockedRoom& result)
583 {
584
585 if (jo.contains("knock_state"s)) {
586 result.knockState = jo.at("knock_state"s);
587 }
588
589 }
590
591};
592 template<>
593 struct adl_serializer<SyncJob::LeftRoom> {
594
595 static void to_json(json& jo, const SyncJob::LeftRoom &pod)
596 {
597 if (! jo.is_object()) { jo = json::object(); }
598
599
600
601 addToJsonIfNeeded(jo, "state"s, pod.state);
602
603 addToJsonIfNeeded(jo, "timeline"s, pod.timeline);
604
605 addToJsonIfNeeded(jo, "account_data"s, pod.accountData);
606 }
607
608 static void from_json(const json &jo, SyncJob::LeftRoom& result)
609 {
610
611 if (jo.contains("state"s)) {
612 result.state = jo.at("state"s);
613 }
614 if (jo.contains("timeline"s)) {
615 result.timeline = jo.at("timeline"s);
616 }
617 if (jo.contains("account_data"s)) {
618 result.accountData = jo.at("account_data"s);
619 }
620
621 }
622
623};
624 template<>
625 struct adl_serializer<SyncJob::Rooms> {
626
627 static void to_json(json& jo, const SyncJob::Rooms &pod)
628 {
629 if (! jo.is_object()) { jo = json::object(); }
630
631
632
633 addToJsonIfNeeded(jo, "join"s, pod.join);
634
635 addToJsonIfNeeded(jo, "invite"s, pod.invite);
636
637 addToJsonIfNeeded(jo, "knock"s, pod.knock);
638
639 addToJsonIfNeeded(jo, "leave"s, pod.leave);
640 }
641
642 static void from_json(const json &jo, SyncJob::Rooms& result)
643 {
644
645 if (jo.contains("join"s)) {
646 result.join = jo.at("join"s);
647 }
648 if (jo.contains("invite"s)) {
649 result.invite = jo.at("invite"s);
650 }
651 if (jo.contains("knock"s)) {
652 result.knock = jo.at("knock"s);
653 }
654 if (jo.contains("leave"s)) {
655 result.leave = jo.at("leave"s);
656 }
657
658 }
659
660};
661 }
662
663 namespace Kazv::Api
664 {
665
666} // namespace Kazv::Api
Definition sync.hpp:274
JsonWrap deviceLists() const
Information on end-to-end device updates, as specified in End-to-end encryption.
Definition sync.cpp:145
std::optional< EventBatch > accountData() const
The global private data created by this user.
Definition sync.cpp:123
std::optional< Rooms > rooms() const
Updates to rooms.
Definition sync.cpp:101
JsonWrap toDevice() const
Information on the send-to-device messages for the client device, as defined in Send-to-Device messag...
Definition sync.cpp:134
immer::map< std::string, int > deviceOneTimeKeysCount() const
Information on end-to-end encryption keys, as specified in End-to-end encryption.
Definition sync.cpp:156
std::string nextBatch() const
The batch token to supply in the since param of the next /sync request.
Definition sync.cpp:90
bool success() const
Definition sync.cpp:79
std::optional< EventBatch > presence() const
The updates to the presence status of other users.
Definition sync.cpp:112
Synchronise the client's state and receive new messages.
Definition sync.hpp:39
SyncJob withData(JsonWrap j) &&
Definition sync.cpp:62
static BaseJob::Query buildQuery(std::optional< std::string > filter, std::optional< std::string > since, std::optional< bool > fullState, std::optional< std::string > setPresence, std::optional< int > timeout)
Definition sync.cpp:13
static BaseJob::Body buildBody(std::optional< std::string > filter, std::optional< std::string > since, std::optional< bool > fullState, std::optional< std::string > setPresence, std::optional< int > timeout)
Definition sync.cpp:30
static constexpr auto needsAuth()
Definition sync.hpp:317
Definition basejob.hpp:94
Definition basejob.hpp:68
::Kazv::Body Body
Definition basejob.hpp:103
Definition jsonwrap.hpp:23
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 stripped state of a room that the user has been invited to.
Definition sync.hpp:149
EventList events
The stripped state events that form the invite state.
Definition sync.hpp:151
Synchronise the client's state with the latest state on the server.
Definition sync.hpp:177
std::optional< InviteState > inviteState
The stripped state of a room that the user has been invited to.
Definition sync.hpp:180
Synchronise the client's state with the latest state on the server.
Definition sync.hpp:113
std::optional< EventBatch > accountData
The private data that this user has attached to this room.
Definition sync.hpp:138
Timeline timeline
The timeline of messages and state changes in the room.
Definition sync.hpp:131
std::optional< UnreadNotificationCounts > unreadNotifications
Counts of unread notifications for this room.
Definition sync.hpp:142
std::optional< EventBatch > ephemeral
The ephemeral events in the room that aren't recorded in the timeline or state of the room.
Definition sync.hpp:135
std::optional< RoomSummary > summary
Information about the room which clients may need to correctly render it to users.
Definition sync.hpp:116
std::optional< StateEventBatch > state
Updates to the state, between the time indicated by the since parameter, and the start of the timelin...
Definition sync.hpp:128
The stripped state of a room that the user has knocked upon.
Definition sync.hpp:186
EventList events
The stripped state events that form the knock state.
Definition sync.hpp:188
Synchronise the client's state with the latest state on the server.
Definition sync.hpp:214
std::optional< KnockState > knockState
The stripped state of a room that the user has knocked upon.
Definition sync.hpp:216
Synchronise the client's state with the latest state on the server.
Definition sync.hpp:242
std::optional< StateEventBatch > state
The state updates for the room up to the start of the timeline.
Definition sync.hpp:244
Timeline timeline
The timeline of messages and state changes in the room up to the point when the user left.
Definition sync.hpp:247
std::optional< EventBatch > accountData
The private data that this user has attached to this room.
Definition sync.hpp:250
Information about the room which clients may need to correctly render it to users.
Definition sync.hpp:46
std::optional< int > mJoinedMemberCount
The number of users with membership of join, including the client's own user ID.
Definition sync.hpp:71
immer::array< std::string > mHeroes
The users which can be used to generate a room name if the room does not have one.
Definition sync.hpp:66
std::optional< int > mInvitedMemberCount
The number of users with membership of invite.
Definition sync.hpp:75
Updates to rooms.
Definition sync.hpp:256
immer::map< std::string, JoinedRoom > join
The rooms that the user has joined, mapped as room ID to room information.
Definition sync.hpp:259
immer::map< std::string, KnockedRoom > knock
The rooms that the user has knocked upon, mapped as room ID to room information.
Definition sync.hpp:264
immer::map< std::string, InvitedRoom > invite
The rooms that the user has been invited to, mapped as room ID to room information.
Definition sync.hpp:262
immer::map< std::string, LeftRoom > leave
The rooms that the user has left or been banned from, mapped as room ID to room information.
Definition sync.hpp:267
Counts of unread notifications for this room.
Definition sync.hpp:83
std::optional< int > notificationCount
The total number of unread notifications for this room.
Definition sync.hpp:87
std::optional< int > highlightCount
The number of unread notifications for this room with the highlight flag set.
Definition sync.hpp:85
Definition timeline_batch.hpp:13
Definition basejob.hpp:49
static void to_json(json &jo, const SyncJob::InviteState &pod)
Definition sync.hpp:507
static void from_json(const json &jo, SyncJob::InviteState &result)
Definition sync.hpp:516
static void from_json(const json &jo, SyncJob::InvitedRoom &result)
Definition sync.hpp:538
static void to_json(json &jo, const SyncJob::InvitedRoom &pod)
Definition sync.hpp:529
static void from_json(const json &jo, SyncJob::JoinedRoom &result)
Definition sync.hpp:479
static void to_json(json &jo, const SyncJob::JoinedRoom &pod)
Definition sync.hpp:460
static void from_json(const json &jo, SyncJob::KnockState &result)
Definition sync.hpp:560
static void to_json(json &jo, const SyncJob::KnockState &pod)
Definition sync.hpp:551
static void from_json(const json &jo, SyncJob::KnockedRoom &result)
Definition sync.hpp:582
static void to_json(json &jo, const SyncJob::KnockedRoom &pod)
Definition sync.hpp:573
static void from_json(const json &jo, SyncJob::LeftRoom &result)
Definition sync.hpp:608
static void to_json(json &jo, const SyncJob::LeftRoom &pod)
Definition sync.hpp:595
static void to_json(json &jo, const SyncJob::RoomSummary &pod)
Definition sync.hpp:401
static void from_json(const json &jo, SyncJob::RoomSummary &result)
Definition sync.hpp:414
static void from_json(const json &jo, SyncJob::Rooms &result)
Definition sync.hpp:642
static void to_json(json &jo, const SyncJob::Rooms &pod)
Definition sync.hpp:627
static void from_json(const json &jo, SyncJob::UnreadNotificationCounts &result)
Definition sync.hpp:444
static void to_json(json &jo, const SyncJob::UnreadNotificationCounts &pod)
Definition sync.hpp:433