From 606db144b9ef6f1b2958ff49c4a6860bff48090c Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 11 Jul 2018 18:34:41 +0900 Subject: csapi: Update to the latest API definitions Presence requires authentication; GetConfigJob; GetLoginFlowsJob; serverName parameter in JoinRoomJob. --- lib/csapi/content-repo.cpp | 35 ++++++++++++++++++++++++++++++ lib/csapi/content-repo.h | 26 +++++++++++++++++++++++ lib/csapi/gtad.yaml | 1 + lib/csapi/joining.cpp | 12 +++++++++-- lib/csapi/joining.h | 2 +- lib/csapi/login.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++ lib/csapi/login.h | 37 ++++++++++++++++++++++++++++++++ lib/csapi/presence.cpp | 2 +- 8 files changed, 164 insertions(+), 4 deletions(-) (limited to 'lib/csapi') diff --git a/lib/csapi/content-repo.cpp b/lib/csapi/content-repo.cpp index 9ac226ba..f686683c 100644 --- a/lib/csapi/content-repo.cpp +++ b/lib/csapi/content-repo.cpp @@ -281,3 +281,38 @@ BaseJob::Status GetUrlPreviewJob::parseJson(const QJsonDocument& data) return Success; } +class GetConfigJob::Private +{ + public: + Omittable uploadSize; +}; + +QUrl GetConfigJob::makeRequestUrl(QUrl baseUrl) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/config"); +} + +static const auto GetConfigJobName = QStringLiteral("GetConfigJob"); + +GetConfigJob::GetConfigJob() + : BaseJob(HttpVerb::Get, GetConfigJobName, + basePath % "/config") + , d(new Private) +{ +} + +GetConfigJob::~GetConfigJob() = default; + +Omittable GetConfigJob::uploadSize() const +{ + return d->uploadSize; +} + +BaseJob::Status GetConfigJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->uploadSize = fromJson(json.value("m.upload.size"_ls)); + return Success; +} + diff --git a/lib/csapi/content-repo.h b/lib/csapi/content-repo.h index 0883c776..6a871893 100644 --- a/lib/csapi/content-repo.h +++ b/lib/csapi/content-repo.h @@ -140,4 +140,30 @@ namespace QMatrixClient class Private; QScopedPointer d; }; + + class GetConfigJob : public BaseJob + { + public: + explicit GetConfigJob(); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetConfigJob. This function can be used when + * a URL for GetConfigJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl); + + ~GetConfigJob() override; + + // Result properties + + Omittable uploadSize() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer d; + }; } // namespace QMatrixClient diff --git a/lib/csapi/gtad.yaml b/lib/csapi/gtad.yaml index 09344be5..b480e67a 100644 --- a/lib/csapi/gtad.yaml +++ b/lib/csapi/gtad.yaml @@ -8,6 +8,7 @@ analyzer: default: isDefault origin_server_ts: originServerTimestamp # Instead of originServerTs start: begin # Because start() is a method in BaseJob + m.upload.size: uploadSize # Structure inside `types`: # - swaggerType: diff --git a/lib/csapi/joining.cpp b/lib/csapi/joining.cpp index 0a4618af..1a29ac62 100644 --- a/lib/csapi/joining.cpp +++ b/lib/csapi/joining.cpp @@ -90,11 +90,19 @@ class JoinRoomJob::Private QString roomId; }; +BaseJob::Query queryToJoinRoom(const QStringList& serverName) +{ + BaseJob::Query _q; + addParam(_q, QStringLiteral("server_name"), serverName); + return _q; +} + static const auto JoinRoomJobName = QStringLiteral("JoinRoomJob"); -JoinRoomJob::JoinRoomJob(const QString& roomIdOrAlias, const Omittable& thirdPartySigned) +JoinRoomJob::JoinRoomJob(const QString& roomIdOrAlias, const QStringList& serverName, const Omittable& thirdPartySigned) : BaseJob(HttpVerb::Post, JoinRoomJobName, - basePath % "/join/" % roomIdOrAlias) + basePath % "/join/" % roomIdOrAlias, + queryToJoinRoom(serverName)) , d(new Private) { QJsonObject _data; diff --git a/lib/csapi/joining.h b/lib/csapi/joining.h index 7742a0a5..7164f9ff 100644 --- a/lib/csapi/joining.h +++ b/lib/csapi/joining.h @@ -63,7 +63,7 @@ namespace QMatrixClient // Construction/destruction - explicit JoinRoomJob(const QString& roomIdOrAlias, const Omittable& thirdPartySigned = none); + explicit JoinRoomJob(const QString& roomIdOrAlias, const QStringList& serverName = {}, const Omittable& thirdPartySigned = none); ~JoinRoomJob() override; // Result properties diff --git a/lib/csapi/login.cpp b/lib/csapi/login.cpp index b8734d05..3956a1c4 100644 --- a/lib/csapi/login.cpp +++ b/lib/csapi/login.cpp @@ -12,6 +12,59 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); +namespace QMatrixClient +{ + // Converters + + template <> struct FromJson + { + GetLoginFlowsJob::LoginFlow operator()(const QJsonValue& jv) + { + const auto& _json = jv.toObject(); + GetLoginFlowsJob::LoginFlow result; + result.type = + fromJson(_json.value("type"_ls)); + + return result; + } + }; +} // namespace QMatrixClient + +class GetLoginFlowsJob::Private +{ + public: + QVector flows; +}; + +QUrl GetLoginFlowsJob::makeRequestUrl(QUrl baseUrl) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/login"); +} + +static const auto GetLoginFlowsJobName = QStringLiteral("GetLoginFlowsJob"); + +GetLoginFlowsJob::GetLoginFlowsJob() + : BaseJob(HttpVerb::Get, GetLoginFlowsJobName, + basePath % "/login", false) + , d(new Private) +{ +} + +GetLoginFlowsJob::~GetLoginFlowsJob() = default; + +const QVector& GetLoginFlowsJob::flows() const +{ + return d->flows; +} + +BaseJob::Status GetLoginFlowsJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->flows = fromJson>(json.value("flows"_ls)); + return Success; +} + class LoginJob::Private { public: diff --git a/lib/csapi/login.h b/lib/csapi/login.h index f30bef57..6e462aeb 100644 --- a/lib/csapi/login.h +++ b/lib/csapi/login.h @@ -6,11 +6,48 @@ #include "jobs/basejob.h" +#include "converters.h" +#include namespace QMatrixClient { // Operations + class GetLoginFlowsJob : public BaseJob + { + public: + // Inner data structures + + struct LoginFlow + { + QString type; + }; + + // Construction/destruction + + explicit GetLoginFlowsJob(); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetLoginFlowsJob. This function can be used when + * a URL for GetLoginFlowsJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl); + + ~GetLoginFlowsJob() override; + + // Result properties + + const QVector& flows() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer d; + }; + class LoginJob : public BaseJob { public: diff --git a/lib/csapi/presence.cpp b/lib/csapi/presence.cpp index 66827163..ca4c850e 100644 --- a/lib/csapi/presence.cpp +++ b/lib/csapi/presence.cpp @@ -43,7 +43,7 @@ static const auto GetPresenceJobName = QStringLiteral("GetPresenceJob"); GetPresenceJob::GetPresenceJob(const QString& userId) : BaseJob(HttpVerb::Get, GetPresenceJobName, - basePath % "/presence/" % userId % "/status", false) + basePath % "/presence/" % userId % "/status") , d(new Private) { } -- cgit v1.2.3