From 1c83d54f705ad786e4a27aaab94e3a0af725a07c Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 12 Feb 2019 15:58:19 +0900 Subject: Omittable: disallow implicit conversion to value_type altogether Because it works, and fails, in surprising ways. And none of the code uses it, as of now. --- lib/util.h | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/util.h b/lib/util.h index 420b0984..596872e2 100644 --- a/lib/util.h +++ b/lib/util.h @@ -159,7 +159,6 @@ namespace QMatrixClient } value_type&& release() { _omitted = true; return std::move(_value); } - operator const value_type&() const & { return value(); } const value_type* operator->() const & { return &value(); } value_type* operator->() & { return &editValue(); } const value_type& operator*() const & { return value(); } -- cgit v1.2.3 From 52dcb27e1c19389bd833c93609910483ea3be549 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 12 Feb 2019 07:55:15 +0900 Subject: RoomVersionsCapability: fix naming for 'default' parameter The same word is used as a predicate in push_rule.yaml and as a noun in capabilities.yaml; fortunately, GTAD gives some means to distinguish the two. --- lib/csapi/capabilities.cpp | 2 +- lib/csapi/capabilities.h | 2 +- lib/csapi/gtad.yaml | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/csapi/capabilities.cpp b/lib/csapi/capabilities.cpp index a8e79f6b..bd92cf25 100644 --- a/lib/csapi/capabilities.cpp +++ b/lib/csapi/capabilities.cpp @@ -28,7 +28,7 @@ namespace QMatrixClient { static void fillFrom(const QJsonObject& jo, GetCapabilitiesJob::RoomVersionsCapability& result) { - fromJson(jo.value("default"_ls), result.isDefault); + fromJson(jo.value("default"_ls), result.defaultVersion); fromJson(jo.value("available"_ls), result.available); } }; diff --git a/lib/csapi/capabilities.h b/lib/csapi/capabilities.h index e38483bc..40a2e6f7 100644 --- a/lib/csapi/capabilities.h +++ b/lib/csapi/capabilities.h @@ -33,7 +33,7 @@ namespace QMatrixClient struct RoomVersionsCapability { /// The default room version the server is using for new rooms. - QString isDefault; + QString defaultVersion; /// A detailed description of the room versions the server supports. QHash available; }; diff --git a/lib/csapi/gtad.yaml b/lib/csapi/gtad.yaml index 21a59a5c..a44f803a 100644 --- a/lib/csapi/gtad.yaml +++ b/lib/csapi/gtad.yaml @@ -5,7 +5,8 @@ analyzer: identifiers: signed: signedData unsigned: unsignedData - default: isDefault + PushRule/default: isDefault + default: defaultVersion # getCapabilities/RoomVersionsCapability origin_server_ts: originServerTimestamp # Instead of originServerTs start: begin # Because start() is a method in BaseJob m.upload.size: uploadSize -- cgit v1.2.3 From a2d9a7b865bfd93386844270849ab72b36a86fbe Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 12 Feb 2019 16:50:36 +0900 Subject: csapi/capabilities.*: fix the definition As per https://github.com/matrix-org/matrix-doc/pull/1879. --- lib/csapi/capabilities.cpp | 28 +++++++++++++++++----------- lib/csapi/capabilities.h | 21 +++++++++++++++++---- 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 + { + 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 changePassword; - Omittable roomVersions; + Capabilities capabilities; }; QUrl GetCapabilitiesJob::makeRequestUrl(QUrl baseUrl) @@ -58,21 +67,18 @@ GetCapabilitiesJob::GetCapabilitiesJob() GetCapabilitiesJob::~GetCapabilitiesJob() = default; -const Omittable& GetCapabilitiesJob::changePassword() const -{ - return d->changePassword; -} - -const Omittable& 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 #include "converters.h" #include @@ -38,6 +39,19 @@ namespace QMatrixClient QHash 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 changePassword; + /// The room versions the server supports. + Omittable roomVersions; + /// The custom capabilities the server supports, using the + /// Java package naming convention. + QHash 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& changePassword() const; - /// The room versions the server supports. - const Omittable& 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; -- cgit v1.2.3