libQuotient
A Qt library for building matrix clients
space_hierarchy.h
Go to the documentation of this file.
1 // THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
2 
3 #pragma once
4 
5 #include <Quotient/events/stateevent.h>
6 #include <Quotient/jobs/basejob.h>
7 
8 namespace Quotient {
9 
10 //! \brief Retrieve a portion of a space tree.
11 //!
12 //! Paginates over the space tree in a depth-first manner to locate child rooms of a given space.
13 //!
14 //! Where a child room is unknown to the local server, federation is used to fill in the details.
15 //! The servers listed in the `via` array should be contacted to attempt to fill in missing rooms.
16 //!
17 //! Only [`m.space.child`](#mspacechild) state events of the room are considered. Invalid child
18 //! rooms and parent events are not covered by this endpoint.
19 class QUOTIENT_API GetSpaceHierarchyJob : public BaseJob {
20 public:
21  // Inner data structures
22 
23  struct QUOTIENT_API SpaceHierarchyRoomsChunk {
24  //! The number of members joined to the room.
25  int numJoinedMembers;
26 
27  //! The ID of the room.
28  QString roomId;
29 
30  //! Whether the room may be viewed by guest users without joining.
31  bool worldReadable;
32 
33  //! Whether guest users may join the room and participate in it.
34  //! If they can, they will be subject to ordinary power level
35  //! rules like any other user.
36  bool guestCanJoin;
37 
38  //! The [`m.space.child`](#mspacechild) events of the space-room, represented
39  //! as [Stripped State Events](#stripped-state) with an added `origin_server_ts` key.
40  //!
41  //! If the room is not a space-room, this should be empty.
42  StateEvents childrenState;
43 
44  //! The canonical alias of the room, if any.
45  QString canonicalAlias{};
46 
47  //! The name of the room, if any.
48  QString name{};
49 
50  //! The topic of the room, if any.
51  QString topic{};
52 
53  //! The URL for the room's avatar, if one is set.
54  QUrl avatarUrl{};
55 
56  //! The room's join rule. When not present, the room is assumed to
57  //! be `public`.
58  QString joinRule{};
59 
60  //! The `type` of room (from [`m.room.create`](/client-server-api/#mroomcreate)), if any.
61  QString roomType{};
62  };
63 
64  // Construction/destruction
65 
66  //! \param roomId
67  //! The room ID of the space to get a hierarchy for.
68  //!
69  //! \param suggestedOnly
70  //! Optional (default `false`) flag to indicate whether or not the server should only consider
71  //! suggested rooms. Suggested rooms are annotated in their [`m.space.child`](#mspacechild)
72  //! event contents.
73  //!
74  //! \param limit
75  //! Optional limit for the maximum number of rooms to include per response. Must be an integer
76  //! greater than zero.
77  //!
78  //! Servers should apply a default value, and impose a maximum value to avoid resource
79  //! exhaustion.
80  //!
81  //! \param maxDepth
82  //! Optional limit for how far to go into the space. Must be a non-negative integer.
83  //!
84  //! When reached, no further child rooms will be returned.
85  //!
86  //! Servers should apply a default value, and impose a maximum value to avoid resource
87  //! exhaustion.
88  //!
89  //! \param from
90  //! A pagination token from a previous result. If specified, `max_depth` and `suggested_only`
91  //! cannot be changed from the first request.
92  explicit GetSpaceHierarchyJob(const QString& roomId,
93  std::optional<bool> suggestedOnly = std::nullopt,
94  std::optional<int> limit = std::nullopt,
95  std::optional<int> maxDepth = std::nullopt,
96  const QString& from = {});
97 
98  //! \brief Construct a URL without creating a full-fledged job object
99  //!
100  //! This function can be used when a URL for GetSpaceHierarchyJob
101  //! is necessary but the job itself isn't.
102  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
103  std::optional<bool> suggestedOnly = std::nullopt,
104  std::optional<int> limit = std::nullopt,
105  std::optional<int> maxDepth = std::nullopt, const QString& from = {});
106 
107  // Result properties
108 
109  //! The rooms for the current page, with the current filters.
110  std::vector<SpaceHierarchyRoomsChunk> rooms()
111  {
112  return takeFromJson<std::vector<SpaceHierarchyRoomsChunk>>("rooms"_L1);
113  }
114 
115  //! A token to supply to `from` to keep paginating the responses. Not present when there are
116  //! no further results.
117  QString nextBatch() const { return loadFromJson<QString>("next_batch"_L1); }
118 
119  struct Response {
120  //! The rooms for the current page, with the current filters.
121  std::vector<SpaceHierarchyRoomsChunk> rooms{};
122 
123  //! A token to supply to `from` to keep paginating the responses. Not present when there are
124  //! no further results.
125  QString nextBatch{};
126  };
127 };
128 
129 template <std::derived_from<GetSpaceHierarchyJob> JobT>
130 constexpr inline auto doCollectResponse<JobT> =
131  [](JobT* j) -> GetSpaceHierarchyJob::Response { return { j->rooms(), j->nextBatch() }; };
132 
133 template <>
134 struct QUOTIENT_API JsonObjectConverter<GetSpaceHierarchyJob::SpaceHierarchyRoomsChunk> {
135  static void fillFrom(const QJsonObject& jo,
136  GetSpaceHierarchyJob::SpaceHierarchyRoomsChunk& result)
137  {
138  fillFromJson(jo.value("num_joined_members"_L1), result.numJoinedMembers);
139  fillFromJson(jo.value("room_id"_L1), result.roomId);
140  fillFromJson(jo.value("world_readable"_L1), result.worldReadable);
141  fillFromJson(jo.value("guest_can_join"_L1), result.guestCanJoin);
142  fillFromJson(jo.value("children_state"_L1), result.childrenState);
143  fillFromJson(jo.value("canonical_alias"_L1), result.canonicalAlias);
144  fillFromJson(jo.value("name"_L1), result.name);
145  fillFromJson(jo.value("topic"_L1), result.topic);
146  fillFromJson(jo.value("avatar_url"_L1), result.avatarUrl);
147  fillFromJson(jo.value("join_rule"_L1), result.joinRule);
148  fillFromJson(jo.value("room_type"_L1), result.roomType);
149  }
150 };
151 
152 } // namespace Quotient