aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-02-12 16:50:36 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-02-15 07:47:14 +0900
commita2d9a7b865bfd93386844270849ab72b36a86fbe (patch)
tree291310304bc3039606b37665d4e11f373d151058 /lib
parent52dcb27e1c19389bd833c93609910483ea3be549 (diff)
downloadlibquotient-a2d9a7b865bfd93386844270849ab72b36a86fbe.tar.gz
libquotient-a2d9a7b865bfd93386844270849ab72b36a86fbe.zip
csapi/capabilities.*: fix the definition
As per https://github.com/matrix-org/matrix-doc/pull/1879.
Diffstat (limited to 'lib')
-rw-r--r--lib/csapi/capabilities.cpp28
-rw-r--r--lib/csapi/capabilities.h21
2 files changed, 34 insertions, 15 deletions
diff --git a/lib/csapi/capabilities.cpp b/lib/csapi/capabilities.cpp
index bd92cf25..210423f5 100644
--- a/lib/csapi/capabilities.cpp
+++ b/lib/csapi/capabilities.cpp
@@ -32,13 +32,22 @@ namespace QMatrixClient
fromJson(jo.value("available"_ls), result.available);
}
};
+
+ template <> struct JsonObjectConverter<GetCapabilitiesJob::Capabilities>
+ {
+ static void fillFrom(QJsonObject jo, GetCapabilitiesJob::Capabilities& result)
+ {
+ fromJson(jo.take("m.change_password"_ls), result.changePassword);
+ fromJson(jo.take("m.room_versions"_ls), result.roomVersions);
+ fromJson(jo, result.additionalProperties);
+ }
+ };
} // namespace QMatrixClient
class GetCapabilitiesJob::Private
{
public:
- Omittable<ChangePasswordCapability> changePassword;
- Omittable<RoomVersionsCapability> roomVersions;
+ Capabilities capabilities;
};
QUrl GetCapabilitiesJob::makeRequestUrl(QUrl baseUrl)
@@ -58,21 +67,18 @@ GetCapabilitiesJob::GetCapabilitiesJob()
GetCapabilitiesJob::~GetCapabilitiesJob() = default;
-const Omittable<GetCapabilitiesJob::ChangePasswordCapability>& GetCapabilitiesJob::changePassword() const
-{
- return d->changePassword;
-}
-
-const Omittable<GetCapabilitiesJob::RoomVersionsCapability>& GetCapabilitiesJob::roomVersions() const
+const GetCapabilitiesJob::Capabilities& GetCapabilitiesJob::capabilities() const
{
- return d->roomVersions;
+ return d->capabilities;
}
BaseJob::Status GetCapabilitiesJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
- fromJson(json.value("m.change_password"_ls), d->changePassword);
- fromJson(json.value("m.room_versions"_ls), d->roomVersions);
+ if (!json.contains("capabilities"_ls))
+ return { JsonParseError,
+ "The key 'capabilities' not found in the response" };
+ fromJson(json.value("capabilities"_ls), d->capabilities);
return Success;
}
diff --git a/lib/csapi/capabilities.h b/lib/csapi/capabilities.h
index 40a2e6f7..39e2f4d1 100644
--- a/lib/csapi/capabilities.h
+++ b/lib/csapi/capabilities.h
@@ -6,6 +6,7 @@
#include "jobs/basejob.h"
+#include <QtCore/QJsonObject>
#include "converters.h"
#include <QtCore/QHash>
@@ -38,6 +39,19 @@ namespace QMatrixClient
QHash<QString, QString> available;
};
+ /// Gets information about the server's supported feature set
+ /// and other relevant capabilities.
+ struct Capabilities
+ {
+ /// Capability to indicate if the user can change their password.
+ Omittable<ChangePasswordCapability> changePassword;
+ /// The room versions the server supports.
+ Omittable<RoomVersionsCapability> roomVersions;
+ /// The custom capabilities the server supports, using the
+ /// Java package naming convention.
+ QHash<QString, QJsonObject> additionalProperties;
+ };
+
// Construction/destruction
explicit GetCapabilitiesJob();
@@ -54,10 +68,9 @@ namespace QMatrixClient
// Result properties
- /// Capability to indicate if the user can change their password.
- const Omittable<ChangePasswordCapability>& changePassword() const;
- /// The room versions the server supports.
- const Omittable<RoomVersionsCapability>& roomVersions() const;
+ /// Gets information about the server's supported feature set
+ /// and other relevant capabilities.
+ const Capabilities& capabilities() const;
protected:
Status parseJson(const QJsonDocument& data) override;