1 | /****************************************************************************** |
2 | * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN |
3 | */ |
4 | |
5 | #pragma once |
6 | |
7 | #include <Quotient/jobs/basejob.h> |
8 | |
9 | namespace Quotient { |
10 | |
11 | /*! \brief Create a new room |
12 | * |
13 | * Create a new room with various configuration options. |
14 | * |
15 | * The server MUST apply the normal state resolution rules when creating |
16 | * the new room, including checking power levels for each event. It MUST |
17 | * apply the events implied by the request in the following order: |
18 | * |
19 | * 1. The `m.room.create` event itself. Must be the first event in the |
20 | * room. |
21 | * |
22 | * 2. An `m.room.member` event for the creator to join the room. This is |
23 | * needed so the remaining events can be sent. |
24 | * |
25 | * 3. A default `m.room.power_levels` event, giving the room creator |
26 | * (and not other members) permission to send state events. Overridden |
27 | * by the `power_level_content_override` parameter. |
28 | * |
29 | * 4. An `m.room.canonical_alias` event if `room_alias_name` is given. |
30 | * |
31 | * 5. Events set by the `preset`. Currently these are the `m.room.join_rules`, |
32 | * `m.room.history_visibility`, and `m.room.guest_access` state events. |
33 | * |
34 | * 6. Events listed in `initial_state`, in the order that they are |
35 | * listed. |
36 | * |
37 | * 7. Events implied by `name` and `topic` (`m.room.name` and `m.room.topic` |
38 | * state events). |
39 | * |
40 | * 8. Invite events implied by `invite` and `invite_3pid` (`m.room.member` with |
41 | * `membership: invite` and `m.room.third_party_invite`). |
42 | * |
43 | * The available presets do the following with respect to room state: |
44 | * |
45 | * | Preset | `join_rules` | `history_visibility` | |
46 | * `guest_access` | Other | |
47 | * |------------------------|--------------|----------------------|----------------|-------| |
48 | * | `private_chat` | `invite` | `shared` | `can_join` |
49 | * | | | `trusted_private_chat` | `invite` | `shared` | |
50 | * `can_join` | All invitees are given the same power level as the room |
51 | * creator. | | `public_chat` | `public` | `shared` | |
52 | * `forbidden` | | |
53 | * |
54 | * The server will create a `m.room.create` event in the room with the |
55 | * requesting user as the creator, alongside other keys provided in the |
56 | * `creation_content`. |
57 | */ |
58 | class QUOTIENT_API CreateRoomJob : public BaseJob { |
59 | public: |
60 | // Inner data structures |
61 | |
62 | /// Create a new room with various configuration options. |
63 | /// |
64 | /// The server MUST apply the normal state resolution rules when creating |
65 | /// the new room, including checking power levels for each event. It MUST |
66 | /// apply the events implied by the request in the following order: |
67 | /// |
68 | /// 1. The `m.room.create` event itself. Must be the first event in the |
69 | /// room. |
70 | /// |
71 | /// 2. An `m.room.member` event for the creator to join the room. This is |
72 | /// needed so the remaining events can be sent. |
73 | /// |
74 | /// 3. A default `m.room.power_levels` event, giving the room creator |
75 | /// (and not other members) permission to send state events. Overridden |
76 | /// by the `power_level_content_override` parameter. |
77 | /// |
78 | /// 4. An `m.room.canonical_alias` event if `room_alias_name` is given. |
79 | /// |
80 | /// 5. Events set by the `preset`. Currently these are the |
81 | /// `m.room.join_rules`, |
82 | /// `m.room.history_visibility`, and `m.room.guest_access` state events. |
83 | /// |
84 | /// 6. Events listed in `initial_state`, in the order that they are |
85 | /// listed. |
86 | /// |
87 | /// 7. Events implied by `name` and `topic` (`m.room.name` and |
88 | /// `m.room.topic` |
89 | /// state events). |
90 | /// |
91 | /// 8. Invite events implied by `invite` and `invite_3pid` (`m.room.member` |
92 | /// with |
93 | /// `membership: invite` and `m.room.third_party_invite`). |
94 | /// |
95 | /// The available presets do the following with respect to room state: |
96 | /// |
97 | /// | Preset | `join_rules` | `history_visibility` | |
98 | /// `guest_access` | Other | |
99 | /// |------------------------|--------------|----------------------|----------------|-------| |
100 | /// | `private_chat` | `invite` | `shared` | |
101 | /// `can_join` | | | `trusted_private_chat` | `invite` | |
102 | /// `shared` | `can_join` | All invitees are given the same |
103 | /// power level as the room creator. | | `public_chat` | `public` |
104 | /// | `shared` | `forbidden` | | |
105 | /// |
106 | /// The server will create a `m.room.create` event in the room with the |
107 | /// requesting user as the creator, alongside other keys provided in the |
108 | /// `creation_content`. |
109 | struct Invite3pid { |
110 | /// The hostname+port of the identity server which should be used for |
111 | /// third-party identifier lookups. |
112 | QString idServer; |
113 | /// An access token previously registered with the identity server. |
114 | /// Servers can treat this as optional to distinguish between |
115 | /// r0.5-compatible clients and this specification version. |
116 | QString idAccessToken; |
117 | /// The kind of address being passed in the address field, for example |
118 | /// `email` (see [the list of recognised |
119 | /// values](/appendices/#3pid-types)). |
120 | QString medium; |
121 | /// The invitee's third-party identifier. |
122 | QString address; |
123 | }; |
124 | |
125 | /// Create a new room with various configuration options. |
126 | /// |
127 | /// The server MUST apply the normal state resolution rules when creating |
128 | /// the new room, including checking power levels for each event. It MUST |
129 | /// apply the events implied by the request in the following order: |
130 | /// |
131 | /// 1. The `m.room.create` event itself. Must be the first event in the |
132 | /// room. |
133 | /// |
134 | /// 2. An `m.room.member` event for the creator to join the room. This is |
135 | /// needed so the remaining events can be sent. |
136 | /// |
137 | /// 3. A default `m.room.power_levels` event, giving the room creator |
138 | /// (and not other members) permission to send state events. Overridden |
139 | /// by the `power_level_content_override` parameter. |
140 | /// |
141 | /// 4. An `m.room.canonical_alias` event if `room_alias_name` is given. |
142 | /// |
143 | /// 5. Events set by the `preset`. Currently these are the |
144 | /// `m.room.join_rules`, |
145 | /// `m.room.history_visibility`, and `m.room.guest_access` state events. |
146 | /// |
147 | /// 6. Events listed in `initial_state`, in the order that they are |
148 | /// listed. |
149 | /// |
150 | /// 7. Events implied by `name` and `topic` (`m.room.name` and |
151 | /// `m.room.topic` |
152 | /// state events). |
153 | /// |
154 | /// 8. Invite events implied by `invite` and `invite_3pid` (`m.room.member` |
155 | /// with |
156 | /// `membership: invite` and `m.room.third_party_invite`). |
157 | /// |
158 | /// The available presets do the following with respect to room state: |
159 | /// |
160 | /// | Preset | `join_rules` | `history_visibility` | |
161 | /// `guest_access` | Other | |
162 | /// |------------------------|--------------|----------------------|----------------|-------| |
163 | /// | `private_chat` | `invite` | `shared` | |
164 | /// `can_join` | | | `trusted_private_chat` | `invite` | |
165 | /// `shared` | `can_join` | All invitees are given the same |
166 | /// power level as the room creator. | | `public_chat` | `public` |
167 | /// | `shared` | `forbidden` | | |
168 | /// |
169 | /// The server will create a `m.room.create` event in the room with the |
170 | /// requesting user as the creator, alongside other keys provided in the |
171 | /// `creation_content`. |
172 | struct StateEvent { |
173 | /// The type of event to send. |
174 | QString type; |
175 | /// The content of the event. |
176 | QJsonObject content; |
177 | /// The state_key of the state event. Defaults to an empty string. |
178 | QString stateKey{}; |
179 | }; |
180 | |
181 | // Construction/destruction |
182 | |
183 | /*! \brief Create a new room |
184 | * |
185 | * \param visibility |
186 | * A `public` visibility indicates that the room will be shown |
187 | * in the published room list. A `private` visibility will hide |
188 | * the room from the published room list. Rooms default to |
189 | * `private` visibility if this key is not included. NB: This |
190 | * should not be confused with `join_rules` which also uses the |
191 | * word `public`. |
192 | * |
193 | * \param roomAliasName |
194 | * The desired room alias **local part**. If this is included, a |
195 | * room alias will be created and mapped to the newly created |
196 | * room. The alias will belong on the *same* homeserver which |
197 | * created the room. For example, if this was set to "foo" and |
198 | * sent to the homeserver "example.com" the complete room alias |
199 | * would be `#foo:example.com`. |
200 | * |
201 | * The complete room alias will become the canonical alias for |
202 | * the room and an `m.room.canonical_alias` event will be sent |
203 | * into the room. |
204 | * |
205 | * \param name |
206 | * If this is included, an `m.room.name` event will be sent |
207 | * into the room to indicate the name of the room. See Room |
208 | * Events for more information on `m.room.name`. |
209 | * |
210 | * \param topic |
211 | * If this is included, an `m.room.topic` event will be sent |
212 | * into the room to indicate the topic for the room. See Room |
213 | * Events for more information on `m.room.topic`. |
214 | * |
215 | * \param invite |
216 | * A list of user IDs to invite to the room. This will tell the |
217 | * server to invite everyone in the list to the newly created room. |
218 | * |
219 | * \param invite3pid |
220 | * A list of objects representing third-party IDs to invite into |
221 | * the room. |
222 | * |
223 | * \param roomVersion |
224 | * The room version to set for the room. If not provided, the homeserver |
225 | * is to use its configured default. If provided, the homeserver will return |
226 | * a 400 error with the errcode `M_UNSUPPORTED_ROOM_VERSION` if it does not |
227 | * support the room version. |
228 | * |
229 | * \param creationContent |
230 | * Extra keys, such as `m.federate`, to be added to the content |
231 | * of the [`m.room.create`](/client-server-api/#mroomcreate) event. The |
232 | * server will overwrite the following keys: `creator`, `room_version`. |
233 | * Future versions of the specification may allow the server to overwrite |
234 | * other keys. |
235 | * |
236 | * \param initialState |
237 | * A list of state events to set in the new room. This allows |
238 | * the user to override the default state events set in the new |
239 | * room. The expected format of the state events are an object |
240 | * with type, state_key and content keys set. |
241 | * |
242 | * Takes precedence over events set by `preset`, but gets |
243 | * overridden by `name` and `topic` keys. |
244 | * |
245 | * \param preset |
246 | * Convenience parameter for setting various default state events |
247 | * based on a preset. |
248 | * |
249 | * If unspecified, the server should use the `visibility` to determine |
250 | * which preset to use. A visbility of `public` equates to a preset of |
251 | * `public_chat` and `private` visibility equates to a preset of |
252 | * `private_chat`. |
253 | * |
254 | * \param isDirect |
255 | * This flag makes the server set the `is_direct` flag on the |
256 | * `m.room.member` events sent to the users in `invite` and |
257 | * `invite_3pid`. See [Direct |
258 | * Messaging](/client-server-api/#direct-messaging) for more information. |
259 | * |
260 | * \param powerLevelContentOverride |
261 | * The power level content to override in the default power level |
262 | * event. This object is applied on top of the generated |
263 | * [`m.room.power_levels`](/client-server-api/#mroompower_levels) |
264 | * event content prior to it being sent to the room. Defaults to |
265 | * overriding nothing. |
266 | */ |
267 | explicit CreateRoomJob(const QString& visibility = {}, |
268 | const QString& roomAliasName = {}, |
269 | const QString& name = {}, const QString& topic = {}, |
270 | const QStringList& invite = {}, |
271 | const QVector<Invite3pid>& invite3pid = {}, |
272 | const QString& roomVersion = {}, |
273 | const QJsonObject& creationContent = {}, |
274 | const QVector<StateEvent>& initialState = {}, |
275 | const QString& preset = {}, |
276 | Omittable<bool> isDirect = none, |
277 | const QJsonObject& powerLevelContentOverride = {}); |
278 | |
279 | // Result properties |
280 | |
281 | /// The created room's ID. |
282 | QString roomId() const { return loadFromJson<QString>(keyName: "room_id"_ls ); } |
283 | }; |
284 | |
285 | template <> |
286 | struct JsonObjectConverter<CreateRoomJob::Invite3pid> { |
287 | static void dumpTo(QJsonObject& jo, const CreateRoomJob::Invite3pid& pod) |
288 | { |
289 | addParam<>(container&: jo, QStringLiteral("id_server" ), value: pod.idServer); |
290 | addParam<>(container&: jo, QStringLiteral("id_access_token" ), value: pod.idAccessToken); |
291 | addParam<>(container&: jo, QStringLiteral("medium" ), value: pod.medium); |
292 | addParam<>(container&: jo, QStringLiteral("address" ), value: pod.address); |
293 | } |
294 | }; |
295 | |
296 | template <> |
297 | struct JsonObjectConverter<CreateRoomJob::StateEvent> { |
298 | static void dumpTo(QJsonObject& jo, const CreateRoomJob::StateEvent& pod) |
299 | { |
300 | addParam<>(container&: jo, QStringLiteral("type" ), value: pod.type); |
301 | addParam<>(container&: jo, QStringLiteral("content" ), value: pod.content); |
302 | addParam<IfNotEmpty>(container&: jo, QStringLiteral("state_key" ), value: pod.stateKey); |
303 | } |
304 | }; |
305 | |
306 | } // namespace Quotient |
307 | |