diff options
Diffstat (limited to 'lib/csapi')
-rw-r--r-- | lib/csapi/content-repo.cpp | 35 | ||||
-rw-r--r-- | lib/csapi/content-repo.h | 26 | ||||
-rw-r--r-- | lib/csapi/gtad.yaml | 1 | ||||
-rw-r--r-- | lib/csapi/joining.cpp | 12 | ||||
-rw-r--r-- | lib/csapi/joining.h | 2 | ||||
-rw-r--r-- | lib/csapi/login.cpp | 53 | ||||
-rw-r--r-- | lib/csapi/login.h | 37 | ||||
-rw-r--r-- | lib/csapi/presence.cpp | 2 |
8 files changed, 164 insertions, 4 deletions
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<double> 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<double> GetConfigJob::uploadSize() const +{ + return d->uploadSize; +} + +BaseJob::Status GetConfigJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->uploadSize = fromJson<double>(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<Private> 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<double> uploadSize() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> 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: <targetTypeSpec> 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<IfNotEmpty>(_q, QStringLiteral("server_name"), serverName); + return _q; +} + static const auto JoinRoomJobName = QStringLiteral("JoinRoomJob"); -JoinRoomJob::JoinRoomJob(const QString& roomIdOrAlias, const Omittable<ThirdPartySigned>& thirdPartySigned) +JoinRoomJob::JoinRoomJob(const QString& roomIdOrAlias, const QStringList& serverName, const Omittable<ThirdPartySigned>& 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>& thirdPartySigned = none); + explicit JoinRoomJob(const QString& roomIdOrAlias, const QStringList& serverName = {}, const Omittable<ThirdPartySigned>& 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> + { + GetLoginFlowsJob::LoginFlow operator()(const QJsonValue& jv) + { + const auto& _json = jv.toObject(); + GetLoginFlowsJob::LoginFlow result; + result.type = + fromJson<QString>(_json.value("type"_ls)); + + return result; + } + }; +} // namespace QMatrixClient + +class GetLoginFlowsJob::Private +{ + public: + QVector<LoginFlow> 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::LoginFlow>& GetLoginFlowsJob::flows() const +{ + return d->flows; +} + +BaseJob::Status GetLoginFlowsJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->flows = fromJson<QVector<LoginFlow>>(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 <QtCore/QVector> 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<LoginFlow>& flows() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> 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) { } |