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