diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-06-08 12:59:18 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-06-08 12:59:18 +0900 |
commit | 907865f71aed9c51565bb3ed229e791757874a61 (patch) | |
tree | 76c42ab8e57dcfffdbadde9e95e69233ca397b9d /lib/csapi | |
parent | 35d4c9d028f6a4387f8168898378e80dd03d7f94 (diff) | |
download | libquotient-907865f71aed9c51565bb3ed229e791757874a61.tar.gz libquotient-907865f71aed9c51565bb3ed229e791757874a61.zip |
csapi: add jobs from rooms.yaml
Getting a single event (/events), getting the full room state as well as with
a specific type/key (/state), getting the list of room members (/members and
/joined_members).
Diffstat (limited to 'lib/csapi')
-rw-r--r-- | lib/csapi/rooms.cpp | 244 | ||||
-rw-r--r-- | lib/csapi/rooms.h | 183 |
2 files changed, 427 insertions, 0 deletions
diff --git a/lib/csapi/rooms.cpp b/lib/csapi/rooms.cpp new file mode 100644 index 00000000..4b66b447 --- /dev/null +++ b/lib/csapi/rooms.cpp @@ -0,0 +1,244 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#include "rooms.h" + +#include "converters.h" + +#include <QtCore/QStringBuilder> + +using namespace QMatrixClient; + +static const auto basePath = QStringLiteral("/_matrix/client/r0"); + +class GetOneRoomEventJob::Private +{ + public: + EventPtr data; +}; + +QUrl GetOneRoomEventJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/rooms/" % roomId % "/event/" % eventId); +} + +GetOneRoomEventJob::GetOneRoomEventJob(const QString& roomId, const QString& eventId) + : BaseJob(HttpVerb::Get, "GetOneRoomEventJob", + basePath % "/rooms/" % roomId % "/event/" % eventId) + , d(new Private) +{ +} + +GetOneRoomEventJob::~GetOneRoomEventJob() = default; + +EventPtr&& GetOneRoomEventJob::data() +{ + return std::move(d->data); +} + +BaseJob::Status GetOneRoomEventJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("data")) + return { JsonParseError, + "The key 'data' not found in the response" }; + d->data = fromJson<EventPtr>(json.value("data")); + return Success; +} + +class GetRoomStateWithKeyJob::Private +{ + public: + StateEventPtr data; +}; + +QUrl GetRoomStateWithKeyJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventType, const QString& stateKey) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/rooms/" % roomId % "/state/" % eventType % "/" % stateKey); +} + +GetRoomStateWithKeyJob::GetRoomStateWithKeyJob(const QString& roomId, const QString& eventType, const QString& stateKey) + : BaseJob(HttpVerb::Get, "GetRoomStateWithKeyJob", + basePath % "/rooms/" % roomId % "/state/" % eventType % "/" % stateKey) + , d(new Private) +{ +} + +GetRoomStateWithKeyJob::~GetRoomStateWithKeyJob() = default; + +StateEventPtr&& GetRoomStateWithKeyJob::data() +{ + return std::move(d->data); +} + +BaseJob::Status GetRoomStateWithKeyJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("data")) + return { JsonParseError, + "The key 'data' not found in the response" }; + d->data = fromJson<StateEventPtr>(json.value("data")); + return Success; +} + +class GetRoomStateByTypeJob::Private +{ + public: + StateEventPtr data; +}; + +QUrl GetRoomStateByTypeJob::makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventType) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/rooms/" % roomId % "/state/" % eventType); +} + +GetRoomStateByTypeJob::GetRoomStateByTypeJob(const QString& roomId, const QString& eventType) + : BaseJob(HttpVerb::Get, "GetRoomStateByTypeJob", + basePath % "/rooms/" % roomId % "/state/" % eventType) + , d(new Private) +{ +} + +GetRoomStateByTypeJob::~GetRoomStateByTypeJob() = default; + +StateEventPtr&& GetRoomStateByTypeJob::data() +{ + return std::move(d->data); +} + +BaseJob::Status GetRoomStateByTypeJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("data")) + return { JsonParseError, + "The key 'data' not found in the response" }; + d->data = fromJson<StateEventPtr>(json.value("data")); + return Success; +} + +class GetRoomStateJob::Private +{ + public: + StateEvents data; +}; + +QUrl GetRoomStateJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/rooms/" % roomId % "/state"); +} + +GetRoomStateJob::GetRoomStateJob(const QString& roomId) + : BaseJob(HttpVerb::Get, "GetRoomStateJob", + basePath % "/rooms/" % roomId % "/state") + , d(new Private) +{ +} + +GetRoomStateJob::~GetRoomStateJob() = default; + +StateEvents&& GetRoomStateJob::data() +{ + return std::move(d->data); +} + +BaseJob::Status GetRoomStateJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + if (!json.contains("data")) + return { JsonParseError, + "The key 'data' not found in the response" }; + d->data = fromJson<StateEvents>(json.value("data")); + return Success; +} + +class GetMembersByRoomJob::Private +{ + public: + EventsArray<RoomMemberEvent> chunk; +}; + +QUrl GetMembersByRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/rooms/" % roomId % "/members"); +} + +GetMembersByRoomJob::GetMembersByRoomJob(const QString& roomId) + : BaseJob(HttpVerb::Get, "GetMembersByRoomJob", + basePath % "/rooms/" % roomId % "/members") + , d(new Private) +{ +} + +GetMembersByRoomJob::~GetMembersByRoomJob() = default; + +EventsArray<RoomMemberEvent>&& GetMembersByRoomJob::chunk() +{ + return std::move(d->chunk); +} + +BaseJob::Status GetMembersByRoomJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->chunk = fromJson<EventsArray<RoomMemberEvent>>(json.value("chunk")); + return Success; +} + +namespace QMatrixClient +{ + // Converters + + template <> struct FromJson<GetJoinedMembersByRoomJob::RoomMember> + { + GetJoinedMembersByRoomJob::RoomMember operator()(const QJsonValue& jv) + { + const auto& _json = jv.toObject(); + GetJoinedMembersByRoomJob::RoomMember result; + result.displayName = + fromJson<QString>(_json.value("display_name")); + result.avatarUrl = + fromJson<QString>(_json.value("avatar_url")); + + return result; + } + }; +} // namespace QMatrixClient + +class GetJoinedMembersByRoomJob::Private +{ + public: + QHash<QString, RoomMember> joined; +}; + +QUrl GetJoinedMembersByRoomJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) +{ + return BaseJob::makeRequestUrl(std::move(baseUrl), + basePath % "/rooms/" % roomId % "/joined_members"); +} + +GetJoinedMembersByRoomJob::GetJoinedMembersByRoomJob(const QString& roomId) + : BaseJob(HttpVerb::Get, "GetJoinedMembersByRoomJob", + basePath % "/rooms/" % roomId % "/joined_members") + , d(new Private) +{ +} + +GetJoinedMembersByRoomJob::~GetJoinedMembersByRoomJob() = default; + +const QHash<QString, GetJoinedMembersByRoomJob::RoomMember>& GetJoinedMembersByRoomJob::joined() const +{ + return d->joined; +} + +BaseJob::Status GetJoinedMembersByRoomJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->joined = fromJson<QHash<QString, RoomMember>>(json.value("joined")); + return Success; +} + diff --git a/lib/csapi/rooms.h b/lib/csapi/rooms.h new file mode 100644 index 00000000..459c6ad5 --- /dev/null +++ b/lib/csapi/rooms.h @@ -0,0 +1,183 @@ +/****************************************************************************** + * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN + */ + +#pragma once + +#include "jobs/basejob.h" + +#include "events/event.h" +#include "events/roommemberevent.h" +#include <QtCore/QHash> +#include "converters.h" + +namespace QMatrixClient +{ + // Operations + + class GetOneRoomEventJob : public BaseJob + { + public: + explicit GetOneRoomEventJob(const QString& roomId, const QString& eventId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetOneRoomEventJob. This function can be used when + * a URL for GetOneRoomEventJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventId); + + ~GetOneRoomEventJob() override; + + // Result properties + + EventPtr&& data(); + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; + + class GetRoomStateWithKeyJob : public BaseJob + { + public: + explicit GetRoomStateWithKeyJob(const QString& roomId, const QString& eventType, const QString& stateKey); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetRoomStateWithKeyJob. This function can be used when + * a URL for GetRoomStateWithKeyJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventType, const QString& stateKey); + + ~GetRoomStateWithKeyJob() override; + + // Result properties + + StateEventPtr&& data(); + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; + + class GetRoomStateByTypeJob : public BaseJob + { + public: + explicit GetRoomStateByTypeJob(const QString& roomId, const QString& eventType); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetRoomStateByTypeJob. This function can be used when + * a URL for GetRoomStateByTypeJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId, const QString& eventType); + + ~GetRoomStateByTypeJob() override; + + // Result properties + + StateEventPtr&& data(); + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; + + class GetRoomStateJob : public BaseJob + { + public: + explicit GetRoomStateJob(const QString& roomId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetRoomStateJob. This function can be used when + * a URL for GetRoomStateJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId); + + ~GetRoomStateJob() override; + + // Result properties + + StateEvents&& data(); + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; + + class GetMembersByRoomJob : public BaseJob + { + public: + explicit GetMembersByRoomJob(const QString& roomId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetMembersByRoomJob. This function can be used when + * a URL for GetMembersByRoomJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId); + + ~GetMembersByRoomJob() override; + + // Result properties + + EventsArray<RoomMemberEvent>&& chunk(); + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; + + class GetJoinedMembersByRoomJob : public BaseJob + { + public: + // Inner data structures + + struct RoomMember + { + QString displayName; + QString avatarUrl; + }; + + // Construction/destruction + + explicit GetJoinedMembersByRoomJob(const QString& roomId); + + /** Construct a URL out of baseUrl and usual parameters passed to + * GetJoinedMembersByRoomJob. This function can be used when + * a URL for GetJoinedMembersByRoomJob is necessary but the job + * itself isn't. + */ + static QUrl makeRequestUrl(QUrl baseUrl, const QString& roomId); + + ~GetJoinedMembersByRoomJob() override; + + // Result properties + + const QHash<QString, RoomMember>& joined() const; + + protected: + Status parseJson(const QJsonDocument& data) override; + + private: + class Private; + QScopedPointer<Private> d; + }; +} // namespace QMatrixClient |