1/******************************************************************************
2 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
3 */
4
5#pragma once
6
7#include <Quotient/events/roomevent.h>
8#include <Quotient/events/stateevent.h>
9#include <Quotient/jobs/basejob.h>
10
11namespace Quotient {
12
13/*! \brief Get a single event by event ID.
14 *
15 * Get a single event based on `roomId/eventId`. You must have permission to
16 * retrieve this event e.g. by being a member in the room for this event.
17 */
18class QUOTIENT_API GetOneRoomEventJob : public BaseJob {
19public:
20 /*! \brief Get a single event by event ID.
21 *
22 * \param roomId
23 * The ID of the room the event is in.
24 *
25 * \param eventId
26 * The event ID to get.
27 */
28 explicit GetOneRoomEventJob(const QString& roomId, const QString& eventId);
29
30 /*! \brief Construct a URL without creating a full-fledged job object
31 *
32 * This function can be used when a URL for GetOneRoomEventJob
33 * is necessary but the job itself isn't.
34 */
35 static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId,
36 const QString& eventId);
37
38 // Result properties
39
40 /// The full event.
41 RoomEventPtr event() { return fromJson<RoomEventPtr>(json: jsonData()); }
42};
43
44/*! \brief Get the state identified by the type and key.
45 *
46 * Looks up the contents of a state event in a room. If the user is
47 * joined to the room then the state is taken from the current
48 * state of the room. If the user has left the room then the state is
49 * taken from the state of the room when they left.
50 */
51class QUOTIENT_API GetRoomStateWithKeyJob : public BaseJob {
52public:
53 /*! \brief Get the state identified by the type and key.
54 *
55 * \param roomId
56 * The room to look up the state in.
57 *
58 * \param eventType
59 * The type of state to look up.
60 *
61 * \param stateKey
62 * The key of the state to look up. Defaults to an empty string. When
63 * an empty string, the trailing slash on this endpoint is optional.
64 */
65 explicit GetRoomStateWithKeyJob(const QString& roomId,
66 const QString& eventType,
67 const QString& stateKey);
68
69 /*! \brief Construct a URL without creating a full-fledged job object
70 *
71 * This function can be used when a URL for GetRoomStateWithKeyJob
72 * is necessary but the job itself isn't.
73 */
74 static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId,
75 const QString& eventType,
76 const QString& stateKey);
77};
78
79/*! \brief Get all state events in the current state of a room.
80 *
81 * Get the state events for the current state of a room.
82 */
83class QUOTIENT_API GetRoomStateJob : public BaseJob {
84public:
85 /*! \brief Get all state events in the current state of a room.
86 *
87 * \param roomId
88 * The room to look up the state for.
89 */
90 explicit GetRoomStateJob(const QString& roomId);
91
92 /*! \brief Construct a URL without creating a full-fledged job object
93 *
94 * This function can be used when a URL for GetRoomStateJob
95 * is necessary but the job itself isn't.
96 */
97 static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);
98
99 // Result properties
100
101 /// The current state of the room
102 StateEvents events() { return fromJson<StateEvents>(json: jsonData()); }
103};
104
105/*! \brief Get the m.room.member events for the room.
106 *
107 * Get the list of members for this room.
108 */
109class QUOTIENT_API GetMembersByRoomJob : public BaseJob {
110public:
111 /*! \brief Get the m.room.member events for the room.
112 *
113 * \param roomId
114 * The room to get the member events for.
115 *
116 * \param at
117 * The point in time (pagination token) to return members for in the room.
118 * This token can be obtained from a `prev_batch` token returned for
119 * each room by the sync API. Defaults to the current state of the room,
120 * as determined by the server.
121 *
122 * \param membership
123 * The kind of membership to filter for. Defaults to no filtering if
124 * unspecified. When specified alongside `not_membership`, the two
125 * parameters create an 'or' condition: either the membership *is*
126 * the same as `membership` **or** *is not* the same as `not_membership`.
127 *
128 * \param notMembership
129 * The kind of membership to exclude from the results. Defaults to no
130 * filtering if unspecified.
131 */
132 explicit GetMembersByRoomJob(const QString& roomId, const QString& at = {},
133 const QString& membership = {},
134 const QString& notMembership = {});
135
136 /*! \brief Construct a URL without creating a full-fledged job object
137 *
138 * This function can be used when a URL for GetMembersByRoomJob
139 * is necessary but the job itself isn't.
140 */
141 static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId,
142 const QString& at = {},
143 const QString& membership = {},
144 const QString& notMembership = {});
145
146 // Result properties
147
148 /// Get the list of members for this room.
149 StateEvents chunk() { return takeFromJson<StateEvents>(key: "chunk"_ls); }
150};
151
152/*! \brief Gets the list of currently joined users and their profile data.
153 *
154 * This API returns a map of MXIDs to member info objects for members of the
155 * room. The current user must be in the room for it to work, unless it is an
156 * Application Service in which case any of the AS's users must be in the room.
157 * This API is primarily for Application Services and should be faster to respond
158 * than `/members` as it can be implemented more efficiently on the server.
159 */
160class QUOTIENT_API GetJoinedMembersByRoomJob : public BaseJob {
161public:
162 // Inner data structures
163
164 /// This API returns a map of MXIDs to member info objects for members of
165 /// the room. The current user must be in the room for it to work, unless it
166 /// is an Application Service in which case any of the AS's users must be in
167 /// the room. This API is primarily for Application Services and should be
168 /// faster to respond than `/members` as it can be implemented more
169 /// efficiently on the server.
170 struct RoomMember {
171 /// The display name of the user this object is representing.
172 QString displayName{};
173 /// The avatar of the user this object is representing, as an [`mxc://`
174 /// URI](/client-server-api/#matrix-content-mxc-uris).
175 QUrl avatarUrl{};
176 };
177
178 // Construction/destruction
179
180 /*! \brief Gets the list of currently joined users and their profile data.
181 *
182 * \param roomId
183 * The room to get the members of.
184 */
185 explicit GetJoinedMembersByRoomJob(const QString& roomId);
186
187 /*! \brief Construct a URL without creating a full-fledged job object
188 *
189 * This function can be used when a URL for GetJoinedMembersByRoomJob
190 * is necessary but the job itself isn't.
191 */
192 static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId);
193
194 // Result properties
195
196 /// A map from user ID to a RoomMember object.
197 QHash<QString, RoomMember> joined() const
198 {
199 return loadFromJson<QHash<QString, RoomMember>>(keyName: "joined"_ls);
200 }
201};
202
203template <>
204struct JsonObjectConverter<GetJoinedMembersByRoomJob::RoomMember> {
205 static void fillFrom(const QJsonObject& jo,
206 GetJoinedMembersByRoomJob::RoomMember& result)
207 {
208 fillFromJson(jv: jo.value(key: "display_name"_ls), pod&: result.displayName);
209 fillFromJson(jv: jo.value(key: "avatar_url"_ls), pod&: result.avatarUrl);
210 }
211};
212
213} // namespace Quotient
214