diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-05 19:36:15 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-05-05 19:36:15 +0900 |
commit | a8d2a73c771f188fc0fdc6351b4923af788317d5 (patch) | |
tree | b2795b93149f7c0ae3cd5005331b650a8eb6fd1e /lib/jobs | |
parent | da16225dfbec9b155c2c299757203f7676ac6ccf (diff) | |
parent | a63838235134b066c092ad98e1f18ff7991c91c1 (diff) | |
download | libquotient-a8d2a73c771f188fc0fdc6351b4923af788317d5.tar.gz libquotient-a8d2a73c771f188fc0fdc6351b4923af788317d5.zip |
Merge branch 'kitsune-gtad'
Diffstat (limited to 'lib/jobs')
52 files changed, 30 insertions, 2829 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp index 56565859..2d41650a 100644 --- a/lib/jobs/basejob.cpp +++ b/lib/jobs/basejob.cpp @@ -25,7 +25,6 @@ #include <QtNetwork/QNetworkReply> #include <QtCore/QTimer> #include <QtCore/QRegularExpression> -//#include <QtCore/QStringBuilder> #include <array> diff --git a/lib/jobs/downloadfilejob.h b/lib/jobs/downloadfilejob.h index 1815a7c8..ce47ab1c 100644 --- a/lib/jobs/downloadfilejob.h +++ b/lib/jobs/downloadfilejob.h @@ -1,6 +1,6 @@ #pragma once -#include "generated/content-repo.h" +#include "csapi/content-repo.h" namespace QMatrixClient { diff --git a/lib/jobs/generated/account-data.cpp b/lib/jobs/generated/account-data.cpp deleted file mode 100644 index 35ee94c0..00000000 --- a/lib/jobs/generated/account-data.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "account-data.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -SetAccountDataJob::SetAccountDataJob(const QString& userId, const QString& type, const QJsonObject& content) - : BaseJob(HttpVerb::Put, "SetAccountDataJob", - basePath % "/user/" % userId % "/account_data/" % type) -{ - setRequestData(Data(content)); -} - -SetAccountDataPerRoomJob::SetAccountDataPerRoomJob(const QString& userId, const QString& roomId, const QString& type, const QJsonObject& content) - : BaseJob(HttpVerb::Put, "SetAccountDataPerRoomJob", - basePath % "/user/" % userId % "/rooms/" % roomId % "/account_data/" % type) -{ - setRequestData(Data(content)); -} - diff --git a/lib/jobs/generated/account-data.h b/lib/jobs/generated/account-data.h deleted file mode 100644 index 69ad9fb4..00000000 --- a/lib/jobs/generated/account-data.h +++ /dev/null @@ -1,27 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - -#include <QtCore/QJsonObject> - - -namespace QMatrixClient -{ - // Operations - - class SetAccountDataJob : public BaseJob - { - public: - explicit SetAccountDataJob(const QString& userId, const QString& type, const QJsonObject& content = {}); - }; - - class SetAccountDataPerRoomJob : public BaseJob - { - public: - explicit SetAccountDataPerRoomJob(const QString& userId, const QString& roomId, const QString& type, const QJsonObject& content = {}); - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/administrative_contact.cpp b/lib/jobs/generated/administrative_contact.cpp deleted file mode 100644 index bd74490c..00000000 --- a/lib/jobs/generated/administrative_contact.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "administrative_contact.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -GetAccount3PIDsJob::ThirdPartyIdentifier::operator QJsonObject() const -{ - QJsonObject o; - o.insert("medium", toJson(medium)); - o.insert("address", toJson(address)); - - return o; -} -namespace QMatrixClient -{ - template <> struct FromJson<GetAccount3PIDsJob::ThirdPartyIdentifier> - { - GetAccount3PIDsJob::ThirdPartyIdentifier operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - GetAccount3PIDsJob::ThirdPartyIdentifier result; - result.medium = - fromJson<QString>(o.value("medium")); - result.address = - fromJson<QString>(o.value("address")); - - return result; - } - }; -} // namespace QMatrixClient - -class GetAccount3PIDsJob::Private -{ - public: - QVector<ThirdPartyIdentifier> threepids; -}; - -QUrl GetAccount3PIDsJob::makeRequestUrl(QUrl baseUrl) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/account/3pid"); -} - -GetAccount3PIDsJob::GetAccount3PIDsJob() - : BaseJob(HttpVerb::Get, "GetAccount3PIDsJob", - basePath % "/account/3pid") - , d(new Private) -{ -} - -GetAccount3PIDsJob::~GetAccount3PIDsJob() = default; - -const QVector<GetAccount3PIDsJob::ThirdPartyIdentifier>& GetAccount3PIDsJob::threepids() const -{ - return d->threepids; -} - -BaseJob::Status GetAccount3PIDsJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->threepids = fromJson<QVector<ThirdPartyIdentifier>>(json.value("threepids")); - return Success; -} - -Post3PIDsJob::ThreePidCredentials::operator QJsonObject() const -{ - QJsonObject o; - o.insert("client_secret", toJson(clientSecret)); - o.insert("id_server", toJson(idServer)); - o.insert("sid", toJson(sid)); - - return o; -} -namespace QMatrixClient -{ - template <> struct FromJson<Post3PIDsJob::ThreePidCredentials> - { - Post3PIDsJob::ThreePidCredentials operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - Post3PIDsJob::ThreePidCredentials result; - result.clientSecret = - fromJson<QString>(o.value("client_secret")); - result.idServer = - fromJson<QString>(o.value("id_server")); - result.sid = - fromJson<QString>(o.value("sid")); - - return result; - } - }; -} // namespace QMatrixClient - -Post3PIDsJob::Post3PIDsJob(const ThreePidCredentials& threePidCreds, bool bind) - : BaseJob(HttpVerb::Post, "Post3PIDsJob", - basePath % "/account/3pid") -{ - QJsonObject _data; - _data.insert("three_pid_creds", toJson(threePidCreds)); - _data.insert("bind", toJson(bind)); - setRequestData(_data); -} - -QUrl RequestTokenTo3PIDJob::makeRequestUrl(QUrl baseUrl) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/account/3pid/email/requestToken"); -} - -RequestTokenTo3PIDJob::RequestTokenTo3PIDJob() - : BaseJob(HttpVerb::Post, "RequestTokenTo3PIDJob", - basePath % "/account/3pid/email/requestToken", false) -{ -} - diff --git a/lib/jobs/generated/administrative_contact.h b/lib/jobs/generated/administrative_contact.h deleted file mode 100644 index c8429d39..00000000 --- a/lib/jobs/generated/administrative_contact.h +++ /dev/null @@ -1,83 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - -#include <QtCore/QVector> - -#include "converters.h" - -namespace QMatrixClient -{ - // Operations - - class GetAccount3PIDsJob : public BaseJob - { - public: - // Inner data structures - - struct ThirdPartyIdentifier - { - QString medium; - QString address; - - operator QJsonObject() const; - }; - - // End of inner data structures - - /** Construct a URL out of baseUrl and usual parameters passed to - * GetAccount3PIDsJob. This function can be used when - * a URL for GetAccount3PIDsJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl); - - explicit GetAccount3PIDsJob(); - ~GetAccount3PIDsJob() override; - - const QVector<ThirdPartyIdentifier>& threepids() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - class Post3PIDsJob : public BaseJob - { - public: - // Inner data structures - - struct ThreePidCredentials - { - QString clientSecret; - QString idServer; - QString sid; - - operator QJsonObject() const; - }; - - // End of inner data structures - - explicit Post3PIDsJob(const ThreePidCredentials& threePidCreds, bool bind = {}); - }; - - class RequestTokenTo3PIDJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * RequestTokenTo3PIDJob. This function can be used when - * a URL for RequestTokenTo3PIDJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl); - - explicit RequestTokenTo3PIDJob(); - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/banning.cpp b/lib/jobs/generated/banning.cpp deleted file mode 100644 index f66b27b6..00000000 --- a/lib/jobs/generated/banning.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "banning.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -BanJob::BanJob(const QString& roomId, const QString& userId, const QString& reason) - : BaseJob(HttpVerb::Post, "BanJob", - basePath % "/rooms/" % roomId % "/ban") -{ - QJsonObject _data; - _data.insert("user_id", toJson(userId)); - if (!reason.isEmpty()) - _data.insert("reason", toJson(reason)); - setRequestData(_data); -} - -UnbanJob::UnbanJob(const QString& roomId, const QString& userId) - : BaseJob(HttpVerb::Post, "UnbanJob", - basePath % "/rooms/" % roomId % "/unban") -{ - QJsonObject _data; - _data.insert("user_id", toJson(userId)); - setRequestData(_data); -} - diff --git a/lib/jobs/generated/banning.h b/lib/jobs/generated/banning.h deleted file mode 100644 index 2d6fbd9b..00000000 --- a/lib/jobs/generated/banning.h +++ /dev/null @@ -1,26 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - - - -namespace QMatrixClient -{ - // Operations - - class BanJob : public BaseJob - { - public: - explicit BanJob(const QString& roomId, const QString& userId, const QString& reason = {}); - }; - - class UnbanJob : public BaseJob - { - public: - explicit UnbanJob(const QString& roomId, const QString& userId); - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/content-repo.cpp b/lib/jobs/generated/content-repo.cpp deleted file mode 100644 index 95fc5aed..00000000 --- a/lib/jobs/generated/content-repo.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "content-repo.h" - -#include "converters.h" - -#include <QtNetwork/QNetworkReply> -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/media/r0"); - -class UploadContentJob::Private -{ - public: - QString contentUri; -}; - -BaseJob::Query queryToUploadContent(const QString& filename) -{ - BaseJob::Query _q; - if (!filename.isEmpty()) - _q.addQueryItem("filename", filename); - return _q; -} - -UploadContentJob::UploadContentJob(QIODevice* content, const QString& filename, const QString& contentType) - : BaseJob(HttpVerb::Post, "UploadContentJob", - basePath % "/upload", - queryToUploadContent(filename)) - , d(new Private) -{ - setRequestHeader("Content-Type", contentType.toLatin1()); - - setRequestData(Data(content)); -} - -UploadContentJob::~UploadContentJob() = default; - -const QString& UploadContentJob::contentUri() const -{ - return d->contentUri; -} - -BaseJob::Status UploadContentJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - if (!json.contains("content_uri")) - return { JsonParseError, - "The key 'content_uri' not found in the response" }; - d->contentUri = fromJson<QString>(json.value("content_uri")); - return Success; -} - -class GetContentJob::Private -{ - public: - QString contentType; - QString contentDisposition; - QIODevice* content; -}; - -QUrl GetContentJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/download/" % serverName % "/" % mediaId); -} - -GetContentJob::GetContentJob(const QString& serverName, const QString& mediaId) - : BaseJob(HttpVerb::Get, "GetContentJob", - basePath % "/download/" % serverName % "/" % mediaId, false) - , d(new Private) -{ - setExpectedContentTypes({ "*/*" }); -} - -GetContentJob::~GetContentJob() = default; - -const QString& GetContentJob::contentType() const -{ - return d->contentType; -} - -const QString& GetContentJob::contentDisposition() const -{ - return d->contentDisposition; -} - -QIODevice* GetContentJob::content() const -{ - return d->content; -} - -BaseJob::Status GetContentJob::parseReply(QNetworkReply* reply) -{ - d->contentType = reply->rawHeader("Content-Type"); - d->contentDisposition = reply->rawHeader("Content-Disposition"); - d->content = reply; - return Success; -} - -class GetContentOverrideNameJob::Private -{ - public: - QString contentType; - QString contentDisposition; - QIODevice* content; -}; - -QUrl GetContentOverrideNameJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, const QString& fileName) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/download/" % serverName % "/" % mediaId % "/" % fileName); -} - -GetContentOverrideNameJob::GetContentOverrideNameJob(const QString& serverName, const QString& mediaId, const QString& fileName) - : BaseJob(HttpVerb::Get, "GetContentOverrideNameJob", - basePath % "/download/" % serverName % "/" % mediaId % "/" % fileName, false) - , d(new Private) -{ - setExpectedContentTypes({ "*/*" }); -} - -GetContentOverrideNameJob::~GetContentOverrideNameJob() = default; - -const QString& GetContentOverrideNameJob::contentType() const -{ - return d->contentType; -} - -const QString& GetContentOverrideNameJob::contentDisposition() const -{ - return d->contentDisposition; -} - -QIODevice* GetContentOverrideNameJob::content() const -{ - return d->content; -} - -BaseJob::Status GetContentOverrideNameJob::parseReply(QNetworkReply* reply) -{ - d->contentType = reply->rawHeader("Content-Type"); - d->contentDisposition = reply->rawHeader("Content-Disposition"); - d->content = reply; - return Success; -} - -class GetContentThumbnailJob::Private -{ - public: - QString contentType; - QIODevice* content; -}; - -BaseJob::Query queryToGetContentThumbnail(int width, int height, const QString& method) -{ - BaseJob::Query _q; - _q.addQueryItem("width", QString("%1").arg(width)); - _q.addQueryItem("height", QString("%1").arg(height)); - if (!method.isEmpty()) - _q.addQueryItem("method", method); - return _q; -} - -QUrl GetContentThumbnailJob::makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, int width, int height, const QString& method) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/thumbnail/" % serverName % "/" % mediaId, - queryToGetContentThumbnail(width, height, method)); -} - -GetContentThumbnailJob::GetContentThumbnailJob(const QString& serverName, const QString& mediaId, int width, int height, const QString& method) - : BaseJob(HttpVerb::Get, "GetContentThumbnailJob", - basePath % "/thumbnail/" % serverName % "/" % mediaId, - queryToGetContentThumbnail(width, height, method), - {}, false) - , d(new Private) -{ - setExpectedContentTypes({ "image/jpeg", "image/png" }); -} - -GetContentThumbnailJob::~GetContentThumbnailJob() = default; - -const QString& GetContentThumbnailJob::contentType() const -{ - return d->contentType; -} - -QIODevice* GetContentThumbnailJob::content() const -{ - return d->content; -} - -BaseJob::Status GetContentThumbnailJob::parseReply(QNetworkReply* reply) -{ - d->contentType = reply->rawHeader("Content-Type"); - d->content = reply; - return Success; -} - -class GetUrlPreviewJob::Private -{ - public: - qint64 matrixImageSize; - QString ogImage; -}; - -BaseJob::Query queryToGetUrlPreview(const QString& url, qint64 ts) -{ - BaseJob::Query _q; - _q.addQueryItem("url", url); - _q.addQueryItem("ts", QString("%1").arg(ts)); - return _q; -} - -QUrl GetUrlPreviewJob::makeRequestUrl(QUrl baseUrl, const QString& url, qint64 ts) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/preview_url", - queryToGetUrlPreview(url, ts)); -} - -GetUrlPreviewJob::GetUrlPreviewJob(const QString& url, qint64 ts) - : BaseJob(HttpVerb::Get, "GetUrlPreviewJob", - basePath % "/preview_url", - queryToGetUrlPreview(url, ts)) - , d(new Private) -{ -} - -GetUrlPreviewJob::~GetUrlPreviewJob() = default; - -qint64 GetUrlPreviewJob::matrixImageSize() const -{ - return d->matrixImageSize; -} - -const QString& GetUrlPreviewJob::ogImage() const -{ - return d->ogImage; -} - -BaseJob::Status GetUrlPreviewJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->matrixImageSize = fromJson<qint64>(json.value("matrix:image:size")); - d->ogImage = fromJson<QString>(json.value("og:image")); - return Success; -} - diff --git a/lib/jobs/generated/content-repo.h b/lib/jobs/generated/content-repo.h deleted file mode 100644 index e1e58f88..00000000 --- a/lib/jobs/generated/content-repo.h +++ /dev/null @@ -1,129 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - -#include <QtCore/QIODevice> - - -namespace QMatrixClient -{ - // Operations - - class UploadContentJob : public BaseJob - { - public: - explicit UploadContentJob(QIODevice* content, const QString& filename = {}, const QString& contentType = {}); - ~UploadContentJob() override; - - const QString& contentUri() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - class GetContentJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * GetContentJob. This function can be used when - * a URL for GetContentJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId); - - explicit GetContentJob(const QString& serverName, const QString& mediaId); - ~GetContentJob() override; - - const QString& contentType() const; - const QString& contentDisposition() const; - QIODevice* content() const; - - protected: - Status parseReply(QNetworkReply* reply) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - class GetContentOverrideNameJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * GetContentOverrideNameJob. This function can be used when - * a URL for GetContentOverrideNameJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, const QString& fileName); - - explicit GetContentOverrideNameJob(const QString& serverName, const QString& mediaId, const QString& fileName); - ~GetContentOverrideNameJob() override; - - const QString& contentType() const; - const QString& contentDisposition() const; - QIODevice* content() const; - - protected: - Status parseReply(QNetworkReply* reply) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - class GetContentThumbnailJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * GetContentThumbnailJob. This function can be used when - * a URL for GetContentThumbnailJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& serverName, const QString& mediaId, int width = {}, int height = {}, const QString& method = {}); - - explicit GetContentThumbnailJob(const QString& serverName, const QString& mediaId, int width = {}, int height = {}, const QString& method = {}); - ~GetContentThumbnailJob() override; - - const QString& contentType() const; - QIODevice* content() const; - - protected: - Status parseReply(QNetworkReply* reply) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - class GetUrlPreviewJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * GetUrlPreviewJob. This function can be used when - * a URL for GetUrlPreviewJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& url, qint64 ts = {}); - - explicit GetUrlPreviewJob(const QString& url, qint64 ts = {}); - ~GetUrlPreviewJob() override; - - qint64 matrixImageSize() const; - const QString& ogImage() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/create_room.cpp b/lib/jobs/generated/create_room.cpp deleted file mode 100644 index 6e582791..00000000 --- a/lib/jobs/generated/create_room.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "create_room.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -CreateRoomJob::Invite3pid::operator QJsonObject() const -{ - QJsonObject o; - o.insert("id_server", toJson(idServer)); - o.insert("medium", toJson(medium)); - o.insert("address", toJson(address)); - - return o; -} -namespace QMatrixClient -{ - template <> struct FromJson<CreateRoomJob::Invite3pid> - { - CreateRoomJob::Invite3pid operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - CreateRoomJob::Invite3pid result; - result.idServer = - fromJson<QString>(o.value("id_server")); - result.medium = - fromJson<QString>(o.value("medium")); - result.address = - fromJson<QString>(o.value("address")); - - return result; - } - }; -} // namespace QMatrixClient - -CreateRoomJob::StateEvent::operator QJsonObject() const -{ - QJsonObject o; - o.insert("type", toJson(type)); - o.insert("state_key", toJson(stateKey)); - o.insert("content", toJson(content)); - - return o; -} -namespace QMatrixClient -{ - template <> struct FromJson<CreateRoomJob::StateEvent> - { - CreateRoomJob::StateEvent operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - CreateRoomJob::StateEvent result; - result.type = - fromJson<QString>(o.value("type")); - result.stateKey = - fromJson<QString>(o.value("state_key")); - result.content = - fromJson<QJsonObject>(o.value("content")); - - return result; - } - }; -} // namespace QMatrixClient - -class CreateRoomJob::Private -{ - public: - QString roomId; -}; - -CreateRoomJob::CreateRoomJob(const QString& visibility, const QString& roomAliasName, const QString& name, const QString& topic, const QVector<QString>& invite, const QVector<Invite3pid>& invite3pid, const QJsonObject& creationContent, const QVector<StateEvent>& initialState, const QString& preset, bool isDirect, bool guestCanJoin) - : BaseJob(HttpVerb::Post, "CreateRoomJob", - basePath % "/createRoom") - , d(new Private) -{ - QJsonObject _data; - if (!visibility.isEmpty()) - _data.insert("visibility", toJson(visibility)); - if (!roomAliasName.isEmpty()) - _data.insert("room_alias_name", toJson(roomAliasName)); - if (!name.isEmpty()) - _data.insert("name", toJson(name)); - if (!topic.isEmpty()) - _data.insert("topic", toJson(topic)); - _data.insert("invite", toJson(invite)); - _data.insert("invite_3pid", toJson(invite3pid)); - _data.insert("creation_content", toJson(creationContent)); - _data.insert("initial_state", toJson(initialState)); - if (!preset.isEmpty()) - _data.insert("preset", toJson(preset)); - _data.insert("is_direct", toJson(isDirect)); - _data.insert("guest_can_join", toJson(guestCanJoin)); - setRequestData(_data); -} - -CreateRoomJob::~CreateRoomJob() = default; - -const QString& CreateRoomJob::roomId() const -{ - return d->roomId; -} - -BaseJob::Status CreateRoomJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->roomId = fromJson<QString>(json.value("room_id")); - return Success; -} - diff --git a/lib/jobs/generated/create_room.h b/lib/jobs/generated/create_room.h deleted file mode 100644 index b479615a..00000000 --- a/lib/jobs/generated/create_room.h +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - -#include <QtCore/QJsonObject> -#include <QtCore/QVector> - -#include "converters.h" - -namespace QMatrixClient -{ - // Operations - - class CreateRoomJob : public BaseJob - { - public: - // Inner data structures - - struct Invite3pid - { - QString idServer; - QString medium; - QString address; - - operator QJsonObject() const; - }; - - struct StateEvent - { - QString type; - QString stateKey; - QJsonObject content; - - operator QJsonObject() const; - }; - - // End of inner data structures - - explicit CreateRoomJob(const QString& visibility = {}, const QString& roomAliasName = {}, const QString& name = {}, const QString& topic = {}, const QVector<QString>& invite = {}, const QVector<Invite3pid>& invite3pid = {}, const QJsonObject& creationContent = {}, const QVector<StateEvent>& initialState = {}, const QString& preset = {}, bool isDirect = {}, bool guestCanJoin = {}); - ~CreateRoomJob() override; - - const QString& roomId() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/directory.cpp b/lib/jobs/generated/directory.cpp deleted file mode 100644 index 6324a1f5..00000000 --- a/lib/jobs/generated/directory.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "directory.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0/directory"); - -SetRoomAliasJob::SetRoomAliasJob(const QString& roomAlias, const QString& roomId) - : BaseJob(HttpVerb::Put, "SetRoomAliasJob", - basePath % "/room/" % roomAlias) -{ - QJsonObject _data; - if (!roomId.isEmpty()) - _data.insert("room_id", toJson(roomId)); - setRequestData(_data); -} - -class GetRoomIdByAliasJob::Private -{ - public: - QString roomId; - QVector<QString> servers; -}; - -QUrl GetRoomIdByAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/room/" % roomAlias); -} - -GetRoomIdByAliasJob::GetRoomIdByAliasJob(const QString& roomAlias) - : BaseJob(HttpVerb::Get, "GetRoomIdByAliasJob", - basePath % "/room/" % roomAlias, false) - , d(new Private) -{ -} - -GetRoomIdByAliasJob::~GetRoomIdByAliasJob() = default; - -const QString& GetRoomIdByAliasJob::roomId() const -{ - return d->roomId; -} - -const QVector<QString>& GetRoomIdByAliasJob::servers() const -{ - return d->servers; -} - -BaseJob::Status GetRoomIdByAliasJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->roomId = fromJson<QString>(json.value("room_id")); - d->servers = fromJson<QVector<QString>>(json.value("servers")); - return Success; -} - -QUrl DeleteRoomAliasJob::makeRequestUrl(QUrl baseUrl, const QString& roomAlias) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/room/" % roomAlias); -} - -DeleteRoomAliasJob::DeleteRoomAliasJob(const QString& roomAlias) - : BaseJob(HttpVerb::Delete, "DeleteRoomAliasJob", - basePath % "/room/" % roomAlias) -{ -} - diff --git a/lib/jobs/generated/directory.h b/lib/jobs/generated/directory.h deleted file mode 100644 index 87591240..00000000 --- a/lib/jobs/generated/directory.h +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - -#include <QtCore/QVector> - - -namespace QMatrixClient -{ - // Operations - - class SetRoomAliasJob : public BaseJob - { - public: - explicit SetRoomAliasJob(const QString& roomAlias, const QString& roomId = {}); - }; - - class GetRoomIdByAliasJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * GetRoomIdByAliasJob. This function can be used when - * a URL for GetRoomIdByAliasJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomAlias); - - explicit GetRoomIdByAliasJob(const QString& roomAlias); - ~GetRoomIdByAliasJob() override; - - const QString& roomId() const; - const QVector<QString>& servers() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - class DeleteRoomAliasJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * DeleteRoomAliasJob. This function can be used when - * a URL for DeleteRoomAliasJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomAlias); - - explicit DeleteRoomAliasJob(const QString& roomAlias); - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/inviting.cpp b/lib/jobs/generated/inviting.cpp deleted file mode 100644 index d2ee2107..00000000 --- a/lib/jobs/generated/inviting.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "inviting.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -InviteUserJob::InviteUserJob(const QString& roomId, const QString& userId) - : BaseJob(HttpVerb::Post, "InviteUserJob", - basePath % "/rooms/" % roomId % "/invite") -{ - QJsonObject _data; - _data.insert("user_id", toJson(userId)); - setRequestData(_data); -} - diff --git a/lib/jobs/generated/inviting.h b/lib/jobs/generated/inviting.h deleted file mode 100644 index eaa884df..00000000 --- a/lib/jobs/generated/inviting.h +++ /dev/null @@ -1,20 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - - - -namespace QMatrixClient -{ - // Operations - - class InviteUserJob : public BaseJob - { - public: - explicit InviteUserJob(const QString& roomId, const QString& userId); - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/kicking.cpp b/lib/jobs/generated/kicking.cpp deleted file mode 100644 index bf2490b7..00000000 --- a/lib/jobs/generated/kicking.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "kicking.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -KickJob::KickJob(const QString& roomId, const QString& userId, const QString& reason) - : BaseJob(HttpVerb::Post, "KickJob", - basePath % "/rooms/" % roomId % "/kick") -{ - QJsonObject _data; - _data.insert("user_id", toJson(userId)); - if (!reason.isEmpty()) - _data.insert("reason", toJson(reason)); - setRequestData(_data); -} - diff --git a/lib/jobs/generated/kicking.h b/lib/jobs/generated/kicking.h deleted file mode 100644 index 3814bef7..00000000 --- a/lib/jobs/generated/kicking.h +++ /dev/null @@ -1,20 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - - - -namespace QMatrixClient -{ - // Operations - - class KickJob : public BaseJob - { - public: - explicit KickJob(const QString& roomId, const QString& userId, const QString& reason = {}); - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/leaving.cpp b/lib/jobs/generated/leaving.cpp deleted file mode 100644 index afc4adbd..00000000 --- a/lib/jobs/generated/leaving.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "leaving.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -QUrl LeaveRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/rooms/" % roomId % "/leave"); -} - -LeaveRoomJob::LeaveRoomJob(const QString& roomId) - : BaseJob(HttpVerb::Post, "LeaveRoomJob", - basePath % "/rooms/" % roomId % "/leave") -{ -} - -QUrl ForgetRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/rooms/" % roomId % "/forget"); -} - -ForgetRoomJob::ForgetRoomJob(const QString& roomId) - : BaseJob(HttpVerb::Post, "ForgetRoomJob", - basePath % "/rooms/" % roomId % "/forget") -{ -} - diff --git a/lib/jobs/generated/leaving.h b/lib/jobs/generated/leaving.h deleted file mode 100644 index 9bae2363..00000000 --- a/lib/jobs/generated/leaving.h +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - - - -namespace QMatrixClient -{ - // Operations - - class LeaveRoomJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * LeaveRoomJob. This function can be used when - * a URL for LeaveRoomJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId); - - explicit LeaveRoomJob(const QString& roomId); - }; - - class ForgetRoomJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * ForgetRoomJob. This function can be used when - * a URL for ForgetRoomJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId); - - explicit ForgetRoomJob(const QString& roomId); - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/list_public_rooms.cpp b/lib/jobs/generated/list_public_rooms.cpp deleted file mode 100644 index 1e3c4ed8..00000000 --- a/lib/jobs/generated/list_public_rooms.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "list_public_rooms.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -GetPublicRoomsJob::PublicRoomsChunk::operator QJsonObject() const -{ - QJsonObject o; - o.insert("aliases", toJson(aliases)); - o.insert("canonical_alias", toJson(canonicalAlias)); - o.insert("name", toJson(name)); - o.insert("num_joined_members", toJson(numJoinedMembers)); - o.insert("room_id", toJson(roomId)); - o.insert("topic", toJson(topic)); - o.insert("world_readable", toJson(worldReadable)); - o.insert("guest_can_join", toJson(guestCanJoin)); - o.insert("avatar_url", toJson(avatarUrl)); - - return o; -} -namespace QMatrixClient -{ - template <> struct FromJson<GetPublicRoomsJob::PublicRoomsChunk> - { - GetPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - GetPublicRoomsJob::PublicRoomsChunk result; - result.aliases = - fromJson<QVector<QString>>(o.value("aliases")); - result.canonicalAlias = - fromJson<QString>(o.value("canonical_alias")); - result.name = - fromJson<QString>(o.value("name")); - result.numJoinedMembers = - fromJson<double>(o.value("num_joined_members")); - result.roomId = - fromJson<QString>(o.value("room_id")); - result.topic = - fromJson<QString>(o.value("topic")); - result.worldReadable = - fromJson<bool>(o.value("world_readable")); - result.guestCanJoin = - fromJson<bool>(o.value("guest_can_join")); - result.avatarUrl = - fromJson<QString>(o.value("avatar_url")); - - return result; - } - }; -} // namespace QMatrixClient - -class GetPublicRoomsJob::Private -{ - public: - QVector<PublicRoomsChunk> chunk; - QString nextBatch; - QString prevBatch; - double totalRoomCountEstimate; -}; - -BaseJob::Query queryToGetPublicRooms(double limit, const QString& since, const QString& server) -{ - BaseJob::Query _q; - _q.addQueryItem("limit", QString("%1").arg(limit)); - if (!since.isEmpty()) - _q.addQueryItem("since", since); - if (!server.isEmpty()) - _q.addQueryItem("server", server); - return _q; -} - -QUrl GetPublicRoomsJob::makeRequestUrl(QUrl baseUrl, double limit, const QString& since, const QString& server) -{ - return BaseJob::makeRequestUrl(baseUrl, - basePath % "/publicRooms", - queryToGetPublicRooms(limit, since, server)); -} - -GetPublicRoomsJob::GetPublicRoomsJob(double limit, const QString& since, const QString& server) - : BaseJob(HttpVerb::Get, "GetPublicRoomsJob", - basePath % "/publicRooms", - queryToGetPublicRooms(limit, since, server), - {}, false) - , d(new Private) -{ -} - -GetPublicRoomsJob::~GetPublicRoomsJob() = default; - -const QVector<GetPublicRoomsJob::PublicRoomsChunk>& GetPublicRoomsJob::chunk() const -{ - return d->chunk; -} - -const QString& GetPublicRoomsJob::nextBatch() const -{ - return d->nextBatch; -} - -const QString& GetPublicRoomsJob::prevBatch() const -{ - return d->prevBatch; -} - -double GetPublicRoomsJob::totalRoomCountEstimate() const -{ - return d->totalRoomCountEstimate; -} - -BaseJob::Status GetPublicRoomsJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - if (!json.contains("chunk")) - return { JsonParseError, - "The key 'chunk' not found in the response" }; - d->chunk = fromJson<QVector<PublicRoomsChunk>>(json.value("chunk")); - d->nextBatch = fromJson<QString>(json.value("next_batch")); - d->prevBatch = fromJson<QString>(json.value("prev_batch")); - d->totalRoomCountEstimate = fromJson<double>(json.value("total_room_count_estimate")); - return Success; -} - -QueryPublicRoomsJob::Filter::operator QJsonObject() const -{ - QJsonObject o; - o.insert("generic_search_term", toJson(genericSearchTerm)); - - return o; -} -namespace QMatrixClient -{ - template <> struct FromJson<QueryPublicRoomsJob::Filter> - { - QueryPublicRoomsJob::Filter operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - QueryPublicRoomsJob::Filter result; - result.genericSearchTerm = - fromJson<QString>(o.value("generic_search_term")); - - return result; - } - }; -} // namespace QMatrixClient - -QueryPublicRoomsJob::PublicRoomsChunk::operator QJsonObject() const -{ - QJsonObject o; - o.insert("aliases", toJson(aliases)); - o.insert("canonical_alias", toJson(canonicalAlias)); - o.insert("name", toJson(name)); - o.insert("num_joined_members", toJson(numJoinedMembers)); - o.insert("room_id", toJson(roomId)); - o.insert("topic", toJson(topic)); - o.insert("world_readable", toJson(worldReadable)); - o.insert("guest_can_join", toJson(guestCanJoin)); - o.insert("avatar_url", toJson(avatarUrl)); - - return o; -} -namespace QMatrixClient -{ - template <> struct FromJson<QueryPublicRoomsJob::PublicRoomsChunk> - { - QueryPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - QueryPublicRoomsJob::PublicRoomsChunk result; - result.aliases = - fromJson<QVector<QString>>(o.value("aliases")); - result.canonicalAlias = - fromJson<QString>(o.value("canonical_alias")); - result.name = - fromJson<QString>(o.value("name")); - result.numJoinedMembers = - fromJson<double>(o.value("num_joined_members")); - result.roomId = - fromJson<QString>(o.value("room_id")); - result.topic = - fromJson<QString>(o.value("topic")); - result.worldReadable = - fromJson<bool>(o.value("world_readable")); - result.guestCanJoin = - fromJson<bool>(o.value("guest_can_join")); - result.avatarUrl = - fromJson<QString>(o.value("avatar_url")); - - return result; - } - }; -} // namespace QMatrixClient - -class QueryPublicRoomsJob::Private -{ - public: - QVector<PublicRoomsChunk> chunk; - QString nextBatch; - QString prevBatch; - double totalRoomCountEstimate; -}; - -BaseJob::Query queryToQueryPublicRooms(const QString& server) -{ - BaseJob::Query _q; - if (!server.isEmpty()) - _q.addQueryItem("server", server); - return _q; -} - -QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, double limit, const QString& since, const Filter& filter) - : BaseJob(HttpVerb::Post, "QueryPublicRoomsJob", - basePath % "/publicRooms", - queryToQueryPublicRooms(server)) - , d(new Private) -{ - QJsonObject _data; - _data.insert("limit", toJson(limit)); - if (!since.isEmpty()) - _data.insert("since", toJson(since)); - _data.insert("filter", toJson(filter)); - setRequestData(_data); -} - -QueryPublicRoomsJob::~QueryPublicRoomsJob() = default; - -const QVector<QueryPublicRoomsJob::PublicRoomsChunk>& QueryPublicRoomsJob::chunk() const -{ - return d->chunk; -} - -const QString& QueryPublicRoomsJob::nextBatch() const -{ - return d->nextBatch; -} - -const QString& QueryPublicRoomsJob::prevBatch() const -{ - return d->prevBatch; -} - -double QueryPublicRoomsJob::totalRoomCountEstimate() const -{ - return d->totalRoomCountEstimate; -} - -BaseJob::Status QueryPublicRoomsJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - if (!json.contains("chunk")) - return { JsonParseError, - "The key 'chunk' not found in the response" }; - d->chunk = fromJson<QVector<PublicRoomsChunk>>(json.value("chunk")); - d->nextBatch = fromJson<QString>(json.value("next_batch")); - d->prevBatch = fromJson<QString>(json.value("prev_batch")); - d->totalRoomCountEstimate = fromJson<double>(json.value("total_room_count_estimate")); - return Success; -} - diff --git a/lib/jobs/generated/list_public_rooms.h b/lib/jobs/generated/list_public_rooms.h deleted file mode 100644 index 5c281de3..00000000 --- a/lib/jobs/generated/list_public_rooms.h +++ /dev/null @@ -1,106 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - -#include <QtCore/QVector> - -#include "converters.h" - -namespace QMatrixClient -{ - // Operations - - class GetPublicRoomsJob : public BaseJob - { - public: - // Inner data structures - - struct PublicRoomsChunk - { - QVector<QString> aliases; - QString canonicalAlias; - QString name; - double numJoinedMembers; - QString roomId; - QString topic; - bool worldReadable; - bool guestCanJoin; - QString avatarUrl; - - operator QJsonObject() const; - }; - - // End of inner data structures - - /** Construct a URL out of baseUrl and usual parameters passed to - * GetPublicRoomsJob. This function can be used when - * a URL for GetPublicRoomsJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, double limit = {}, const QString& since = {}, const QString& server = {}); - - explicit GetPublicRoomsJob(double limit = {}, const QString& since = {}, const QString& server = {}); - ~GetPublicRoomsJob() override; - - const QVector<PublicRoomsChunk>& chunk() const; - const QString& nextBatch() const; - const QString& prevBatch() const; - double totalRoomCountEstimate() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - class QueryPublicRoomsJob : public BaseJob - { - public: - // Inner data structures - - struct Filter - { - QString genericSearchTerm; - - operator QJsonObject() const; - }; - - struct PublicRoomsChunk - { - QVector<QString> aliases; - QString canonicalAlias; - QString name; - double numJoinedMembers; - QString roomId; - QString topic; - bool worldReadable; - bool guestCanJoin; - QString avatarUrl; - - operator QJsonObject() const; - }; - - // End of inner data structures - - explicit QueryPublicRoomsJob(const QString& server = {}, double limit = {}, const QString& since = {}, const Filter& filter = {}); - ~QueryPublicRoomsJob() override; - - const QVector<PublicRoomsChunk>& chunk() const; - const QString& nextBatch() const; - const QString& prevBatch() const; - double totalRoomCountEstimate() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/login.cpp b/lib/jobs/generated/login.cpp deleted file mode 100644 index a4dab428..00000000 --- a/lib/jobs/generated/login.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "login.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -class LoginJob::Private -{ - public: - QString userId; - QString accessToken; - QString homeServer; - QString deviceId; -}; - -LoginJob::LoginJob(const QString& type, const QString& user, const QString& medium, const QString& address, const QString& password, const QString& token, const QString& deviceId, const QString& initialDeviceDisplayName) - : BaseJob(HttpVerb::Post, "LoginJob", - basePath % "/login", false) - , d(new Private) -{ - QJsonObject _data; - _data.insert("type", toJson(type)); - if (!user.isEmpty()) - _data.insert("user", toJson(user)); - if (!medium.isEmpty()) - _data.insert("medium", toJson(medium)); - if (!address.isEmpty()) - _data.insert("address", toJson(address)); - if (!password.isEmpty()) - _data.insert("password", toJson(password)); - if (!token.isEmpty()) - _data.insert("token", toJson(token)); - if (!deviceId.isEmpty()) - _data.insert("device_id", toJson(deviceId)); - if (!initialDeviceDisplayName.isEmpty()) - _data.insert("initial_device_display_name", toJson(initialDeviceDisplayName)); - setRequestData(_data); -} - -LoginJob::~LoginJob() = default; - -const QString& LoginJob::userId() const -{ - return d->userId; -} - -const QString& LoginJob::accessToken() const -{ - return d->accessToken; -} - -const QString& LoginJob::homeServer() const -{ - return d->homeServer; -} - -const QString& LoginJob::deviceId() const -{ - return d->deviceId; -} - -BaseJob::Status LoginJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->userId = fromJson<QString>(json.value("user_id")); - d->accessToken = fromJson<QString>(json.value("access_token")); - d->homeServer = fromJson<QString>(json.value("home_server")); - d->deviceId = fromJson<QString>(json.value("device_id")); - return Success; -} - diff --git a/lib/jobs/generated/login.h b/lib/jobs/generated/login.h deleted file mode 100644 index 3ac955d4..00000000 --- a/lib/jobs/generated/login.h +++ /dev/null @@ -1,33 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - - - -namespace QMatrixClient -{ - // Operations - - class LoginJob : public BaseJob - { - public: - explicit LoginJob(const QString& type, const QString& user = {}, const QString& medium = {}, const QString& address = {}, const QString& password = {}, const QString& token = {}, const QString& deviceId = {}, const QString& initialDeviceDisplayName = {}); - ~LoginJob() override; - - const QString& userId() const; - const QString& accessToken() const; - const QString& homeServer() const; - const QString& deviceId() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/logout.cpp b/lib/jobs/generated/logout.cpp deleted file mode 100644 index b943dcd3..00000000 --- a/lib/jobs/generated/logout.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "logout.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -QUrl LogoutJob::makeRequestUrl(QUrl baseUrl) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/logout"); -} - -LogoutJob::LogoutJob() - : BaseJob(HttpVerb::Post, "LogoutJob", - basePath % "/logout") -{ -} - diff --git a/lib/jobs/generated/logout.h b/lib/jobs/generated/logout.h deleted file mode 100644 index 7640ba55..00000000 --- a/lib/jobs/generated/logout.h +++ /dev/null @@ -1,27 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - - - -namespace QMatrixClient -{ - // Operations - - class LogoutJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * LogoutJob. This function can be used when - * a URL for LogoutJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl); - - explicit LogoutJob(); - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/notifications.cpp b/lib/jobs/generated/notifications.cpp deleted file mode 100644 index df6b10ba..00000000 --- a/lib/jobs/generated/notifications.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "notifications.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -namespace QMatrixClient -{ - template <> struct FromJson<GetNotificationsJob::Notification> - { - GetNotificationsJob::Notification operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - GetNotificationsJob::Notification result; - result.actions = - fromJson<QVector<QJsonObject>>(o.value("actions")); - result.event = - fromJson<EventPtr>(o.value("event")); - result.profileTag = - fromJson<QString>(o.value("profile_tag")); - result.read = - fromJson<bool>(o.value("read")); - result.roomId = - fromJson<QString>(o.value("room_id")); - result.ts = - fromJson<qint64>(o.value("ts")); - - return result; - } - }; -} // namespace QMatrixClient - -class GetNotificationsJob::Private -{ - public: - QString nextToken; - std::vector<Notification> notifications; -}; - -BaseJob::Query queryToGetNotifications(const QString& from, int limit, const QString& only) -{ - BaseJob::Query _q; - if (!from.isEmpty()) - _q.addQueryItem("from", from); - _q.addQueryItem("limit", QString("%1").arg(limit)); - if (!only.isEmpty()) - _q.addQueryItem("only", only); - return _q; -} - -QUrl GetNotificationsJob::makeRequestUrl(QUrl baseUrl, const QString& from, int limit, const QString& only) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/notifications", - queryToGetNotifications(from, limit, only)); -} - -GetNotificationsJob::GetNotificationsJob(const QString& from, int limit, const QString& only) - : BaseJob(HttpVerb::Get, "GetNotificationsJob", - basePath % "/notifications", - queryToGetNotifications(from, limit, only)) - , d(new Private) -{ -} - -GetNotificationsJob::~GetNotificationsJob() = default; - -const QString& GetNotificationsJob::nextToken() const -{ - return d->nextToken; -} - -const std::vector<GetNotificationsJob::Notification>& GetNotificationsJob::notifications() const -{ - return d->notifications; -} - -BaseJob::Status GetNotificationsJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->nextToken = fromJson<QString>(json.value("next_token")); - if (!json.contains("notifications")) - return { JsonParseError, - "The key 'notifications' not found in the response" }; - d->notifications = fromJson<std::vector<Notification>>(json.value("notifications")); - return Success; -} - diff --git a/lib/jobs/generated/notifications.h b/lib/jobs/generated/notifications.h deleted file mode 100644 index 798b9576..00000000 --- a/lib/jobs/generated/notifications.h +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - -#include <vector> -#include "events/event.h" -#include <QtCore/QJsonObject> -#include <QtCore/QVector> - -#include "converters.h" - -namespace QMatrixClient -{ - // Operations - - class GetNotificationsJob : public BaseJob - { - public: - // Inner data structures - - struct Notification - { - QVector<QJsonObject> actions; - EventPtr event; - QString profileTag; - bool read; - QString roomId; - qint64 ts; - - }; - - // End of inner data structures - - /** Construct a URL out of baseUrl and usual parameters passed to - * GetNotificationsJob. This function can be used when - * a URL for GetNotificationsJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& from = {}, int limit = {}, const QString& only = {}); - - explicit GetNotificationsJob(const QString& from = {}, int limit = {}, const QString& only = {}); - ~GetNotificationsJob() override; - - const QString& nextToken() const; - const std::vector<Notification>& notifications() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/profile.cpp b/lib/jobs/generated/profile.cpp deleted file mode 100644 index d8ddbc14..00000000 --- a/lib/jobs/generated/profile.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "profile.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -SetDisplayNameJob::SetDisplayNameJob(const QString& userId, const QString& displayname) - : BaseJob(HttpVerb::Put, "SetDisplayNameJob", - basePath % "/profile/" % userId % "/displayname") -{ - QJsonObject _data; - if (!displayname.isEmpty()) - _data.insert("displayname", toJson(displayname)); - setRequestData(_data); -} - -class GetDisplayNameJob::Private -{ - public: - QString displayname; -}; - -QUrl GetDisplayNameJob::makeRequestUrl(QUrl baseUrl, const QString& userId) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/profile/" % userId % "/displayname"); -} - -GetDisplayNameJob::GetDisplayNameJob(const QString& userId) - : BaseJob(HttpVerb::Get, "GetDisplayNameJob", - basePath % "/profile/" % userId % "/displayname", false) - , d(new Private) -{ -} - -GetDisplayNameJob::~GetDisplayNameJob() = default; - -const QString& GetDisplayNameJob::displayname() const -{ - return d->displayname; -} - -BaseJob::Status GetDisplayNameJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->displayname = fromJson<QString>(json.value("displayname")); - return Success; -} - -SetAvatarUrlJob::SetAvatarUrlJob(const QString& userId, const QString& avatarUrl) - : BaseJob(HttpVerb::Put, "SetAvatarUrlJob", - basePath % "/profile/" % userId % "/avatar_url") -{ - QJsonObject _data; - if (!avatarUrl.isEmpty()) - _data.insert("avatar_url", toJson(avatarUrl)); - setRequestData(_data); -} - -class GetAvatarUrlJob::Private -{ - public: - QString avatarUrl; -}; - -QUrl GetAvatarUrlJob::makeRequestUrl(QUrl baseUrl, const QString& userId) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/profile/" % userId % "/avatar_url"); -} - -GetAvatarUrlJob::GetAvatarUrlJob(const QString& userId) - : BaseJob(HttpVerb::Get, "GetAvatarUrlJob", - basePath % "/profile/" % userId % "/avatar_url", false) - , d(new Private) -{ -} - -GetAvatarUrlJob::~GetAvatarUrlJob() = default; - -const QString& GetAvatarUrlJob::avatarUrl() const -{ - return d->avatarUrl; -} - -BaseJob::Status GetAvatarUrlJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->avatarUrl = fromJson<QString>(json.value("avatar_url")); - return Success; -} - -class GetUserProfileJob::Private -{ - public: - QString avatarUrl; - QString displayname; -}; - -QUrl GetUserProfileJob::makeRequestUrl(QUrl baseUrl, const QString& userId) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/profile/" % userId); -} - -GetUserProfileJob::GetUserProfileJob(const QString& userId) - : BaseJob(HttpVerb::Get, "GetUserProfileJob", - basePath % "/profile/" % userId, false) - , d(new Private) -{ -} - -GetUserProfileJob::~GetUserProfileJob() = default; - -const QString& GetUserProfileJob::avatarUrl() const -{ - return d->avatarUrl; -} - -const QString& GetUserProfileJob::displayname() const -{ - return d->displayname; -} - -BaseJob::Status GetUserProfileJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->avatarUrl = fromJson<QString>(json.value("avatar_url")); - d->displayname = fromJson<QString>(json.value("displayname")); - return Success; -} - diff --git a/lib/jobs/generated/profile.h b/lib/jobs/generated/profile.h deleted file mode 100644 index 024130f5..00000000 --- a/lib/jobs/generated/profile.h +++ /dev/null @@ -1,96 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - - - -namespace QMatrixClient -{ - // Operations - - class SetDisplayNameJob : public BaseJob - { - public: - explicit SetDisplayNameJob(const QString& userId, const QString& displayname = {}); - }; - - class GetDisplayNameJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * GetDisplayNameJob. This function can be used when - * a URL for GetDisplayNameJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId); - - explicit GetDisplayNameJob(const QString& userId); - ~GetDisplayNameJob() override; - - const QString& displayname() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - class SetAvatarUrlJob : public BaseJob - { - public: - explicit SetAvatarUrlJob(const QString& userId, const QString& avatarUrl = {}); - }; - - class GetAvatarUrlJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * GetAvatarUrlJob. This function can be used when - * a URL for GetAvatarUrlJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId); - - explicit GetAvatarUrlJob(const QString& userId); - ~GetAvatarUrlJob() override; - - const QString& avatarUrl() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; - - class GetUserProfileJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * GetUserProfileJob. This function can be used when - * a URL for GetUserProfileJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl, const QString& userId); - - explicit GetUserProfileJob(const QString& userId); - ~GetUserProfileJob() override; - - const QString& avatarUrl() const; - const QString& displayname() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/receipts.cpp b/lib/jobs/generated/receipts.cpp deleted file mode 100644 index 83c38b6f..00000000 --- a/lib/jobs/generated/receipts.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "receipts.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -PostReceiptJob::PostReceiptJob(const QString& roomId, const QString& receiptType, const QString& eventId, const QJsonObject& receipt) - : BaseJob(HttpVerb::Post, "PostReceiptJob", - basePath % "/rooms/" % roomId % "/receipt/" % receiptType % "/" % eventId) -{ - setRequestData(Data(receipt)); -} - diff --git a/lib/jobs/generated/receipts.h b/lib/jobs/generated/receipts.h deleted file mode 100644 index 9eb7a489..00000000 --- a/lib/jobs/generated/receipts.h +++ /dev/null @@ -1,21 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - -#include <QtCore/QJsonObject> - - -namespace QMatrixClient -{ - // Operations - - class PostReceiptJob : public BaseJob - { - public: - explicit PostReceiptJob(const QString& roomId, const QString& receiptType, const QString& eventId, const QJsonObject& receipt = {}); - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/redaction.cpp b/lib/jobs/generated/redaction.cpp deleted file mode 100644 index 0da35dfc..00000000 --- a/lib/jobs/generated/redaction.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "redaction.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -class RedactEventJob::Private -{ - public: - QString eventId; -}; - -RedactEventJob::RedactEventJob(const QString& roomId, const QString& eventId, const QString& txnId, const QString& reason) - : BaseJob(HttpVerb::Put, "RedactEventJob", - basePath % "/rooms/" % roomId % "/redact/" % eventId % "/" % txnId) - , d(new Private) -{ - QJsonObject _data; - if (!reason.isEmpty()) - _data.insert("reason", toJson(reason)); - setRequestData(_data); -} - -RedactEventJob::~RedactEventJob() = default; - -const QString& RedactEventJob::eventId() const -{ - return d->eventId; -} - -BaseJob::Status RedactEventJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->eventId = fromJson<QString>(json.value("event_id")); - return Success; -} - diff --git a/lib/jobs/generated/redaction.h b/lib/jobs/generated/redaction.h deleted file mode 100644 index e3b3ff4f..00000000 --- a/lib/jobs/generated/redaction.h +++ /dev/null @@ -1,30 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - - - -namespace QMatrixClient -{ - // Operations - - class RedactEventJob : public BaseJob - { - public: - explicit RedactEventJob(const QString& roomId, const QString& eventId, const QString& txnId, const QString& reason = {}); - ~RedactEventJob() override; - - const QString& eventId() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/third_party_membership.cpp b/lib/jobs/generated/third_party_membership.cpp deleted file mode 100644 index b637d481..00000000 --- a/lib/jobs/generated/third_party_membership.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "third_party_membership.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -InviteBy3PIDJob::InviteBy3PIDJob(const QString& roomId, const QString& idServer, const QString& medium, const QString& address) - : BaseJob(HttpVerb::Post, "InviteBy3PIDJob", - basePath % "/rooms/" % roomId % "/invite") -{ - QJsonObject _data; - _data.insert("id_server", toJson(idServer)); - _data.insert("medium", toJson(medium)); - _data.insert("address", toJson(address)); - setRequestData(_data); -} - diff --git a/lib/jobs/generated/third_party_membership.h b/lib/jobs/generated/third_party_membership.h deleted file mode 100644 index c7b5214e..00000000 --- a/lib/jobs/generated/third_party_membership.h +++ /dev/null @@ -1,20 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - - - -namespace QMatrixClient -{ - // Operations - - class InviteBy3PIDJob : public BaseJob - { - public: - explicit InviteBy3PIDJob(const QString& roomId, const QString& idServer, const QString& medium, const QString& address); - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/typing.cpp b/lib/jobs/generated/typing.cpp deleted file mode 100644 index fa700290..00000000 --- a/lib/jobs/generated/typing.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "typing.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -SetTypingJob::SetTypingJob(const QString& userId, const QString& roomId, bool typing, int timeout) - : BaseJob(HttpVerb::Put, "SetTypingJob", - basePath % "/rooms/" % roomId % "/typing/" % userId) -{ - QJsonObject _data; - _data.insert("typing", toJson(typing)); - _data.insert("timeout", toJson(timeout)); - setRequestData(_data); -} - diff --git a/lib/jobs/generated/typing.h b/lib/jobs/generated/typing.h deleted file mode 100644 index 0495ed0a..00000000 --- a/lib/jobs/generated/typing.h +++ /dev/null @@ -1,20 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - - - -namespace QMatrixClient -{ - // Operations - - class SetTypingJob : public BaseJob - { - public: - explicit SetTypingJob(const QString& userId, const QString& roomId, bool typing, int timeout = {}); - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/versions.cpp b/lib/jobs/generated/versions.cpp deleted file mode 100644 index 3b03172c..00000000 --- a/lib/jobs/generated/versions.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "versions.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client"); - -class GetVersionsJob::Private -{ - public: - QVector<QString> versions; -}; - -QUrl GetVersionsJob::makeRequestUrl(QUrl baseUrl) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/versions"); -} - -GetVersionsJob::GetVersionsJob() - : BaseJob(HttpVerb::Get, "GetVersionsJob", - basePath % "/versions", false) - , d(new Private) -{ -} - -GetVersionsJob::~GetVersionsJob() = default; - -const QVector<QString>& GetVersionsJob::versions() const -{ - return d->versions; -} - -BaseJob::Status GetVersionsJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->versions = fromJson<QVector<QString>>(json.value("versions")); - return Success; -} - diff --git a/lib/jobs/generated/versions.h b/lib/jobs/generated/versions.h deleted file mode 100644 index 18f6bb44..00000000 --- a/lib/jobs/generated/versions.h +++ /dev/null @@ -1,38 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - -#include <QtCore/QVector> - - -namespace QMatrixClient -{ - // Operations - - class GetVersionsJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * GetVersionsJob. This function can be used when - * a URL for GetVersionsJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl); - - explicit GetVersionsJob(); - ~GetVersionsJob() override; - - const QVector<QString>& versions() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/generated/whoami.cpp b/lib/jobs/generated/whoami.cpp deleted file mode 100644 index 4c231b5f..00000000 --- a/lib/jobs/generated/whoami.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "whoami.h" - -#include "converters.h" - -#include <QtCore/QStringBuilder> - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -class GetTokenOwnerJob::Private -{ - public: - QString userId; -}; - -QUrl GetTokenOwnerJob::makeRequestUrl(QUrl baseUrl) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/account/whoami"); -} - -GetTokenOwnerJob::GetTokenOwnerJob() - : BaseJob(HttpVerb::Get, "GetTokenOwnerJob", - basePath % "/account/whoami") - , d(new Private) -{ -} - -GetTokenOwnerJob::~GetTokenOwnerJob() = default; - -const QString& GetTokenOwnerJob::userId() const -{ - return d->userId; -} - -BaseJob::Status GetTokenOwnerJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - if (!json.contains("user_id")) - return { JsonParseError, - "The key 'user_id' not found in the response" }; - d->userId = fromJson<QString>(json.value("user_id")); - return Success; -} - diff --git a/lib/jobs/generated/whoami.h b/lib/jobs/generated/whoami.h deleted file mode 100644 index 835232ee..00000000 --- a/lib/jobs/generated/whoami.h +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#pragma once - -#include "../basejob.h" - - - -namespace QMatrixClient -{ - // Operations - - class GetTokenOwnerJob : public BaseJob - { - public: - /** Construct a URL out of baseUrl and usual parameters passed to - * GetTokenOwnerJob. This function can be used when - * a URL for GetTokenOwnerJob is necessary but the job - * itself isn't. - */ - static QUrl makeRequestUrl(QUrl baseUrl); - - explicit GetTokenOwnerJob(); - ~GetTokenOwnerJob() override; - - const QString& userId() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - QScopedPointer<Private> d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/joinroomjob.cpp b/lib/jobs/joinroomjob.cpp deleted file mode 100644 index 66a75089..00000000 --- a/lib/jobs/joinroomjob.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "joinroomjob.h" -#include "util.h" - -using namespace QMatrixClient; - -class JoinRoomJob::Private -{ - public: - QString roomId; -}; - -JoinRoomJob::JoinRoomJob(const QString& roomAlias) - : BaseJob(HttpVerb::Post, "JoinRoomJob", - QStringLiteral("_matrix/client/r0/join/%1").arg(roomAlias)) - , d(new Private) -{ -} - -JoinRoomJob::~JoinRoomJob() -{ - delete d; -} - -QString JoinRoomJob::roomId() -{ - return d->roomId; -} - -BaseJob::Status JoinRoomJob::parseJson(const QJsonDocument& data) -{ - QJsonObject json = data.object(); - if( json.contains("room_id") ) - { - d->roomId = json.value("room_id").toString(); - return Success; - } - - qCDebug(JOBS) << data; - return { UserDefinedError, "No room_id in the JSON response" }; -} diff --git a/lib/jobs/joinroomjob.h b/lib/jobs/joinroomjob.h deleted file mode 100644 index f3ba216f..00000000 --- a/lib/jobs/joinroomjob.h +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#pragma once - -#include "basejob.h" - -namespace QMatrixClient -{ - class JoinRoomJob: public BaseJob - { - public: - explicit JoinRoomJob(const QString& roomAlias); - virtual ~JoinRoomJob(); - - QString roomId(); - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - Private* d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/mediathumbnailjob.h b/lib/jobs/mediathumbnailjob.h index 6e0b94f3..7963796e 100644 --- a/lib/jobs/mediathumbnailjob.h +++ b/lib/jobs/mediathumbnailjob.h @@ -18,7 +18,7 @@ #pragma once -#include "generated/content-repo.h" +#include "csapi/content-repo.h" #include <QtGui/QPixmap> diff --git a/lib/jobs/roommessagesjob.cpp b/lib/jobs/roommessagesjob.cpp deleted file mode 100644 index e5568f17..00000000 --- a/lib/jobs/roommessagesjob.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "roommessagesjob.h" - -using namespace QMatrixClient; - -class RoomMessagesJob::Private -{ - public: - RoomEvents events; - QString end; -}; - -RoomMessagesJob::RoomMessagesJob(const QString& roomId, const QString& from, - int limit, FetchDirection dir) - : BaseJob(HttpVerb::Get, "RoomMessagesJob", - QStringLiteral("/_matrix/client/r0/rooms/%1/messages").arg(roomId), - Query( - { { "from", from } - , { "dir", dir == FetchDirection::Backward ? "b" : "f" } - , { "limit", QString::number(limit) } - })) - , d(new Private) -{ - qCDebug(JOBS) << "Room messages query:" << query().toString(QUrl::PrettyDecoded); -} - -RoomMessagesJob::~RoomMessagesJob() -{ - delete d; -} - -RoomEvents&& RoomMessagesJob::releaseEvents() -{ - return move(d->events); -} - -QString RoomMessagesJob::end() const -{ - return d->end; -} - -BaseJob::Status RoomMessagesJob::parseJson(const QJsonDocument& data) -{ - const auto obj = data.object(); - d->events.fromJson(obj, "chunk"); - d->end = obj.value("end").toString(); - return Success; -} diff --git a/lib/jobs/roommessagesjob.h b/lib/jobs/roommessagesjob.h deleted file mode 100644 index 7b3fd9c9..00000000 --- a/lib/jobs/roommessagesjob.h +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2016 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#pragma once - -#include "basejob.h" - -#include "../events/event.h" - -namespace QMatrixClient -{ - enum class FetchDirection { Backward, Forward }; - - class RoomMessagesJob: public BaseJob - { - public: - RoomMessagesJob(const QString& roomId, const QString& from, - int limit = 10, - FetchDirection dir = FetchDirection::Backward); - virtual ~RoomMessagesJob(); - - RoomEvents&& releaseEvents(); - QString end() const; - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - class Private; - Private* d; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/sendeventjob.h b/lib/jobs/sendeventjob.h index 3a11eb6a..a3e9a291 100644 --- a/lib/jobs/sendeventjob.h +++ b/lib/jobs/sendeventjob.h @@ -32,7 +32,7 @@ namespace QMatrixClient SendEventJob(const QString& roomId, const EvT& event) : BaseJob(HttpVerb::Put, QStringLiteral("SendEventJob"), QStringLiteral("_matrix/client/r0/rooms/%1/send/%2/") - .arg(roomId, EvT::TypeId), // See also beforeStart() + .arg(roomId, EvT::typeId()), // See also beforeStart() Query(), Data(event.toJson())) { } diff --git a/lib/jobs/setroomstatejob.cpp b/lib/jobs/setroomstatejob.cpp deleted file mode 100644 index c2beb87b..00000000 --- a/lib/jobs/setroomstatejob.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "setroomstatejob.h" - -using namespace QMatrixClient; - -BaseJob::Status SetRoomStateJob::parseJson(const QJsonDocument& data) -{ - _eventId = data.object().value("event_id").toString(); - if (!_eventId.isEmpty()) - return Success; - - qCDebug(JOBS) << data; - return { UserDefinedError, "No event_id in the JSON response" }; -} - diff --git a/lib/jobs/setroomstatejob.h b/lib/jobs/setroomstatejob.h deleted file mode 100644 index b7e6d4a1..00000000 --- a/lib/jobs/setroomstatejob.h +++ /dev/null @@ -1,64 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2015 Felix Rohrbach <kde@fxrh.de> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#pragma once - -#include "basejob.h" - -#include "connectiondata.h" - -namespace QMatrixClient -{ - class SetRoomStateJob: public BaseJob - { - public: - /** - * Constructs a job that sets a state using an arbitrary room event - * with a state key. - */ - template <typename EvT> - SetRoomStateJob(const QString& roomId, const QString& stateKey, - const EvT& event) - : BaseJob(HttpVerb::Put, "SetRoomStateJob", - QStringLiteral("_matrix/client/r0/rooms/%1/state/%2/%3") - .arg(roomId, EvT::TypeId, stateKey), - Query(), - Data(event.toJson())) - { } - /** - * Constructs a job that sets a state using an arbitrary room event - * without a state key. - */ - template <typename EvT> - SetRoomStateJob(const QString& roomId, const EvT& event) - : BaseJob(HttpVerb::Put, "SetRoomStateJob", - QStringLiteral("_matrix/client/r0/rooms/%1/state/%2") - .arg(roomId, EvT::TypeId), - Query(), - Data(event.toJson())) - { } - - QString eventId() const { return _eventId; } - - protected: - Status parseJson(const QJsonDocument& data) override; - - private: - QString _eventId; - }; -} // namespace QMatrixClient diff --git a/lib/jobs/syncjob.cpp b/lib/jobs/syncjob.cpp index 435dfd0e..a739ea0d 100644 --- a/lib/jobs/syncjob.cpp +++ b/lib/jobs/syncjob.cpp @@ -54,11 +54,17 @@ SyncDataList&& SyncData::takeRoomData() return std::move(roomData); } -SyncBatch<Event>&& SyncData::takeAccountData() +Events&& SyncData::takeAccountData() { return std::move(accountData); } +template <typename EventsArrayT, typename StrT> +inline EventsArrayT load(const QJsonObject& batches, StrT keyName) +{ + return fromJson<EventsArrayT>(batches[keyName].toObject().value("events")); +} + BaseJob::Status SyncJob::parseJson(const QJsonDocument& data) { return d.parseJson(data); @@ -71,7 +77,7 @@ BaseJob::Status SyncData::parseJson(const QJsonDocument &data) auto json = data.object(); nextBatch_ = json.value("next_batch").toString(); // TODO: presence - accountData.fromJson(json); + accountData = load<Events>(json, "account_data"); QJsonObject rooms = json.value("rooms").toObject(); JoinStates::Int ii = 1; // ii is used to make a JoinState value @@ -96,33 +102,26 @@ SyncRoomData::SyncRoomData(const QString& roomId_, JoinState joinState_, const QJsonObject& room_) : roomId(roomId_) , joinState(joinState_) - , state(joinState == JoinState::Invite ? "invite_state" : "state") - , timeline("timeline") - , ephemeral("ephemeral") - , accountData("account_data") + , state(load<StateEvents>(room_, + joinState == JoinState::Invite ? "invite_state" : "state")) { switch (joinState) { - case JoinState::Invite: - state.fromJson(room_); - break; case JoinState::Join: - state.fromJson(room_); - timeline.fromJson(room_); - ephemeral.fromJson(room_); - accountData.fromJson(room_); - break; + ephemeral = load<Events>(room_, "ephemeral"); + accountData = load<Events>(room_, "account_data"); + // [[fallthrough]] case JoinState::Leave: - state.fromJson(room_); - timeline.fromJson(room_); + { + timeline = load<RoomEvents>(room_, "timeline"); + auto timelineJson = room_.value("timeline").toObject(); + timelineLimited = timelineJson.value("limited").toBool(); + timelinePrevBatch = timelineJson.value("prev_batch").toString(); + break; - default: - qCWarning(SYNCJOB) << "SyncRoomData: Unknown JoinState value, ignoring:" << int(joinState); + } + default: /* nothing on top of state */; } - auto timelineJson = room_.value("timeline").toObject(); - timelineLimited = timelineJson.value("limited").toBool(); - timelinePrevBatch = timelineJson.value("prev_batch").toString(); - auto unreadJson = room_.value("unread_notifications").toObject(); unreadCount = unreadJson.value(UnreadCountKey).toInt(-2); highlightCount = unreadJson.value("highlight_count").toInt(); diff --git a/lib/jobs/syncjob.h b/lib/jobs/syncjob.h index 919060be..b12f9fff 100644 --- a/lib/jobs/syncjob.h +++ b/lib/jobs/syncjob.h @@ -26,30 +26,15 @@ namespace QMatrixClient { - template <typename EventT> - class SyncBatch : public EventsBatch<EventT> - { - public: - explicit SyncBatch(QString k) : jsonKey(std::move(k)) { } - void fromJson(const QJsonObject& roomContents) - { - EventsBatch<EventT>::fromJson( - roomContents[jsonKey].toObject(), "events"); - } - - private: - QString jsonKey; - }; - class SyncRoomData { public: QString roomId; JoinState joinState; - SyncBatch<RoomEvent> state; - SyncBatch<RoomEvent> timeline; - SyncBatch<Event> ephemeral; - SyncBatch<Event> accountData; + StateEvents state; + RoomEvents timeline; + Events ephemeral; + Events accountData; bool timelineLimited; QString timelinePrevBatch; @@ -71,13 +56,13 @@ namespace QMatrixClient { public: BaseJob::Status parseJson(const QJsonDocument &data); - SyncBatch<Event>&& takeAccountData(); + Events&& takeAccountData(); SyncDataList&& takeRoomData(); QString nextBatch() const; private: QString nextBatch_; - SyncBatch<Event> accountData { "account_data" }; + Events accountData; SyncDataList roomData; }; |