libQuotient
A Qt library for building matrix clients
key_backup.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/csapi/definitions/key_backup_data.h>
6 #include <Quotient/csapi/definitions/room_key_backup.h>
7 
8 #include <Quotient/jobs/basejob.h>
9 
10 namespace Quotient {
11 
12 //! \brief Create a new backup.
13 //!
14 //! Creates a new backup.
15 class QUOTIENT_API PostRoomKeysVersionJob : public BaseJob {
16 public:
17  //! \param algorithm
18  //! The algorithm used for storing backups.
19  //!
20  //! \param authData
21  //! Algorithm-dependent data. See the documentation for the backup
22  //! algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
23  //! more information on the expected format of the data.
24  explicit PostRoomKeysVersionJob(const QString& algorithm, const QJsonObject& authData);
25 
26  // Result properties
27 
28  //! The backup version. This is an opaque string.
29  QString version() const { return loadFromJson<QString>("version"_L1); }
30 };
31 
32 inline auto collectResponse(const PostRoomKeysVersionJob* job) { return job->version(); }
33 
34 //! \brief Get information about the latest backup version.
35 //!
36 //! Get information about the latest backup version.
37 class QUOTIENT_API GetRoomKeysVersionCurrentJob : public BaseJob {
38 public:
39  explicit GetRoomKeysVersionCurrentJob();
40 
41  //! \brief Construct a URL without creating a full-fledged job object
42  //!
43  //! This function can be used when a URL for GetRoomKeysVersionCurrentJob
44  //! is necessary but the job itself isn't.
45  static QUrl makeRequestUrl(const HomeserverData& hsData);
46 
47  // Result properties
48 
49  //! The algorithm used for storing backups.
50  QString algorithm() const { return loadFromJson<QString>("algorithm"_L1); }
51 
52  //! Algorithm-dependent data. See the documentation for the backup
53  //! algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
54  //! more information on the expected format of the data.
55  QJsonObject authData() const { return loadFromJson<QJsonObject>("auth_data"_L1); }
56 
57  //! The number of keys stored in the backup.
58  int count() const { return loadFromJson<int>("count"_L1); }
59 
60  //! An opaque string representing stored keys in the backup.
61  //! Clients can compare it with the `etag` value they received
62  //! in the request of their last key storage request. If not
63  //! equal, another client has modified the backup.
64  QString etag() const { return loadFromJson<QString>("etag"_L1); }
65 
66  //! The backup version.
67  QString version() const { return loadFromJson<QString>("version"_L1); }
68 
69  struct Response {
70  //! The algorithm used for storing backups.
71  QString algorithm{};
72 
73  //! Algorithm-dependent data. See the documentation for the backup
74  //! algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
75  //! more information on the expected format of the data.
76  QJsonObject authData{};
77 
78  //! The number of keys stored in the backup.
79  int count{};
80 
81  //! An opaque string representing stored keys in the backup.
82  //! Clients can compare it with the `etag` value they received
83  //! in the request of their last key storage request. If not
84  //! equal, another client has modified the backup.
85  QString etag{};
86 
87  //! The backup version.
88  QString version{};
89  };
90 };
91 
92 template <std::derived_from<GetRoomKeysVersionCurrentJob> JobT>
93 constexpr inline auto doCollectResponse<JobT> =
94  [](JobT* j) -> GetRoomKeysVersionCurrentJob::Response {
95  return { j->algorithm(), j->authData(), j->count(), j->etag(), j->version() };
96 };
97 
98 //! \brief Get information about an existing backup.
99 //!
100 //! Get information about an existing backup.
101 class QUOTIENT_API GetRoomKeysVersionJob : public BaseJob {
102 public:
103  //! \param version
104  //! The backup version to get, as returned in the `version` parameter
105  //! of the response in
106  //! [`POST
107  //! /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion)
108  //! or this endpoint.
109  explicit GetRoomKeysVersionJob(const QString& version);
110 
111  //! \brief Construct a URL without creating a full-fledged job object
112  //!
113  //! This function can be used when a URL for GetRoomKeysVersionJob
114  //! is necessary but the job itself isn't.
115  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& version);
116 
117  // Result properties
118 
119  //! The algorithm used for storing backups.
120  QString algorithm() const { return loadFromJson<QString>("algorithm"_L1); }
121 
122  //! Algorithm-dependent data. See the documentation for the backup
123  //! algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
124  //! more information on the expected format of the data.
125  QJsonObject authData() const { return loadFromJson<QJsonObject>("auth_data"_L1); }
126 
127  //! The number of keys stored in the backup.
128  int count() const { return loadFromJson<int>("count"_L1); }
129 
130  //! An opaque string representing stored keys in the backup.
131  //! Clients can compare it with the `etag` value they received
132  //! in the request of their last key storage request. If not
133  //! equal, another client has modified the backup.
134  QString etag() const { return loadFromJson<QString>("etag"_L1); }
135 
136  //! The backup version.
137  QString version() const { return loadFromJson<QString>("version"_L1); }
138 
139  struct Response {
140  //! The algorithm used for storing backups.
141  QString algorithm{};
142 
143  //! Algorithm-dependent data. See the documentation for the backup
144  //! algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
145  //! more information on the expected format of the data.
146  QJsonObject authData{};
147 
148  //! The number of keys stored in the backup.
149  int count{};
150 
151  //! An opaque string representing stored keys in the backup.
152  //! Clients can compare it with the `etag` value they received
153  //! in the request of their last key storage request. If not
154  //! equal, another client has modified the backup.
155  QString etag{};
156 
157  //! The backup version.
158  QString version{};
159  };
160 };
161 
162 template <std::derived_from<GetRoomKeysVersionJob> JobT>
163 constexpr inline auto doCollectResponse<JobT> = [](JobT* j) -> GetRoomKeysVersionJob::Response {
164  return { j->algorithm(), j->authData(), j->count(), j->etag(), j->version() };
165 };
166 
167 //! \brief Update information about an existing backup.
168 //!
169 //! Update information about an existing backup. Only `auth_data` can be modified.
170 class QUOTIENT_API PutRoomKeysVersionJob : public BaseJob {
171 public:
172  //! \param version
173  //! The backup version to update, as returned in the `version`
174  //! parameter in the response of
175  //! [`POST
176  //! /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion)
177  //! or [`GET
178  //! /_matrix/client/v3/room_keys/version/{version}`](/client-server-api/#get_matrixclientv3room_keysversionversion).
179  //!
180  //! \param algorithm
181  //! The algorithm used for storing backups. Must be the same as
182  //! the algorithm currently used by the backup.
183  //!
184  //! \param authData
185  //! Algorithm-dependent data. See the documentation for the backup
186  //! algorithms in [Server-side key backups](/client-server-api/#server-side-key-backups) for
187  //! more information on the expected format of the data.
188  explicit PutRoomKeysVersionJob(const QString& version, const QString& algorithm,
189  const QJsonObject& authData);
190 };
191 
192 //! \brief Delete an existing key backup.
193 //!
194 //! Delete an existing key backup. Both the information about the backup,
195 //! as well as all key data related to the backup will be deleted.
196 class QUOTIENT_API DeleteRoomKeysVersionJob : public BaseJob {
197 public:
198  //! \param version
199  //! The backup version to delete, as returned in the `version`
200  //! parameter in the response of
201  //! [`POST
202  //! /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion)
203  //! or [`GET
204  //! /_matrix/client/v3/room_keys/version/{version}`](/client-server-api/#get_matrixclientv3room_keysversionversion).
205  explicit DeleteRoomKeysVersionJob(const QString& version);
206 
207  //! \brief Construct a URL without creating a full-fledged job object
208  //!
209  //! This function can be used when a URL for DeleteRoomKeysVersionJob
210  //! is necessary but the job itself isn't.
211  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& version);
212 };
213 
214 //! \brief Store a key in the backup.
215 //!
216 //! Store a key in the backup.
217 class QUOTIENT_API PutRoomKeyBySessionIdJob : public BaseJob {
218 public:
219  //! \param roomId
220  //! The ID of the room that the key is for.
221  //!
222  //! \param sessionId
223  //! The ID of the megolm session that the key is for.
224  //!
225  //! \param version
226  //! The backup in which to store the key. Must be the current backup.
227  //!
228  //! \param data
229  //! The key data.
230  explicit PutRoomKeyBySessionIdJob(const QString& roomId, const QString& sessionId,
231  const QString& version, const KeyBackupData& data);
232 
233  // Result properties
234 
235  //! The new etag value representing stored keys in the backup.
236  //! See `GET /room_keys/version/{version}` for more details.
237  QString etag() const { return loadFromJson<QString>("etag"_L1); }
238 
239  //! The number of keys stored in the backup
240  int count() const { return loadFromJson<int>("count"_L1); }
241 
242  struct Response {
243  //! The new etag value representing stored keys in the backup.
244  //! See `GET /room_keys/version/{version}` for more details.
245  QString etag{};
246 
247  //! The number of keys stored in the backup
248  int count{};
249  };
250 };
251 
252 template <std::derived_from<PutRoomKeyBySessionIdJob> JobT>
253 constexpr inline auto doCollectResponse<JobT> =
254  [](JobT* j) -> PutRoomKeyBySessionIdJob::Response { return { j->etag(), j->count() }; };
255 
256 //! \brief Retrieve a key from the backup.
257 //!
258 //! Retrieve a key from the backup.
259 class QUOTIENT_API GetRoomKeyBySessionIdJob : public BaseJob {
260 public:
261  //! \param roomId
262  //! The ID of the room that the requested key is for.
263  //!
264  //! \param sessionId
265  //! The ID of the megolm session whose key is requested.
266  //!
267  //! \param version
268  //! The backup from which to retrieve the key.
269  explicit GetRoomKeyBySessionIdJob(const QString& roomId, const QString& sessionId,
270  const QString& version);
271 
272  //! \brief Construct a URL without creating a full-fledged job object
273  //!
274  //! This function can be used when a URL for GetRoomKeyBySessionIdJob
275  //! is necessary but the job itself isn't.
276  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
277  const QString& sessionId, const QString& version);
278 
279  // Result properties
280 
281  //! The key data
282  KeyBackupData data() const { return fromJson<KeyBackupData>(jsonData()); }
283 };
284 
285 inline auto collectResponse(const GetRoomKeyBySessionIdJob* job) { return job->data(); }
286 
287 //! \brief Delete a key from the backup.
288 //!
289 //! Delete a key from the backup.
290 class QUOTIENT_API DeleteRoomKeyBySessionIdJob : public BaseJob {
291 public:
292  //! \param roomId
293  //! The ID of the room that the specified key is for.
294  //!
295  //! \param sessionId
296  //! The ID of the megolm session whose key is to be deleted.
297  //!
298  //! \param version
299  //! The backup from which to delete the key
300  explicit DeleteRoomKeyBySessionIdJob(const QString& roomId, const QString& sessionId,
301  const QString& version);
302 
303  //! \brief Construct a URL without creating a full-fledged job object
304  //!
305  //! This function can be used when a URL for DeleteRoomKeyBySessionIdJob
306  //! is necessary but the job itself isn't.
307  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
308  const QString& sessionId, const QString& version);
309 
310  // Result properties
311 
312  //! The new etag value representing stored keys in the backup.
313  //! See `GET /room_keys/version/{version}` for more details.
314  QString etag() const { return loadFromJson<QString>("etag"_L1); }
315 
316  //! The number of keys stored in the backup
317  int count() const { return loadFromJson<int>("count"_L1); }
318 
319  struct Response {
320  //! The new etag value representing stored keys in the backup.
321  //! See `GET /room_keys/version/{version}` for more details.
322  QString etag{};
323 
324  //! The number of keys stored in the backup
325  int count{};
326  };
327 };
328 
329 template <std::derived_from<DeleteRoomKeyBySessionIdJob> JobT>
330 constexpr inline auto doCollectResponse<JobT> =
331  [](JobT* j) -> DeleteRoomKeyBySessionIdJob::Response { return { j->etag(), j->count() }; };
332 
333 //! \brief Store several keys in the backup for a given room.
334 //!
335 //! Store several keys in the backup for a given room.
336 class QUOTIENT_API PutRoomKeysByRoomIdJob : public BaseJob {
337 public:
338  //! \param roomId
339  //! The ID of the room that the keys are for.
340  //!
341  //! \param version
342  //! The backup in which to store the keys. Must be the current backup.
343  //!
344  //! \param backupData
345  //! The backup data
346  explicit PutRoomKeysByRoomIdJob(const QString& roomId, const QString& version,
347  const RoomKeyBackup& backupData);
348 
349  // Result properties
350 
351  //! The new etag value representing stored keys in the backup.
352  //! See `GET /room_keys/version/{version}` for more details.
353  QString etag() const { return loadFromJson<QString>("etag"_L1); }
354 
355  //! The number of keys stored in the backup
356  int count() const { return loadFromJson<int>("count"_L1); }
357 
358  struct Response {
359  //! The new etag value representing stored keys in the backup.
360  //! See `GET /room_keys/version/{version}` for more details.
361  QString etag{};
362 
363  //! The number of keys stored in the backup
364  int count{};
365  };
366 };
367 
368 template <std::derived_from<PutRoomKeysByRoomIdJob> JobT>
369 constexpr inline auto doCollectResponse<JobT> =
370  [](JobT* j) -> PutRoomKeysByRoomIdJob::Response { return { j->etag(), j->count() }; };
371 
372 //! \brief Retrieve the keys from the backup for a given room.
373 //!
374 //! Retrieve the keys from the backup for a given room.
375 class QUOTIENT_API GetRoomKeysByRoomIdJob : public BaseJob {
376 public:
377  //! \param roomId
378  //! The ID of the room that the requested key is for.
379  //!
380  //! \param version
381  //! The backup from which to retrieve the key.
382  explicit GetRoomKeysByRoomIdJob(const QString& roomId, const QString& version);
383 
384  //! \brief Construct a URL without creating a full-fledged job object
385  //!
386  //! This function can be used when a URL for GetRoomKeysByRoomIdJob
387  //! is necessary but the job itself isn't.
388  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
389  const QString& version);
390 
391  // Result properties
392 
393  //! The key data. If no keys are found, then an object with an empty
394  //! `sessions` property will be returned (`{"sessions": {}}`).
395  RoomKeyBackup data() const { return fromJson<RoomKeyBackup>(jsonData()); }
396 };
397 
398 inline auto collectResponse(const GetRoomKeysByRoomIdJob* job) { return job->data(); }
399 
400 //! \brief Delete the keys from the backup for a given room.
401 //!
402 //! Delete the keys from the backup for a given room.
403 class QUOTIENT_API DeleteRoomKeysByRoomIdJob : public BaseJob {
404 public:
405  //! \param roomId
406  //! The ID of the room that the specified key is for.
407  //!
408  //! \param version
409  //! The backup from which to delete the key.
410  explicit DeleteRoomKeysByRoomIdJob(const QString& roomId, const QString& version);
411 
412  //! \brief Construct a URL without creating a full-fledged job object
413  //!
414  //! This function can be used when a URL for DeleteRoomKeysByRoomIdJob
415  //! is necessary but the job itself isn't.
416  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& roomId,
417  const QString& version);
418 
419  // Result properties
420 
421  //! The new etag value representing stored keys in the backup.
422  //! See `GET /room_keys/version/{version}` for more details.
423  QString etag() const { return loadFromJson<QString>("etag"_L1); }
424 
425  //! The number of keys stored in the backup
426  int count() const { return loadFromJson<int>("count"_L1); }
427 
428  struct Response {
429  //! The new etag value representing stored keys in the backup.
430  //! See `GET /room_keys/version/{version}` for more details.
431  QString etag{};
432 
433  //! The number of keys stored in the backup
434  int count{};
435  };
436 };
437 
438 template <std::derived_from<DeleteRoomKeysByRoomIdJob> JobT>
439 constexpr inline auto doCollectResponse<JobT> =
440  [](JobT* j) -> DeleteRoomKeysByRoomIdJob::Response { return { j->etag(), j->count() }; };
441 
442 //! \brief Store several keys in the backup.
443 //!
444 //! Store several keys in the backup.
445 class QUOTIENT_API PutRoomKeysJob : public BaseJob {
446 public:
447  //! \param version
448  //! The backup in which to store the keys. Must be the current backup.
449  //!
450  //! \param rooms
451  //! A map of room IDs to room key backup data.
452  explicit PutRoomKeysJob(const QString& version, const QHash<RoomId, RoomKeyBackup>& rooms);
453 
454  // Result properties
455 
456  //! The new etag value representing stored keys in the backup.
457  //! See `GET /room_keys/version/{version}` for more details.
458  QString etag() const { return loadFromJson<QString>("etag"_L1); }
459 
460  //! The number of keys stored in the backup
461  int count() const { return loadFromJson<int>("count"_L1); }
462 
463  struct Response {
464  //! The new etag value representing stored keys in the backup.
465  //! See `GET /room_keys/version/{version}` for more details.
466  QString etag{};
467 
468  //! The number of keys stored in the backup
469  int count{};
470  };
471 };
472 
473 template <std::derived_from<PutRoomKeysJob> JobT>
474 constexpr inline auto doCollectResponse<JobT> =
475  [](JobT* j) -> PutRoomKeysJob::Response { return { j->etag(), j->count() }; };
476 
477 //! \brief Retrieve the keys from the backup.
478 //!
479 //! Retrieve the keys from the backup.
480 class QUOTIENT_API GetRoomKeysJob : public BaseJob {
481 public:
482  //! \param version
483  //! The backup from which to retrieve the keys.
484  explicit GetRoomKeysJob(const QString& version);
485 
486  //! \brief Construct a URL without creating a full-fledged job object
487  //!
488  //! This function can be used when a URL for GetRoomKeysJob
489  //! is necessary but the job itself isn't.
490  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& version);
491 
492  // Result properties
493 
494  //! A map of room IDs to room key backup data.
495  QHash<RoomId, RoomKeyBackup> rooms() const
496  {
497  return loadFromJson<QHash<RoomId, RoomKeyBackup>>("rooms"_L1);
498  }
499 };
500 
501 inline auto collectResponse(const GetRoomKeysJob* job) { return job->rooms(); }
502 
503 //! \brief Delete the keys from the backup.
504 //!
505 //! Delete the keys from the backup.
506 class QUOTIENT_API DeleteRoomKeysJob : public BaseJob {
507 public:
508  //! \param version
509  //! The backup from which to delete the key
510  explicit DeleteRoomKeysJob(const QString& version);
511 
512  //! \brief Construct a URL without creating a full-fledged job object
513  //!
514  //! This function can be used when a URL for DeleteRoomKeysJob
515  //! is necessary but the job itself isn't.
516  static QUrl makeRequestUrl(const HomeserverData& hsData, const QString& version);
517 
518  // Result properties
519 
520  //! The new etag value representing stored keys in the backup.
521  //! See `GET /room_keys/version/{version}` for more details.
522  QString etag() const { return loadFromJson<QString>("etag"_L1); }
523 
524  //! The number of keys stored in the backup
525  int count() const { return loadFromJson<int>("count"_L1); }
526 
527  struct Response {
528  //! The new etag value representing stored keys in the backup.
529  //! See `GET /room_keys/version/{version}` for more details.
530  QString etag{};
531 
532  //! The number of keys stored in the backup
533  int count{};
534  };
535 };
536 
537 template <std::derived_from<DeleteRoomKeysJob> JobT>
538 constexpr inline auto doCollectResponse<JobT> =
539  [](JobT* j) -> DeleteRoomKeysJob::Response { return { j->etag(), j->count() }; };
540 
541 } // namespace Quotient