1 | #pragma once |
2 | |
3 | #include <optional> |
4 | #include <string> |
5 | #include <vector> |
6 | |
7 | #include "mtx/common.hpp" |
8 | #include "mtx/events/collections.hpp" |
9 | |
10 | #if __has_include(<nlohmann/json_fwd.hpp>) |
11 | #include <nlohmann/json_fwd.hpp> |
12 | #else |
13 | #include <nlohmann/json.hpp> |
14 | #endif |
15 | |
16 | namespace common = mtx::common; |
17 | |
18 | namespace mtx { |
19 | namespace responses { |
20 | //! Response from the `GET /_matrix/client/r0/directory/list/room/{roomId}`endpoint. |
21 | struct PublicRoomVisibility |
22 | { |
23 | //! The visibility of the room in the directory. One of: ["private", "public"] |
24 | common::RoomVisibility visibility; |
25 | |
26 | friend void from_json(const nlohmann::json &obj, PublicRoomVisibility &res); |
27 | }; |
28 | |
29 | struct PublicRoomsChunk |
30 | { |
31 | //! Aliases of the room. May be empty. |
32 | std::vector<std::string> aliases; |
33 | //! The canonical alias of the room, if any. |
34 | std::string canonical_alias = "" ; |
35 | //! The name of the room, if any. |
36 | std::string name; |
37 | //! **Required.** The number of members joined to the room. |
38 | size_t num_joined_members; |
39 | //! **Required.** The ID of the room. |
40 | std::string room_id; |
41 | //! The topic of the room, if any. |
42 | std::string topic; |
43 | //! **Required.** Whether the room may be viewed by guest users without joining. |
44 | bool world_readable; |
45 | //! **Required.** Whether guest users may join the room |
46 | //! and participate in it. If they can, they will be subject |
47 | //! to ordinary power level rules like any other user. |
48 | bool guest_can_join; |
49 | //! The URL for the room's avatar, if one is set. |
50 | std::string avatar_url; |
51 | |
52 | //! The room’s join rule. When not present, the room is assumed to be public. |
53 | mtx::events::state::JoinRule join_rule = mtx::events::state::JoinRule::Public; |
54 | |
55 | //! Required: The type of room (from m.room.create), if any. |
56 | std::string room_type; |
57 | |
58 | //! Optional (not all APIs return this): The version of this room. |
59 | std::string room_version; |
60 | |
61 | //! Optional: If you are a member of this room. Can usually be assumed to be "leave". |
62 | events::state::Membership membership = events::state::Membership::Leave; |
63 | |
64 | //! Optional: If the room is encrypted, the encryption algorithm. |
65 | std::string encryption; |
66 | |
67 | //! The m.space.child events of the space-room, represented as Stripped State Events with an |
68 | //! added origin_server_ts key. |
69 | //! |
70 | //! If the room is not a space-room, this should be empty. |
71 | std::vector<mtx::events::collections::StrippedEvents> children_state; |
72 | |
73 | friend void from_json(const nlohmann::json &obj, PublicRoomsChunk &res); |
74 | }; |
75 | using PublicRoom = PublicRoomsChunk; |
76 | |
77 | //! Response from the `GET /_matrix/client/r0/publicRooms` & |
78 | //! `POST /_matrix/client/r0/publicRooms` endpoints. |
79 | struct PublicRooms |
80 | { |
81 | //! **Required**. A paginated chunk of public rooms. |
82 | std::vector<PublicRoomsChunk> chunk; |
83 | //! A pagination token for the response. The absence |
84 | //! of this token means there are no more results to |
85 | //! fetch and the client should stop paginating. |
86 | std::string next_batch; |
87 | //! A pagination token that allows fetching previous results. |
88 | //! The absence of this token means there are no results |
89 | //! before this batch, i.e. this is the first batch. |
90 | std::string prev_batch; |
91 | //! An estimate on the total number of public rooms, |
92 | //! if the server has an estimate. |
93 | std::optional<size_t> total_room_count_estimate; |
94 | |
95 | friend void from_json(const nlohmann::json &obj, PublicRooms &publicRooms); |
96 | }; |
97 | |
98 | //! Response from the `GET /_matrix/client/v1/rooms/{roomId}/hierarchy` |
99 | struct HierarchyRooms |
100 | { |
101 | //! Required: The rooms for the current page, with the current filters. |
102 | std::vector<PublicRoomsChunk> rooms; |
103 | //! A token to supply to from to keep paginating the responses. Not present when there are no |
104 | //! further results. |
105 | std::string next_batch; |
106 | |
107 | friend void from_json(const nlohmann::json &obj, HierarchyRooms &publicRooms); |
108 | }; |
109 | |
110 | } // namespace responses |
111 | } // namespace mtx |
112 | |