libkazv
space_hierarchy.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"
9 
10 namespace Kazv::Api {
11 
22 class GetSpaceHierarchyJob : public BaseJob {
23 public:
24  // Inner data structures
25 
34  Event
35  {
37  std::int_fast64_t originServerTs;
38 
39  };
40 
49  {
53  std::string roomId;
64  immer::array<StrippedChildStateEvent> childrenState;
66  std::optional<std::string> canonicalAlias;
68  std::optional<std::string> name;
70  std::optional<std::string> topic;
72  std::optional<std::string> avatarUrl;
75  std::optional<std::string> joinRule;
77  std::optional<std::string> roomType;
78 
79  };
80 
81 
82 
83 class JobResponse : public Response
84 {
85 
86 public:
88  bool success() const;
89 
90  // Result properties
91 
92 
93 
94 
96 immer::array<ChildRoomsChunk> rooms() const;
97 
98 
101 std::optional<std::string> nextBatch() const;
102 
103 };
104  static constexpr auto needsAuth() {
105  return true
106  ;
107  }
108 
109 
110 // Construction/destruction
111 
139  explicit GetSpaceHierarchyJob(std::string serverUrl
140  , std::string _accessToken
141  ,
142  std::string roomId , std::optional<bool> suggestedOnly = std::nullopt, std::optional<int> limit = std::nullopt, std::optional<int> maxDepth = std::nullopt, std::optional<std::string> from = std::nullopt
143  );
144 
145 
146  static BaseJob::Query buildQuery(
147  std::optional<bool> suggestedOnly, std::optional<int> limit, std::optional<int> maxDepth, std::optional<std::string> from);
148 
149  static BaseJob::Body buildBody(std::string roomId, std::optional<bool> suggestedOnly, std::optional<int> limit, std::optional<int> maxDepth, std::optional<std::string> from);
150 
151 
152 
153 
154 
157  };
159  }
160  namespace nlohmann
161  {
162  using namespace Kazv;
163  using namespace Kazv::Api;
164  template<>
165  struct adl_serializer<GetSpaceHierarchyJob::StrippedChildStateEvent> {
166 
168  {
169  if (! jo.is_object()) { jo = json::object(); }
170  jo = static_cast<const Event &>(pod);
171  //nlohmann::to_json(jo, static_cast<const Event &>(pod));
172 
173  jo["origin_server_ts"s] = pod.originServerTs;
174 
175  }
176 
178  {
179  static_cast<Event &>(result) = jo;
180  //nlohmann::from_json(jo, static_cast<const Event &>(result));
181  if (jo.contains("origin_server_ts"s)) {
182  result.originServerTs = jo.at("origin_server_ts"s);
183  }
184 
185  }
186 
187 };
188  template<>
189  struct adl_serializer<GetSpaceHierarchyJob::ChildRoomsChunk> {
190 
192  {
193  if (! jo.is_object()) { jo = json::object(); }
194 
195 
196  jo["num_joined_members"s] = pod.numJoinedMembers;
197 
198  jo["room_id"s] = pod.roomId;
199 
200  jo["world_readable"s] = pod.worldReadable;
201 
202  jo["guest_can_join"s] = pod.guestCanJoin;
203 
204  jo["children_state"s] = pod.childrenState;
205 
206 
207  addToJsonIfNeeded(jo, "canonical_alias"s, pod.canonicalAlias);
208 
209  addToJsonIfNeeded(jo, "name"s, pod.name);
210 
211  addToJsonIfNeeded(jo, "topic"s, pod.topic);
212 
213  addToJsonIfNeeded(jo, "avatar_url"s, pod.avatarUrl);
214 
215  addToJsonIfNeeded(jo, "join_rule"s, pod.joinRule);
216 
217  addToJsonIfNeeded(jo, "room_type"s, pod.roomType);
218  }
219 
220  static void from_json(const json &jo, GetSpaceHierarchyJob::ChildRoomsChunk& result)
221  {
222 
223  if (jo.contains("num_joined_members"s)) {
224  result.numJoinedMembers = jo.at("num_joined_members"s);
225  }
226  if (jo.contains("room_id"s)) {
227  result.roomId = jo.at("room_id"s);
228  }
229  if (jo.contains("world_readable"s)) {
230  result.worldReadable = jo.at("world_readable"s);
231  }
232  if (jo.contains("guest_can_join"s)) {
233  result.guestCanJoin = jo.at("guest_can_join"s);
234  }
235  if (jo.contains("children_state"s)) {
236  result.childrenState = jo.at("children_state"s);
237  }
238  if (jo.contains("canonical_alias"s)) {
239  result.canonicalAlias = jo.at("canonical_alias"s);
240  }
241  if (jo.contains("name"s)) {
242  result.name = jo.at("name"s);
243  }
244  if (jo.contains("topic"s)) {
245  result.topic = jo.at("topic"s);
246  }
247  if (jo.contains("avatar_url"s)) {
248  result.avatarUrl = jo.at("avatar_url"s);
249  }
250  if (jo.contains("join_rule"s)) {
251  result.joinRule = jo.at("join_rule"s);
252  }
253  if (jo.contains("room_type"s)) {
254  result.roomType = jo.at("room_type"s);
255  }
256 
257  }
258 
259 };
260  }
261 
262  namespace Kazv::Api
263  {
264 
265 } // namespace Kazv::Api
Definition: space_hierarchy.hpp:84
bool success() const
Definition: space_hierarchy.cpp:77
JobResponse(Response r)
Definition: space_hierarchy.cpp:74
immer::array< ChildRoomsChunk > rooms() const
The rooms for the current page, with the current filters.
Definition: space_hierarchy.cpp:88
std::optional< std::string > nextBatch() const
A token to supply to from to keep paginating the responses.
Definition: space_hierarchy.cpp:99
Retrieve a portion of a space tree.
Definition: space_hierarchy.hpp:22
static BaseJob::Body buildBody(std::string roomId, std::optional< bool > suggestedOnly, std::optional< int > limit, std::optional< int > maxDepth, std::optional< std::string > from)
Definition: space_hierarchy.cpp:28
static BaseJob::Query buildQuery(std::optional< bool > suggestedOnly, std::optional< int > limit, std::optional< int > maxDepth, std::optional< std::string > from)
Definition: space_hierarchy.cpp:13
GetSpaceHierarchyJob(std::string serverUrl, std::string _accessToken, std::string roomId, std::optional< bool > suggestedOnly=std::nullopt, std::optional< int > limit=std::nullopt, std::optional< int > maxDepth=std::nullopt, std::optional< std::string > from=std::nullopt)
Retrieve a portion of a space tree.
Definition: space_hierarchy.cpp:40
GetSpaceHierarchyJob withData(JsonWrap j) &&
Definition: space_hierarchy.cpp:60
static constexpr auto needsAuth()
Definition: space_hierarchy.hpp:104
Definition: basejob.hpp:91
Definition: basejob.hpp:77
::Kazv::Body Body
Definition: basejob.hpp:100
Definition: event.hpp:21
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
Definition: location.hpp:27
Paginates over the space tree in a depth-first manner to locate child rooms of a given space.
Definition: space_hierarchy.hpp:49
std::optional< std::string > topic
The topic of the room, if any.
Definition: space_hierarchy.hpp:70
std::optional< std::string > joinRule
The room's join rule.
Definition: space_hierarchy.hpp:75
bool guestCanJoin
Whether guest users may join the room and participate in it.
Definition: space_hierarchy.hpp:59
immer::array< StrippedChildStateEvent > childrenState
The m.space.child events of the space-room, represented as Stripped State Events with an added origin...
Definition: space_hierarchy.hpp:64
std::optional< std::string > canonicalAlias
The canonical alias of the room, if any.
Definition: space_hierarchy.hpp:66
std::string roomId
The ID of the room.
Definition: space_hierarchy.hpp:53
bool worldReadable
Whether the room may be viewed by guest users without joining.
Definition: space_hierarchy.hpp:55
std::optional< std::string > name
The name of the room, if any.
Definition: space_hierarchy.hpp:68
int numJoinedMembers
The number of members joined to the room.
Definition: space_hierarchy.hpp:51
std::optional< std::string > avatarUrl
The URL for the room's avatar, if one is set.
Definition: space_hierarchy.hpp:72
std::optional< std::string > roomType
The type of room (from m.room.create), if any.
Definition: space_hierarchy.hpp:77
Paginates over the space tree in a depth-first manner to locate child rooms of a given space.
Definition: space_hierarchy.hpp:35
std::int_fast64_t originServerTs
The origin_server_ts for the event.
Definition: space_hierarchy.hpp:37
Definition: basejob.hpp:50
static void from_json(const json &jo, GetSpaceHierarchyJob::ChildRoomsChunk &result)
Definition: space_hierarchy.hpp:220
static void to_json(json &jo, const GetSpaceHierarchyJob::ChildRoomsChunk &pod)
Definition: space_hierarchy.hpp:191
static void from_json(const json &jo, GetSpaceHierarchyJob::StrippedChildStateEvent &result)
Definition: space_hierarchy.hpp:177
static void to_json(json &jo, const GetSpaceHierarchyJob::StrippedChildStateEvent &pod)
Definition: space_hierarchy.hpp:167