diff --git a/Quotient/csapi/definitions/key_backup_data.h b/Quotient/csapi/definitions/key_backup_data.h new file mode 100644 index 000000000..f7c2f050b --- /dev/null +++ b/Quotient/csapi/definitions/key_backup_data.h @@ -0,0 +1,49 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include + +namespace Quotient { +/// The key data +struct KeyBackupData { + /// The index of the first message in the session that the key can decrypt. + int firstMessageIndex; + + /// The number of times this key has been forwarded via key-sharing between + /// devices. + int forwardedCount; + + /// Whether the device backing up the key verified the device that the key + /// is from. + bool isVerified; + + /// Algorithm-dependent data. See the documentation for the backup + /// algorithms in [Server-side key + /// backups](/client-server-api/#server-side-key-backups) for more + /// information on the expected format of the data. + QJsonObject sessionData; +}; + +template <> +struct JsonObjectConverter { + static void dumpTo(QJsonObject& jo, const KeyBackupData& pod) + { + addParam<>(jo, QStringLiteral("first_message_index"), + pod.firstMessageIndex); + addParam<>(jo, QStringLiteral("forwarded_count"), pod.forwardedCount); + addParam<>(jo, QStringLiteral("is_verified"), pod.isVerified); + addParam<>(jo, QStringLiteral("session_data"), pod.sessionData); + } + static void fillFrom(const QJsonObject& jo, KeyBackupData& pod) + { + fillFromJson(jo.value("first_message_index"_ls), pod.firstMessageIndex); + fillFromJson(jo.value("forwarded_count"_ls), pod.forwardedCount); + fillFromJson(jo.value("is_verified"_ls), pod.isVerified); + fillFromJson(jo.value("session_data"_ls), pod.sessionData); + } +}; + +} // namespace Quotient diff --git a/Quotient/csapi/definitions/room_key_backup.h b/Quotient/csapi/definitions/room_key_backup.h new file mode 100644 index 000000000..6b2bf11e5 --- /dev/null +++ b/Quotient/csapi/definitions/room_key_backup.h @@ -0,0 +1,30 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include + +#include + +namespace Quotient { +/// The backed up keys for a room. +struct RoomKeyBackup { + /// A map of session IDs to key data. + QHash sessions; +}; + +template <> +struct JsonObjectConverter { + static void dumpTo(QJsonObject& jo, const RoomKeyBackup& pod) + { + addParam<>(jo, QStringLiteral("sessions"), pod.sessions); + } + static void fillFrom(const QJsonObject& jo, RoomKeyBackup& pod) + { + fillFromJson(jo.value("sessions"_ls), pod.sessions); + } +}; + +} // namespace Quotient diff --git a/Quotient/csapi/key_backup.cpp b/Quotient/csapi/key_backup.cpp new file mode 100644 index 000000000..68857c3a6 --- /dev/null +++ b/Quotient/csapi/key_backup.cpp @@ -0,0 +1,295 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "key_backup.h" + +using namespace Quotient; + +PostRoomKeysVersionJob::PostRoomKeysVersionJob(const QString& algorithm, + const QJsonObject& authData) + : BaseJob(HttpVerb::Post, QStringLiteral("PostRoomKeysVersionJob"), + makePath("/_matrix/client/v3", "/room_keys/version")) +{ + QJsonObject _dataJson; + addParam<>(_dataJson, QStringLiteral("algorithm"), algorithm); + addParam<>(_dataJson, QStringLiteral("auth_data"), authData); + setRequestData({ _dataJson }); + addExpectedKey("version"); +} + +QUrl GetRoomKeysVersionCurrentJob::makeRequestUrl(QUrl baseUrl) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/version")); +} + +GetRoomKeysVersionCurrentJob::GetRoomKeysVersionCurrentJob() + : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomKeysVersionCurrentJob"), + makePath("/_matrix/client/v3", "/room_keys/version")) +{ + addExpectedKey("algorithm"); + addExpectedKey("auth_data"); + addExpectedKey("count"); + addExpectedKey("etag"); + addExpectedKey("version"); +} + +QUrl GetRoomKeysVersionJob::makeRequestUrl(QUrl baseUrl, const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/version/", version)); +} + +GetRoomKeysVersionJob::GetRoomKeysVersionJob(const QString& version) + : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomKeysVersionJob"), + makePath("/_matrix/client/v3", "/room_keys/version/", version)) +{ + addExpectedKey("algorithm"); + addExpectedKey("auth_data"); + addExpectedKey("count"); + addExpectedKey("etag"); + addExpectedKey("version"); +} + +PutRoomKeysVersionJob::PutRoomKeysVersionJob(const QString& version, + const QString& algorithm, + const QJsonObject& authData) + : BaseJob(HttpVerb::Put, QStringLiteral("PutRoomKeysVersionJob"), + makePath("/_matrix/client/v3", "/room_keys/version/", version)) +{ + QJsonObject _dataJson; + addParam<>(_dataJson, QStringLiteral("algorithm"), algorithm); + addParam<>(_dataJson, QStringLiteral("auth_data"), authData); + setRequestData({ _dataJson }); +} + +QUrl DeleteRoomKeysVersionJob::makeRequestUrl(QUrl baseUrl, + const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/version/", version)); +} + +DeleteRoomKeysVersionJob::DeleteRoomKeysVersionJob(const QString& version) + : BaseJob(HttpVerb::Delete, QStringLiteral("DeleteRoomKeysVersionJob"), + makePath("/_matrix/client/v3", "/room_keys/version/", version)) +{} + +auto queryToPutRoomKeyBySessionId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +PutRoomKeyBySessionIdJob::PutRoomKeyBySessionIdJob(const QString& roomId, + const QString& sessionId, + const QString& version, + const KeyBackupData& data) + : BaseJob(HttpVerb::Put, QStringLiteral("PutRoomKeyBySessionIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId, "/", + sessionId), + queryToPutRoomKeyBySessionId(version)) +{ + setRequestData({ toJson(data) }); + addExpectedKey("etag"); + addExpectedKey("count"); +} + +auto queryToGetRoomKeyBySessionId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl GetRoomKeyBySessionIdJob::makeRequestUrl(QUrl baseUrl, + const QString& roomId, + const QString& sessionId, + const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys/", roomId, "/", + sessionId), + queryToGetRoomKeyBySessionId(version)); +} + +GetRoomKeyBySessionIdJob::GetRoomKeyBySessionIdJob(const QString& roomId, + const QString& sessionId, + const QString& version) + : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomKeyBySessionIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId, "/", + sessionId), + queryToGetRoomKeyBySessionId(version)) +{} + +auto queryToDeleteRoomKeyBySessionId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl DeleteRoomKeyBySessionIdJob::makeRequestUrl(QUrl baseUrl, + const QString& roomId, + const QString& sessionId, + const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys/", roomId, "/", + sessionId), + queryToDeleteRoomKeyBySessionId(version)); +} + +DeleteRoomKeyBySessionIdJob::DeleteRoomKeyBySessionIdJob( + const QString& roomId, const QString& sessionId, const QString& version) + : BaseJob(HttpVerb::Delete, QStringLiteral("DeleteRoomKeyBySessionIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId, "/", + sessionId), + queryToDeleteRoomKeyBySessionId(version)) +{ + addExpectedKey("etag"); + addExpectedKey("count"); +} + +auto queryToPutRoomKeysByRoomId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +PutRoomKeysByRoomIdJob::PutRoomKeysByRoomIdJob(const QString& roomId, + const QString& version, + const RoomKeyBackup& backupData) + : BaseJob(HttpVerb::Put, QStringLiteral("PutRoomKeysByRoomIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId), + queryToPutRoomKeysByRoomId(version)) +{ + setRequestData({ toJson(backupData) }); + addExpectedKey("etag"); + addExpectedKey("count"); +} + +auto queryToGetRoomKeysByRoomId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl GetRoomKeysByRoomIdJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys/", roomId), + queryToGetRoomKeysByRoomId(version)); +} + +GetRoomKeysByRoomIdJob::GetRoomKeysByRoomIdJob(const QString& roomId, + const QString& version) + : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomKeysByRoomIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId), + queryToGetRoomKeysByRoomId(version)) +{} + +auto queryToDeleteRoomKeysByRoomId(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl DeleteRoomKeysByRoomIdJob::makeRequestUrl(QUrl baseUrl, + const QString& roomId, + const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys/", roomId), + queryToDeleteRoomKeysByRoomId(version)); +} + +DeleteRoomKeysByRoomIdJob::DeleteRoomKeysByRoomIdJob(const QString& roomId, + const QString& version) + : BaseJob(HttpVerb::Delete, QStringLiteral("DeleteRoomKeysByRoomIdJob"), + makePath("/_matrix/client/v3", "/room_keys/keys/", roomId), + queryToDeleteRoomKeysByRoomId(version)) +{ + addExpectedKey("etag"); + addExpectedKey("count"); +} + +auto queryToPutRoomKeys(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +PutRoomKeysJob::PutRoomKeysJob(const QString& version, + const QHash& rooms) + : BaseJob(HttpVerb::Put, QStringLiteral("PutRoomKeysJob"), + makePath("/_matrix/client/v3", "/room_keys/keys"), + queryToPutRoomKeys(version)) +{ + QJsonObject _dataJson; + addParam<>(_dataJson, QStringLiteral("rooms"), rooms); + setRequestData({ _dataJson }); + addExpectedKey("etag"); + addExpectedKey("count"); +} + +auto queryToGetRoomKeys(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl GetRoomKeysJob::makeRequestUrl(QUrl baseUrl, const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys"), + queryToGetRoomKeys(version)); +} + +GetRoomKeysJob::GetRoomKeysJob(const QString& version) + : BaseJob(HttpVerb::Get, QStringLiteral("GetRoomKeysJob"), + makePath("/_matrix/client/v3", "/room_keys/keys"), + queryToGetRoomKeys(version)) +{ + addExpectedKey("rooms"); +} + +auto queryToDeleteRoomKeys(const QString& version) +{ + QUrlQuery _q; + addParam<>(_q, QStringLiteral("version"), version); + return _q; +} + +QUrl DeleteRoomKeysJob::makeRequestUrl(QUrl baseUrl, const QString& version) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + makePath("/_matrix/client/v3", + "/room_keys/keys"), + queryToDeleteRoomKeys(version)); +} + +DeleteRoomKeysJob::DeleteRoomKeysJob(const QString& version) + : BaseJob(HttpVerb::Delete, QStringLiteral("DeleteRoomKeysJob"), + makePath("/_matrix/client/v3", "/room_keys/keys"), + queryToDeleteRoomKeys(version)) +{ + addExpectedKey("etag"); + addExpectedKey("count"); +} diff --git a/Quotient/csapi/key_backup.h b/Quotient/csapi/key_backup.h new file mode 100644 index 000000000..c7fb6124c --- /dev/null +++ b/Quotient/csapi/key_backup.h @@ -0,0 +1,486 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include +#include + +#include + +namespace Quotient { + +/*! \brief Create a new backup. + * + * Creates a new backup. + */ +class QUOTIENT_API PostRoomKeysVersionJob : public BaseJob { +public: + /*! \brief Create a new backup. + * + * \param algorithm + * The algorithm used for storing backups. + * + * \param authData + * Algorithm-dependent data. See the documentation for the backup + * algorithms in [Server-side key + * backups](/client-server-api/#server-side-key-backups) for more + * information on the expected format of the data. + */ + explicit PostRoomKeysVersionJob(const QString& algorithm, + const QJsonObject& authData); + + // Result properties + + /// The backup version. This is an opaque string. + QString version() const { return loadFromJson("version"_ls); } +}; + +/*! \brief Get information about the latest backup version. + * + * Get information about the latest backup version. + */ +class QUOTIENT_API GetRoomKeysVersionCurrentJob : public BaseJob { +public: + /// Get information about the latest backup version. + explicit GetRoomKeysVersionCurrentJob(); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetRoomKeysVersionCurrentJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl); + + // Result properties + + /// The algorithm used for storing backups. + QString algorithm() const { return loadFromJson("algorithm"_ls); } + + /// Algorithm-dependent data. See the documentation for the backup + /// algorithms in [Server-side key + /// backups](/client-server-api/#server-side-key-backups) for more + /// information on the expected format of the data. + QJsonObject authData() const + { + return loadFromJson("auth_data"_ls); + } + + /// The number of keys stored in the backup. + int count() const { return loadFromJson("count"_ls); } + + /// An opaque string representing stored keys in the backup. + /// Clients can compare it with the `etag` value they received + /// in the request of their last key storage request. If not + /// equal, another client has modified the backup. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The backup version. + QString version() const { return loadFromJson("version"_ls); } +}; + +/*! \brief Get information about an existing backup. + * + * Get information about an existing backup. + */ +class QUOTIENT_API GetRoomKeysVersionJob : public BaseJob { +public: + /*! \brief Get information about an existing backup. + * + * \param version + * The backup version to get, as returned in the `version` parameter + * of the response in + * [`POST + * /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion) + * or this endpoint. + */ + explicit GetRoomKeysVersionJob(const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetRoomKeysVersionJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& version); + + // Result properties + + /// The algorithm used for storing backups. + QString algorithm() const { return loadFromJson("algorithm"_ls); } + + /// Algorithm-dependent data. See the documentation for the backup + /// algorithms in [Server-side key + /// backups](/client-server-api/#server-side-key-backups) for more + /// information on the expected format of the data. + QJsonObject authData() const + { + return loadFromJson("auth_data"_ls); + } + + /// The number of keys stored in the backup. + int count() const { return loadFromJson("count"_ls); } + + /// An opaque string representing stored keys in the backup. + /// Clients can compare it with the `etag` value they received + /// in the request of their last key storage request. If not + /// equal, another client has modified the backup. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The backup version. + QString version() const { return loadFromJson("version"_ls); } +}; + +/*! \brief Update information about an existing backup. + * + * Update information about an existing backup. Only `auth_data` can be + * modified. + */ +class QUOTIENT_API PutRoomKeysVersionJob : public BaseJob { +public: + /*! \brief Update information about an existing backup. + * + * \param version + * The backup version to update, as returned in the `version` + * parameter in the response of + * [`POST + * /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion) + * or [`GET + * /_matrix/client/v3/room_keys/version/{version}`](/client-server-api/#get_matrixclientv3room_keysversionversion). + * + * \param algorithm + * The algorithm used for storing backups. Must be the same as + * the algorithm currently used by the backup. + * + * \param authData + * Algorithm-dependent data. See the documentation for the backup + * algorithms in [Server-side key + * backups](/client-server-api/#server-side-key-backups) for more + * information on the expected format of the data. + */ + explicit PutRoomKeysVersionJob(const QString& version, + const QString& algorithm, + const QJsonObject& authData); +}; + +/*! \brief Delete an existing key backup. + * + * Delete an existing key backup. Both the information about the backup, + * as well as all key data related to the backup will be deleted. + */ +class QUOTIENT_API DeleteRoomKeysVersionJob : public BaseJob { +public: + /*! \brief Delete an existing key backup. + * + * \param version + * The backup version to delete, as returned in the `version` + * parameter in the response of + * [`POST + * /_matrix/client/v3/room_keys/version`](/client-server-api/#post_matrixclientv3room_keysversion) + * or [`GET + * /_matrix/client/v3/room_keys/version/{version}`](/client-server-api/#get_matrixclientv3room_keysversionversion). + */ + explicit DeleteRoomKeysVersionJob(const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for DeleteRoomKeysVersionJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& version); +}; + +/*! \brief Store a key in the backup. + * + * Store a key in the backup. + */ +class QUOTIENT_API PutRoomKeyBySessionIdJob : public BaseJob { +public: + /*! \brief Store a key in the backup. + * + * \param roomId + * The ID of the room that the key is for. + * + * \param sessionId + * The ID of the megolm session that the key is for. + * + * \param version + * The backup in which to store the key. Must be the current backup. + * + * \param data + * The key data. + */ + explicit PutRoomKeyBySessionIdJob(const QString& roomId, + const QString& sessionId, + const QString& version, + const KeyBackupData& data); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +/*! \brief Retrieve a key from the backup. + * + * Retrieve a key from the backup. + */ +class QUOTIENT_API GetRoomKeyBySessionIdJob : public BaseJob { +public: + /*! \brief Retrieve a key from the backup. + * + * \param roomId + * The ID of the room that the requested key is for. + * + * \param sessionId + * The ID of the megolm session whose key is requested. + * + * \param version + * The backup from which to retrieve the key. + */ + explicit GetRoomKeyBySessionIdJob(const QString& roomId, + const QString& sessionId, + const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetRoomKeyBySessionIdJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& sessionId, const QString& version); + + // Result properties + + /// The key data + KeyBackupData data() const { return fromJson(jsonData()); } +}; + +/*! \brief Delete a key from the backup. + * + * Delete a key from the backup. + */ +class QUOTIENT_API DeleteRoomKeyBySessionIdJob : public BaseJob { +public: + /*! \brief Delete a key from the backup. + * + * \param roomId + * The ID of the room that the specified key is for. + * + * \param sessionId + * The ID of the megolm session whose key is to be deleted. + * + * \param version + * The backup from which to delete the key + */ + explicit DeleteRoomKeyBySessionIdJob(const QString& roomId, + const QString& sessionId, + const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for DeleteRoomKeyBySessionIdJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& sessionId, const QString& version); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +/*! \brief Store several keys in the backup for a given room. + * + * Store several keys in the backup for a given room. + */ +class QUOTIENT_API PutRoomKeysByRoomIdJob : public BaseJob { +public: + /*! \brief Store several keys in the backup for a given room. + * + * \param roomId + * The ID of the room that the keys are for. + * + * \param version + * The backup in which to store the keys. Must be the current backup. + * + * \param backupData + * The backup data + */ + explicit PutRoomKeysByRoomIdJob(const QString& roomId, + const QString& version, + const RoomKeyBackup& backupData); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +/*! \brief Retrieve the keys from the backup for a given room. + * + * Retrieve the keys from the backup for a given room. + */ +class QUOTIENT_API GetRoomKeysByRoomIdJob : public BaseJob { +public: + /*! \brief Retrieve the keys from the backup for a given room. + * + * \param roomId + * The ID of the room that the requested key is for. + * + * \param version + * The backup from which to retrieve the key. + */ + explicit GetRoomKeysByRoomIdJob(const QString& roomId, + const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetRoomKeysByRoomIdJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& version); + + // Result properties + + /// The key data. If no keys are found, then an object with an empty + /// `sessions` property will be returned (`{"sessions": {}}`). + RoomKeyBackup data() const { return fromJson(jsonData()); } +}; + +/*! \brief Delete the keys from the backup for a given room. + * + * Delete the keys from the backup for a given room. + */ +class QUOTIENT_API DeleteRoomKeysByRoomIdJob : public BaseJob { +public: + /*! \brief Delete the keys from the backup for a given room. + * + * \param roomId + * The ID of the room that the specified key is for. + * + * \param version + * The backup from which to delete the key. + */ + explicit DeleteRoomKeysByRoomIdJob(const QString& roomId, + const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for DeleteRoomKeysByRoomIdJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, + const QString& version); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +/*! \brief Store several keys in the backup. + * + * Store several keys in the backup. + */ +class QUOTIENT_API PutRoomKeysJob : public BaseJob { +public: + /*! \brief Store several keys in the backup. + * + * \param version + * The backup in which to store the keys. Must be the current backup. + * + * \param rooms + * A map of room IDs to room key backup data. + */ + explicit PutRoomKeysJob(const QString& version, + const QHash& rooms); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +/*! \brief Retrieve the keys from the backup. + * + * Retrieve the keys from the backup. + */ +class QUOTIENT_API GetRoomKeysJob : public BaseJob { +public: + /*! \brief Retrieve the keys from the backup. + * + * \param version + * The backup from which to retrieve the keys. + */ + explicit GetRoomKeysJob(const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for GetRoomKeysJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& version); + + // Result properties + + /// A map of room IDs to room key backup data. + QHash rooms() const + { + return loadFromJson>("rooms"_ls); + } +}; + +/*! \brief Delete the keys from the backup. + * + * Delete the keys from the backup. + */ +class QUOTIENT_API DeleteRoomKeysJob : public BaseJob { +public: + /*! \brief Delete the keys from the backup. + * + * \param version + * The backup from which to delete the key + */ + explicit DeleteRoomKeysJob(const QString& version); + + /*! \brief Construct a URL without creating a full-fledged job object + * + * This function can be used when a URL for DeleteRoomKeysJob + * is necessary but the job itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& version); + + // Result properties + + /// The new etag value representing stored keys in the backup. + /// See `GET /room_keys/version/{version}` for more details. + QString etag() const { return loadFromJson("etag"_ls); } + + /// The number of keys stored in the backup + int count() const { return loadFromJson("count"_ls); } +}; + +} // namespace Quotient