/****************************************************************************** * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN */ #include "keys.h" #include "converters.h" #include using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); class UploadKeysJob::Private { public: QHash oneTimeKeyCounts; }; UploadKeysJob::UploadKeysJob(const Omittable& deviceKeys, const QHash& oneTimeKeys) : BaseJob(HttpVerb::Post, "UploadKeysJob", basePath % "/keys/upload") , d(new Private) { QJsonObject _data; addToJson(_data, "device_keys", deviceKeys); addToJson(_data, "one_time_keys", oneTimeKeys); setRequestData(_data); } UploadKeysJob::~UploadKeysJob() = default; const QHash& UploadKeysJob::oneTimeKeyCounts() const { return d->oneTimeKeyCounts; } BaseJob::Status UploadKeysJob::parseJson(const QJsonDocument& data) { auto json = data.object(); if (!json.contains("one_time_key_counts")) return { JsonParseError, "The key 'one_time_key_counts' not found in the response" }; d->oneTimeKeyCounts = fromJson>(json.value("one_time_key_counts")); return Success; } namespace QMatrixClient { // Converters template <> struct FromJson { QueryKeysJob::UnsignedDeviceInfo operator()(const QJsonValue& jv) { const auto& _json = jv.toObject(); QueryKeysJob::UnsignedDeviceInfo result; result.deviceDisplayName = fromJson(_json.value("device_display_name")); return result; } }; template <> struct FromJson { QueryKeysJob::DeviceInformation operator()(const QJsonValue& jv) { const auto& _json = jv.toObject(); QueryKeysJob::DeviceInformation result; result.unsignedData = fromJson(_json.value("unsigned")); return result; } }; } // namespace QMatrixClient class QueryKeysJob::Private { public: QHash failures; QHash> deviceKeys; }; QueryKeysJob::QueryKeysJob(const QHash& deviceKeys, Omittable timeout, const QString& token) : BaseJob(HttpVerb::Post, "QueryKeysJob", basePath % "/keys/query") , d(new Private) { QJsonObject _data; addToJson(_data, "timeout", timeout); addToJson<>(_data, "device_keys", deviceKeys); addToJson(_data, "token", token); setRequestData(_data); } QueryKeysJob::~QueryKeysJob() = default; const QHash& QueryKeysJob::failures() const { return d->failures; } const QHash>& QueryKeysJob::deviceKeys() const { return d->deviceKeys; } BaseJob::Status QueryKeysJob::parseJson(const QJsonDocument& data) { auto json = data.object(); d->failures = fromJson>(json.value("failures")); d->deviceKeys = fromJson>>(json.value("device_keys")); return Success; } class ClaimKeysJob::Private { public: QHash failures; QHash> oneTimeKeys; }; ClaimKeysJob::ClaimKeysJob(const QHash>& oneTimeKeys, Omittable timeout) : BaseJob(HttpVerb::Post, "ClaimKeysJob", basePath % "/keys/claim") , d(new Private) { QJsonObject _data; addToJson(_data, "timeout", timeout); addToJson<>(_data, "one_time_keys", oneTimeKeys); setRequestData(_data); } ClaimKeysJob::~ClaimKeysJob() = default; const QHash& ClaimKeysJob::failures() const { return d->failures; } const QHash>& ClaimKeysJob::oneTimeKeys() const { return d->oneTimeKeys; } BaseJob::Status ClaimKeysJob::parseJson(const QJsonDocument& data) { auto json = data.object(); d->failures = fromJson>(json.value("failures")); d->oneTimeKeys = fromJson>>(json.value("one_time_keys")); return Success; } class GetKeysChangesJob::Private { public: QStringList changed; QStringList left; }; BaseJob::Query queryToGetKeysChanges(const QString& from, const QString& to) { BaseJob::Query _q; addToQuery<>(_q, "from", from); addToQuery<>(_q, "to", to); return _q; } QUrl GetKeysChangesJob::makeRequestUrl(QUrl baseUrl, const QString& from, const QString& to) { return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/keys/changes", queryToGetKeysChanges(from, to)); } GetKeysChangesJob::GetKeysChangesJob(const QString& from, const QString& to) : BaseJob(HttpVerb::Get, "GetKeysChangesJob", basePath % "/keys/changes", queryToGetKeysChanges(from, to)) , d(new Private) { } GetKeysChangesJob::~GetKeysChangesJob() = default; const QStringList& GetKeysChangesJob::changed() const { return d->changed; } const QStringList& GetKeysChangesJob::left() const { return d->left; } BaseJob::Status GetKeysChangesJob::parseJson(const QJsonDocument& data) { auto json = data.object(); d->changed = fromJson(json.value("changed")); d->left = fromJson(json.value("left")); return Success; }