aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi/keys.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csapi/keys.cpp')
-rw-r--r--lib/csapi/keys.cpp115
1 files changed, 59 insertions, 56 deletions
diff --git a/lib/csapi/keys.cpp b/lib/csapi/keys.cpp
index 5bbc1aab..cd33ad19 100644
--- a/lib/csapi/keys.cpp
+++ b/lib/csapi/keys.cpp
@@ -8,21 +8,21 @@
#include <QtCore/QStringBuilder>
-using namespace QMatrixClient;
+using namespace Quotient;
static const auto basePath = QStringLiteral("/_matrix/client/r0");
class UploadKeysJob::Private
{
- public:
- QHash<QString, int> oneTimeKeyCounts;
+public:
+ QHash<QString, int> oneTimeKeyCounts;
};
static const auto UploadKeysJobName = QStringLiteral("UploadKeysJob");
-UploadKeysJob::UploadKeysJob(const Omittable<DeviceKeys>& deviceKeys, const QHash<QString, QVariant>& oneTimeKeys)
- : BaseJob(HttpVerb::Post, UploadKeysJobName,
- basePath % "/keys/upload")
+UploadKeysJob::UploadKeysJob(const Omittable<DeviceKeys>& deviceKeys,
+ const QHash<QString, QVariant>& oneTimeKeys)
+ : BaseJob(HttpVerb::Post, UploadKeysJobName, basePath % "/keys/upload")
, d(new Private)
{
QJsonObject _data;
@@ -43,45 +43,51 @@ BaseJob::Status UploadKeysJob::parseJson(const QJsonDocument& data)
auto json = data.object();
if (!json.contains("one_time_key_counts"_ls))
return { IncorrectResponse,
- "The key 'one_time_key_counts' not found in the response" };
+ "The key 'one_time_key_counts' not found in the response" };
fromJson(json.value("one_time_key_counts"_ls), d->oneTimeKeyCounts);
+
return Success;
}
-namespace QMatrixClient
+// Converters
+namespace Quotient
{
- // Converters
- template <> struct JsonObjectConverter<QueryKeysJob::UnsignedDeviceInfo>
+template <>
+struct JsonObjectConverter<QueryKeysJob::UnsignedDeviceInfo>
+{
+ static void fillFrom(const QJsonObject& jo,
+ QueryKeysJob::UnsignedDeviceInfo& result)
{
- static void fillFrom(const QJsonObject& jo, QueryKeysJob::UnsignedDeviceInfo& result)
- {
- fromJson(jo.value("device_display_name"_ls), result.deviceDisplayName);
- }
- };
+ fromJson(jo.value("device_display_name"_ls), result.deviceDisplayName);
+ }
+};
- template <> struct JsonObjectConverter<QueryKeysJob::DeviceInformation>
+template <>
+struct JsonObjectConverter<QueryKeysJob::DeviceInformation>
+{
+ static void fillFrom(const QJsonObject& jo,
+ QueryKeysJob::DeviceInformation& result)
{
- static void fillFrom(const QJsonObject& jo, QueryKeysJob::DeviceInformation& result)
- {
- fillFromJson<DeviceKeys>(jo, result);
- fromJson(jo.value("unsigned"_ls), result.unsignedData);
- }
- };
-} // namespace QMatrixClient
+ fillFromJson<DeviceKeys>(jo, result);
+ fromJson(jo.value("unsigned"_ls), result.unsignedData);
+ }
+};
+
+} // namespace Quotient
class QueryKeysJob::Private
{
- public:
- QHash<QString, QJsonObject> failures;
- QHash<QString, QHash<QString, DeviceInformation>> deviceKeys;
+public:
+ QHash<QString, QJsonObject> failures;
+ QHash<QString, QHash<QString, DeviceInformation>> deviceKeys;
};
static const auto QueryKeysJobName = QStringLiteral("QueryKeysJob");
-QueryKeysJob::QueryKeysJob(const QHash<QString, QStringList>& deviceKeys, Omittable<int> timeout, const QString& token)
- : BaseJob(HttpVerb::Post, QueryKeysJobName,
- basePath % "/keys/query")
+QueryKeysJob::QueryKeysJob(const QHash<QString, QStringList>& deviceKeys,
+ Omittable<int> timeout, const QString& token)
+ : BaseJob(HttpVerb::Post, QueryKeysJobName, basePath % "/keys/query")
, d(new Private)
{
QJsonObject _data;
@@ -98,7 +104,8 @@ const QHash<QString, QJsonObject>& QueryKeysJob::failures() const
return d->failures;
}
-const QHash<QString, QHash<QString, QueryKeysJob::DeviceInformation>>& QueryKeysJob::deviceKeys() const
+const QHash<QString, QHash<QString, QueryKeysJob::DeviceInformation>>&
+QueryKeysJob::deviceKeys() const
{
return d->deviceKeys;
}
@@ -108,21 +115,23 @@ BaseJob::Status QueryKeysJob::parseJson(const QJsonDocument& data)
auto json = data.object();
fromJson(json.value("failures"_ls), d->failures);
fromJson(json.value("device_keys"_ls), d->deviceKeys);
+
return Success;
}
class ClaimKeysJob::Private
{
- public:
- QHash<QString, QJsonObject> failures;
- QHash<QString, QHash<QString, QVariant>> oneTimeKeys;
+public:
+ QHash<QString, QJsonObject> failures;
+ QHash<QString, QHash<QString, QVariant>> oneTimeKeys;
};
static const auto ClaimKeysJobName = QStringLiteral("ClaimKeysJob");
-ClaimKeysJob::ClaimKeysJob(const QHash<QString, QHash<QString, QString>>& oneTimeKeys, Omittable<int> timeout)
- : BaseJob(HttpVerb::Post, ClaimKeysJobName,
- basePath % "/keys/claim")
+ClaimKeysJob::ClaimKeysJob(
+ const QHash<QString, QHash<QString, QString>>& oneTimeKeys,
+ Omittable<int> timeout)
+ : BaseJob(HttpVerb::Post, ClaimKeysJobName, basePath % "/keys/claim")
, d(new Private)
{
QJsonObject _data;
@@ -148,14 +157,15 @@ BaseJob::Status ClaimKeysJob::parseJson(const QJsonDocument& data)
auto json = data.object();
fromJson(json.value("failures"_ls), d->failures);
fromJson(json.value("one_time_keys"_ls), d->oneTimeKeys);
+
return Success;
}
class GetKeysChangesJob::Private
{
- public:
- QStringList changed;
- QStringList left;
+public:
+ QStringList changed;
+ QStringList left;
};
BaseJob::Query queryToGetKeysChanges(const QString& from, const QString& to)
@@ -166,40 +176,33 @@ BaseJob::Query queryToGetKeysChanges(const QString& from, const QString& to)
return _q;
}
-QUrl GetKeysChangesJob::makeRequestUrl(QUrl baseUrl, const QString& from, const QString& to)
+QUrl GetKeysChangesJob::makeRequestUrl(QUrl baseUrl, const QString& from,
+ const QString& to)
{
return BaseJob::makeRequestUrl(std::move(baseUrl),
- basePath % "/keys/changes",
- queryToGetKeysChanges(from, to));
+ basePath % "/keys/changes",
+ queryToGetKeysChanges(from, to));
}
static const auto GetKeysChangesJobName = QStringLiteral("GetKeysChangesJob");
GetKeysChangesJob::GetKeysChangesJob(const QString& from, const QString& to)
- : BaseJob(HttpVerb::Get, GetKeysChangesJobName,
- basePath % "/keys/changes",
- queryToGetKeysChanges(from, to))
+ : BaseJob(HttpVerb::Get, GetKeysChangesJobName, basePath % "/keys/changes",
+ queryToGetKeysChanges(from, to))
, d(new Private)
-{
-}
+{}
GetKeysChangesJob::~GetKeysChangesJob() = default;
-const QStringList& GetKeysChangesJob::changed() const
-{
- return d->changed;
-}
+const QStringList& GetKeysChangesJob::changed() const { return d->changed; }
-const QStringList& GetKeysChangesJob::left() const
-{
- return d->left;
-}
+const QStringList& GetKeysChangesJob::left() const { return d->left; }
BaseJob::Status GetKeysChangesJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
fromJson(json.value("changed"_ls), d->changed);
fromJson(json.value("left"_ls), d->left);
+
return Success;
}
-