From 3dd6b5e6cc50aafce74b21b5a0bf4b26a9fcf6ee Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 2 Jul 2018 17:58:34 +0900 Subject: Use QStringLiteral() and operator"" _ls() in network jobs --- lib/csapi/keys.cpp | 54 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 23 deletions(-) (limited to 'lib/csapi/keys.cpp') diff --git a/lib/csapi/keys.cpp b/lib/csapi/keys.cpp index 4a76b7e2..fac811d0 100644 --- a/lib/csapi/keys.cpp +++ b/lib/csapi/keys.cpp @@ -18,14 +18,16 @@ class UploadKeysJob::Private QHash oneTimeKeyCounts; }; +static const auto UploadKeysJobName = QStringLiteral("UploadKeysJob"); + UploadKeysJob::UploadKeysJob(const Omittable& deviceKeys, const QHash& oneTimeKeys) - : BaseJob(HttpVerb::Post, "UploadKeysJob", + : BaseJob(HttpVerb::Post, UploadKeysJobName, basePath % "/keys/upload") , d(new Private) { QJsonObject _data; - addParam(_data, "device_keys", deviceKeys); - addParam(_data, "one_time_keys", oneTimeKeys); + addParam(_data, QStringLiteral("device_keys"), deviceKeys); + addParam(_data, QStringLiteral("one_time_keys"), oneTimeKeys); setRequestData(_data); } @@ -39,10 +41,10 @@ const QHash& UploadKeysJob::oneTimeKeyCounts() const BaseJob::Status UploadKeysJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - if (!json.contains("one_time_key_counts")) + if (!json.contains("one_time_key_counts"_ls)) return { JsonParseError, "The key 'one_time_key_counts' not found in the response" }; - d->oneTimeKeyCounts = fromJson>(json.value("one_time_key_counts")); + d->oneTimeKeyCounts = fromJson>(json.value("one_time_key_counts"_ls)); return Success; } @@ -57,7 +59,7 @@ namespace QMatrixClient const auto& _json = jv.toObject(); QueryKeysJob::UnsignedDeviceInfo result; result.deviceDisplayName = - fromJson(_json.value("device_display_name")); + fromJson(_json.value("device_display_name"_ls)); return result; } @@ -70,7 +72,7 @@ namespace QMatrixClient const auto& _json = jv.toObject(); QueryKeysJob::DeviceInformation result; result.unsignedData = - fromJson(_json.value("unsigned")); + fromJson(_json.value("unsigned"_ls)); return result; } @@ -84,15 +86,17 @@ class QueryKeysJob::Private QHash> deviceKeys; }; +static const auto QueryKeysJobName = QStringLiteral("QueryKeysJob"); + QueryKeysJob::QueryKeysJob(const QHash& deviceKeys, Omittable timeout, const QString& token) - : BaseJob(HttpVerb::Post, "QueryKeysJob", + : BaseJob(HttpVerb::Post, QueryKeysJobName, basePath % "/keys/query") , d(new Private) { QJsonObject _data; - addParam(_data, "timeout", timeout); - addParam<>(_data, "device_keys", deviceKeys); - addParam(_data, "token", token); + addParam(_data, QStringLiteral("timeout"), timeout); + addParam<>(_data, QStringLiteral("device_keys"), deviceKeys); + addParam(_data, QStringLiteral("token"), token); setRequestData(_data); } @@ -111,8 +115,8 @@ const QHash>& QueryKeys BaseJob::Status QueryKeysJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->failures = fromJson>(json.value("failures")); - d->deviceKeys = fromJson>>(json.value("device_keys")); + d->failures = fromJson>(json.value("failures"_ls)); + d->deviceKeys = fromJson>>(json.value("device_keys"_ls)); return Success; } @@ -123,14 +127,16 @@ class ClaimKeysJob::Private QHash> oneTimeKeys; }; +static const auto ClaimKeysJobName = QStringLiteral("ClaimKeysJob"); + ClaimKeysJob::ClaimKeysJob(const QHash>& oneTimeKeys, Omittable timeout) - : BaseJob(HttpVerb::Post, "ClaimKeysJob", + : BaseJob(HttpVerb::Post, ClaimKeysJobName, basePath % "/keys/claim") , d(new Private) { QJsonObject _data; - addParam(_data, "timeout", timeout); - addParam<>(_data, "one_time_keys", oneTimeKeys); + addParam(_data, QStringLiteral("timeout"), timeout); + addParam<>(_data, QStringLiteral("one_time_keys"), oneTimeKeys); setRequestData(_data); } @@ -149,8 +155,8 @@ const QHash>& ClaimKeysJob::oneTimeKeys() cons 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")); + d->failures = fromJson>(json.value("failures"_ls)); + d->oneTimeKeys = fromJson>>(json.value("one_time_keys"_ls)); return Success; } @@ -164,8 +170,8 @@ class GetKeysChangesJob::Private BaseJob::Query queryToGetKeysChanges(const QString& from, const QString& to) { BaseJob::Query _q; - addParam<>(_q, "from", from); - addParam<>(_q, "to", to); + addParam<>(_q, QStringLiteral("from"), from); + addParam<>(_q, QStringLiteral("to"), to); return _q; } @@ -176,8 +182,10 @@ QUrl GetKeysChangesJob::makeRequestUrl(QUrl baseUrl, const QString& from, const queryToGetKeysChanges(from, to)); } +static const auto GetKeysChangesJobName = QStringLiteral("GetKeysChangesJob"); + GetKeysChangesJob::GetKeysChangesJob(const QString& from, const QString& to) - : BaseJob(HttpVerb::Get, "GetKeysChangesJob", + : BaseJob(HttpVerb::Get, GetKeysChangesJobName, basePath % "/keys/changes", queryToGetKeysChanges(from, to)) , d(new Private) @@ -199,8 +207,8 @@ const QStringList& GetKeysChangesJob::left() const BaseJob::Status GetKeysChangesJob::parseJson(const QJsonDocument& data) { auto json = data.object(); - d->changed = fromJson(json.value("changed")); - d->left = fromJson(json.value("left")); + d->changed = fromJson(json.value("changed"_ls)); + d->left = fromJson(json.value("left"_ls)); return Success; } -- cgit v1.2.3