From 4ced9792f27ed3d891c1f7772ae30d9fe452dd79 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 14 Apr 2018 14:12:03 +0900 Subject: jobs/generated: Overload toJson() instead of operator QJsonObject()/QJsonValue() It slightly reduces the header interface and shortcuts the actual call chain (not that it had any performance implications, just easier reasoning). --- lib/jobs/generated/list_public_rooms.cpp | 116 +++++++++++++++++++++---------- 1 file changed, 81 insertions(+), 35 deletions(-) (limited to 'lib/jobs/generated/list_public_rooms.cpp') diff --git a/lib/jobs/generated/list_public_rooms.cpp b/lib/jobs/generated/list_public_rooms.cpp index 39653300..2ae7f5d3 100644 --- a/lib/jobs/generated/list_public_rooms.cpp +++ b/lib/jobs/generated/list_public_rooms.cpp @@ -10,23 +10,67 @@ using namespace QMatrixClient; static const auto basePath = QStringLiteral("/_matrix/client/r0"); -GetPublicRoomsJob::PublicRoomsChunk::operator QJsonObject() const +class GetRoomVisibilityOnDirectoryJob::Private { - 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; + public: + QString visibility; +}; + +QUrl GetRoomVisibilityOnDirectoryJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) +{ + return BaseJob::makeRequestUrl(baseUrl, + basePath % "/directory/list/room/" % roomId); +} + +GetRoomVisibilityOnDirectoryJob::GetRoomVisibilityOnDirectoryJob(const QString& roomId) + : BaseJob(HttpVerb::Get, "GetRoomVisibilityOnDirectoryJob", + basePath % "/directory/list/room/" % roomId, false) + , d(new Private) +{ +} + +GetRoomVisibilityOnDirectoryJob::~GetRoomVisibilityOnDirectoryJob() = default; + +const QString& GetRoomVisibilityOnDirectoryJob::visibility() const +{ + return d->visibility; +} + +BaseJob::Status GetRoomVisibilityOnDirectoryJob::parseJson(const QJsonDocument& data) +{ + auto json = data.object(); + d->visibility = fromJson(json.value("visibility")); + return Success; } + +SetRoomVisibilityOnDirectoryJob::SetRoomVisibilityOnDirectoryJob(const QString& roomId, const QString& visibility) + : BaseJob(HttpVerb::Put, "SetRoomVisibilityOnDirectoryJob", + basePath % "/directory/list/room/" % roomId) +{ + QJsonObject _data; + if (!visibility.isEmpty()) + _data.insert("visibility", toJson(visibility)); + setRequestData(_data); +} + namespace QMatrixClient { + QJsonObject toJson(const GetPublicRoomsJob::PublicRoomsChunk& pod) + { + QJsonObject o; + o.insert("aliases", toJson(pod.aliases)); + o.insert("canonical_alias", toJson(pod.canonicalAlias)); + o.insert("name", toJson(pod.name)); + o.insert("num_joined_members", toJson(pod.numJoinedMembers)); + o.insert("room_id", toJson(pod.roomId)); + o.insert("topic", toJson(pod.topic)); + o.insert("world_readable", toJson(pod.worldReadable)); + o.insert("guest_can_join", toJson(pod.guestCanJoin)); + o.insert("avatar_url", toJson(pod.avatarUrl)); + + return o; + } + template <> struct FromJson { GetPublicRoomsJob::PublicRoomsChunk operator()(QJsonValue jv) @@ -128,15 +172,16 @@ BaseJob::Status GetPublicRoomsJob::parseJson(const QJsonDocument& data) return Success; } -QueryPublicRoomsJob::Filter::operator QJsonObject() const -{ - QJsonObject o; - o.insert("generic_search_term", toJson(genericSearchTerm)); - - return o; -} namespace QMatrixClient { + QJsonObject toJson(const QueryPublicRoomsJob::Filter& pod) + { + QJsonObject o; + o.insert("generic_search_term", toJson(pod.genericSearchTerm)); + + return o; + } + template <> struct FromJson { QueryPublicRoomsJob::Filter operator()(QJsonValue jv) @@ -151,23 +196,24 @@ namespace QMatrixClient }; } // 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 { + QJsonObject toJson(const QueryPublicRoomsJob::PublicRoomsChunk& pod) + { + QJsonObject o; + o.insert("aliases", toJson(pod.aliases)); + o.insert("canonical_alias", toJson(pod.canonicalAlias)); + o.insert("name", toJson(pod.name)); + o.insert("num_joined_members", toJson(pod.numJoinedMembers)); + o.insert("room_id", toJson(pod.roomId)); + o.insert("topic", toJson(pod.topic)); + o.insert("world_readable", toJson(pod.worldReadable)); + o.insert("guest_can_join", toJson(pod.guestCanJoin)); + o.insert("avatar_url", toJson(pod.avatarUrl)); + + return o; + } + template <> struct FromJson { QueryPublicRoomsJob::PublicRoomsChunk operator()(QJsonValue jv) -- cgit v1.2.3 From cbb7c2d7eff7ac8724d766ade2c3e659d15d97e2 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 30 Apr 2018 22:17:04 +0900 Subject: jobs/generated: cleanup C++ --- lib/jobs/generated/list_public_rooms.cpp | 50 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'lib/jobs/generated/list_public_rooms.cpp') diff --git a/lib/jobs/generated/list_public_rooms.cpp b/lib/jobs/generated/list_public_rooms.cpp index 2ae7f5d3..35a670fb 100644 --- a/lib/jobs/generated/list_public_rooms.cpp +++ b/lib/jobs/generated/list_public_rooms.cpp @@ -73,28 +73,28 @@ namespace QMatrixClient template <> struct FromJson { - GetPublicRoomsJob::PublicRoomsChunk operator()(QJsonValue jv) + GetPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv) { - QJsonObject o = jv.toObject(); + const auto& o = jv.toObject(); GetPublicRoomsJob::PublicRoomsChunk result; result.aliases = - fromJson>(o.value("aliases")); + fromJson>(o.value("aliases")); result.canonicalAlias = - fromJson(o.value("canonical_alias")); + fromJson(o.value("canonical_alias")); result.name = - fromJson(o.value("name")); + fromJson(o.value("name")); result.numJoinedMembers = - fromJson(o.value("num_joined_members")); + fromJson(o.value("num_joined_members")); result.roomId = - fromJson(o.value("room_id")); + fromJson(o.value("room_id")); result.topic = - fromJson(o.value("topic")); + fromJson(o.value("topic")); result.worldReadable = - fromJson(o.value("world_readable")); + fromJson(o.value("world_readable")); result.guestCanJoin = - fromJson(o.value("guest_can_join")); + fromJson(o.value("guest_can_join")); result.avatarUrl = - fromJson(o.value("avatar_url")); + fromJson(o.value("avatar_url")); return result; } @@ -184,12 +184,12 @@ namespace QMatrixClient template <> struct FromJson { - QueryPublicRoomsJob::Filter operator()(QJsonValue jv) + QueryPublicRoomsJob::Filter operator()(const QJsonValue& jv) { - QJsonObject o = jv.toObject(); + const auto& o = jv.toObject(); QueryPublicRoomsJob::Filter result; result.genericSearchTerm = - fromJson(o.value("generic_search_term")); + fromJson(o.value("generic_search_term")); return result; } @@ -216,28 +216,28 @@ namespace QMatrixClient template <> struct FromJson { - QueryPublicRoomsJob::PublicRoomsChunk operator()(QJsonValue jv) + QueryPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv) { - QJsonObject o = jv.toObject(); + const auto& o = jv.toObject(); QueryPublicRoomsJob::PublicRoomsChunk result; result.aliases = - fromJson>(o.value("aliases")); + fromJson>(o.value("aliases")); result.canonicalAlias = - fromJson(o.value("canonical_alias")); + fromJson(o.value("canonical_alias")); result.name = - fromJson(o.value("name")); + fromJson(o.value("name")); result.numJoinedMembers = - fromJson(o.value("num_joined_members")); + fromJson(o.value("num_joined_members")); result.roomId = - fromJson(o.value("room_id")); + fromJson(o.value("room_id")); result.topic = - fromJson(o.value("topic")); + fromJson(o.value("topic")); result.worldReadable = - fromJson(o.value("world_readable")); + fromJson(o.value("world_readable")); result.guestCanJoin = - fromJson(o.value("guest_can_join")); + fromJson(o.value("guest_can_join")); result.avatarUrl = - fromJson(o.value("avatar_url")); + fromJson(o.value("avatar_url")); return result; } -- cgit v1.2.3 From 38934c2310b426be640988dc10f48de88a3d92bc Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 1 May 2018 20:04:51 +0900 Subject: jobs/generated: use std::move in baseURL; type updates from the API files The type updates are a matter of pending PR to matrix-doc yet. --- lib/jobs/generated/list_public_rooms.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'lib/jobs/generated/list_public_rooms.cpp') diff --git a/lib/jobs/generated/list_public_rooms.cpp b/lib/jobs/generated/list_public_rooms.cpp index 35a670fb..9b4174cb 100644 --- a/lib/jobs/generated/list_public_rooms.cpp +++ b/lib/jobs/generated/list_public_rooms.cpp @@ -18,7 +18,7 @@ class GetRoomVisibilityOnDirectoryJob::Private QUrl GetRoomVisibilityOnDirectoryJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/directory/list/room/" % roomId); } @@ -84,7 +84,7 @@ namespace QMatrixClient result.name = fromJson(o.value("name")); result.numJoinedMembers = - fromJson(o.value("num_joined_members")); + fromJson(o.value("num_joined_members")); result.roomId = fromJson(o.value("room_id")); result.topic = @@ -107,10 +107,10 @@ class GetPublicRoomsJob::Private QVector chunk; QString nextBatch; QString prevBatch; - double totalRoomCountEstimate; + qint64 totalRoomCountEstimate; }; -BaseJob::Query queryToGetPublicRooms(double limit, const QString& since, const QString& server) +BaseJob::Query queryToGetPublicRooms(int limit, const QString& since, const QString& server) { BaseJob::Query _q; _q.addQueryItem("limit", QString("%1").arg(limit)); @@ -121,14 +121,14 @@ BaseJob::Query queryToGetPublicRooms(double limit, const QString& since, const Q return _q; } -QUrl GetPublicRoomsJob::makeRequestUrl(QUrl baseUrl, double limit, const QString& since, const QString& server) +QUrl GetPublicRoomsJob::makeRequestUrl(QUrl baseUrl, int limit, const QString& since, const QString& server) { - return BaseJob::makeRequestUrl(baseUrl, + return BaseJob::makeRequestUrl(std::move(baseUrl), basePath % "/publicRooms", queryToGetPublicRooms(limit, since, server)); } -GetPublicRoomsJob::GetPublicRoomsJob(double limit, const QString& since, const QString& server) +GetPublicRoomsJob::GetPublicRoomsJob(int limit, const QString& since, const QString& server) : BaseJob(HttpVerb::Get, "GetPublicRoomsJob", basePath % "/publicRooms", queryToGetPublicRooms(limit, since, server), @@ -154,7 +154,7 @@ const QString& GetPublicRoomsJob::prevBatch() const return d->prevBatch; } -double GetPublicRoomsJob::totalRoomCountEstimate() const +qint64 GetPublicRoomsJob::totalRoomCountEstimate() const { return d->totalRoomCountEstimate; } @@ -168,7 +168,7 @@ BaseJob::Status GetPublicRoomsJob::parseJson(const QJsonDocument& data) d->chunk = fromJson>(json.value("chunk")); d->nextBatch = fromJson(json.value("next_batch")); d->prevBatch = fromJson(json.value("prev_batch")); - d->totalRoomCountEstimate = fromJson(json.value("total_room_count_estimate")); + d->totalRoomCountEstimate = fromJson(json.value("total_room_count_estimate")); return Success; } @@ -227,7 +227,7 @@ namespace QMatrixClient result.name = fromJson(o.value("name")); result.numJoinedMembers = - fromJson(o.value("num_joined_members")); + fromJson(o.value("num_joined_members")); result.roomId = fromJson(o.value("room_id")); result.topic = @@ -250,7 +250,7 @@ class QueryPublicRoomsJob::Private QVector chunk; QString nextBatch; QString prevBatch; - double totalRoomCountEstimate; + qint64 totalRoomCountEstimate; }; BaseJob::Query queryToQueryPublicRooms(const QString& server) @@ -261,7 +261,7 @@ BaseJob::Query queryToQueryPublicRooms(const QString& server) return _q; } -QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, double limit, const QString& since, const Filter& filter) +QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, int limit, const QString& since, const Filter& filter) : BaseJob(HttpVerb::Post, "QueryPublicRoomsJob", basePath % "/publicRooms", queryToQueryPublicRooms(server)) @@ -292,7 +292,7 @@ const QString& QueryPublicRoomsJob::prevBatch() const return d->prevBatch; } -double QueryPublicRoomsJob::totalRoomCountEstimate() const +qint64 QueryPublicRoomsJob::totalRoomCountEstimate() const { return d->totalRoomCountEstimate; } @@ -306,7 +306,7 @@ BaseJob::Status QueryPublicRoomsJob::parseJson(const QJsonDocument& data) d->chunk = fromJson>(json.value("chunk")); d->nextBatch = fromJson(json.value("next_batch")); d->prevBatch = fromJson(json.value("prev_batch")); - d->totalRoomCountEstimate = fromJson(json.value("total_room_count_estimate")); + d->totalRoomCountEstimate = fromJson(json.value("total_room_count_estimate")); return Success; } -- cgit v1.2.3 From f3927ca0c16a61fcb0933333ecff8095917a5b47 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 3 May 2018 20:10:14 +0900 Subject: jobs/generated: Drop unused code --- lib/jobs/generated/list_public_rooms.cpp | 54 +++----------------------------- 1 file changed, 5 insertions(+), 49 deletions(-) (limited to 'lib/jobs/generated/list_public_rooms.cpp') diff --git a/lib/jobs/generated/list_public_rooms.cpp b/lib/jobs/generated/list_public_rooms.cpp index 9b4174cb..03664def 100644 --- a/lib/jobs/generated/list_public_rooms.cpp +++ b/lib/jobs/generated/list_public_rooms.cpp @@ -55,21 +55,7 @@ SetRoomVisibilityOnDirectoryJob::SetRoomVisibilityOnDirectoryJob(const QString& namespace QMatrixClient { - QJsonObject toJson(const GetPublicRoomsJob::PublicRoomsChunk& pod) - { - QJsonObject o; - o.insert("aliases", toJson(pod.aliases)); - o.insert("canonical_alias", toJson(pod.canonicalAlias)); - o.insert("name", toJson(pod.name)); - o.insert("num_joined_members", toJson(pod.numJoinedMembers)); - o.insert("room_id", toJson(pod.roomId)); - o.insert("topic", toJson(pod.topic)); - o.insert("world_readable", toJson(pod.worldReadable)); - o.insert("guest_can_join", toJson(pod.guestCanJoin)); - o.insert("avatar_url", toJson(pod.avatarUrl)); - - return o; - } + // Converters template <> struct FromJson { @@ -95,7 +81,7 @@ namespace QMatrixClient fromJson(o.value("guest_can_join")); result.avatarUrl = fromJson(o.value("avatar_url")); - + return result; } }; @@ -174,43 +160,13 @@ BaseJob::Status GetPublicRoomsJob::parseJson(const QJsonDocument& data) namespace QMatrixClient { + // Converters + QJsonObject toJson(const QueryPublicRoomsJob::Filter& pod) { QJsonObject o; o.insert("generic_search_term", toJson(pod.genericSearchTerm)); - - return o; - } - template <> struct FromJson - { - QueryPublicRoomsJob::Filter operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - QueryPublicRoomsJob::Filter result; - result.genericSearchTerm = - fromJson(o.value("generic_search_term")); - - return result; - } - }; -} // namespace QMatrixClient - -namespace QMatrixClient -{ - QJsonObject toJson(const QueryPublicRoomsJob::PublicRoomsChunk& pod) - { - QJsonObject o; - o.insert("aliases", toJson(pod.aliases)); - o.insert("canonical_alias", toJson(pod.canonicalAlias)); - o.insert("name", toJson(pod.name)); - o.insert("num_joined_members", toJson(pod.numJoinedMembers)); - o.insert("room_id", toJson(pod.roomId)); - o.insert("topic", toJson(pod.topic)); - o.insert("world_readable", toJson(pod.worldReadable)); - o.insert("guest_can_join", toJson(pod.guestCanJoin)); - o.insert("avatar_url", toJson(pod.avatarUrl)); - return o; } @@ -238,7 +194,7 @@ namespace QMatrixClient fromJson(o.value("guest_can_join")); result.avatarUrl = fromJson(o.value("avatar_url")); - + return result; } }; -- cgit v1.2.3 From e49a842e877d17a1c6cbbb2349c2816639447721 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 4 May 2018 19:09:57 +0900 Subject: Connection, jobs/generated: Use QStringList instead of QVector QStringList's API is richer, after all. --- lib/jobs/generated/list_public_rooms.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/jobs/generated/list_public_rooms.cpp') diff --git a/lib/jobs/generated/list_public_rooms.cpp b/lib/jobs/generated/list_public_rooms.cpp index 03664def..b27bdd58 100644 --- a/lib/jobs/generated/list_public_rooms.cpp +++ b/lib/jobs/generated/list_public_rooms.cpp @@ -64,7 +64,7 @@ namespace QMatrixClient const auto& o = jv.toObject(); GetPublicRoomsJob::PublicRoomsChunk result; result.aliases = - fromJson>(o.value("aliases")); + fromJson(o.value("aliases")); result.canonicalAlias = fromJson(o.value("canonical_alias")); result.name = @@ -177,7 +177,7 @@ namespace QMatrixClient const auto& o = jv.toObject(); QueryPublicRoomsJob::PublicRoomsChunk result; result.aliases = - fromJson>(o.value("aliases")); + fromJson(o.value("aliases")); result.canonicalAlias = fromJson(o.value("canonical_alias")); result.name = -- cgit v1.2.3 From 49022915fde72b83d9f18944c268110b01fa3469 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 4 May 2018 23:04:04 +0900 Subject: New home for the generated code - lib/csapi --- lib/jobs/generated/list_public_rooms.cpp | 268 ------------------------------- 1 file changed, 268 deletions(-) delete mode 100644 lib/jobs/generated/list_public_rooms.cpp (limited to 'lib/jobs/generated/list_public_rooms.cpp') diff --git a/lib/jobs/generated/list_public_rooms.cpp b/lib/jobs/generated/list_public_rooms.cpp deleted file mode 100644 index b27bdd58..00000000 --- a/lib/jobs/generated/list_public_rooms.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/****************************************************************************** - * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN - */ - -#include "list_public_rooms.h" - -#include - -using namespace QMatrixClient; - -static const auto basePath = QStringLiteral("/_matrix/client/r0"); - -class GetRoomVisibilityOnDirectoryJob::Private -{ - public: - QString visibility; -}; - -QUrl GetRoomVisibilityOnDirectoryJob::makeRequestUrl(QUrl baseUrl, const QString& roomId) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/directory/list/room/" % roomId); -} - -GetRoomVisibilityOnDirectoryJob::GetRoomVisibilityOnDirectoryJob(const QString& roomId) - : BaseJob(HttpVerb::Get, "GetRoomVisibilityOnDirectoryJob", - basePath % "/directory/list/room/" % roomId, false) - , d(new Private) -{ -} - -GetRoomVisibilityOnDirectoryJob::~GetRoomVisibilityOnDirectoryJob() = default; - -const QString& GetRoomVisibilityOnDirectoryJob::visibility() const -{ - return d->visibility; -} - -BaseJob::Status GetRoomVisibilityOnDirectoryJob::parseJson(const QJsonDocument& data) -{ - auto json = data.object(); - d->visibility = fromJson(json.value("visibility")); - return Success; -} - -SetRoomVisibilityOnDirectoryJob::SetRoomVisibilityOnDirectoryJob(const QString& roomId, const QString& visibility) - : BaseJob(HttpVerb::Put, "SetRoomVisibilityOnDirectoryJob", - basePath % "/directory/list/room/" % roomId) -{ - QJsonObject _data; - if (!visibility.isEmpty()) - _data.insert("visibility", toJson(visibility)); - setRequestData(_data); -} - -namespace QMatrixClient -{ - // Converters - - template <> struct FromJson - { - GetPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - GetPublicRoomsJob::PublicRoomsChunk result; - result.aliases = - fromJson(o.value("aliases")); - result.canonicalAlias = - fromJson(o.value("canonical_alias")); - result.name = - fromJson(o.value("name")); - result.numJoinedMembers = - fromJson(o.value("num_joined_members")); - result.roomId = - fromJson(o.value("room_id")); - result.topic = - fromJson(o.value("topic")); - result.worldReadable = - fromJson(o.value("world_readable")); - result.guestCanJoin = - fromJson(o.value("guest_can_join")); - result.avatarUrl = - fromJson(o.value("avatar_url")); - - return result; - } - }; -} // namespace QMatrixClient - -class GetPublicRoomsJob::Private -{ - public: - QVector chunk; - QString nextBatch; - QString prevBatch; - qint64 totalRoomCountEstimate; -}; - -BaseJob::Query queryToGetPublicRooms(int 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, int limit, const QString& since, const QString& server) -{ - return BaseJob::makeRequestUrl(std::move(baseUrl), - basePath % "/publicRooms", - queryToGetPublicRooms(limit, since, server)); -} - -GetPublicRoomsJob::GetPublicRoomsJob(int 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::chunk() const -{ - return d->chunk; -} - -const QString& GetPublicRoomsJob::nextBatch() const -{ - return d->nextBatch; -} - -const QString& GetPublicRoomsJob::prevBatch() const -{ - return d->prevBatch; -} - -qint64 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>(json.value("chunk")); - d->nextBatch = fromJson(json.value("next_batch")); - d->prevBatch = fromJson(json.value("prev_batch")); - d->totalRoomCountEstimate = fromJson(json.value("total_room_count_estimate")); - return Success; -} - -namespace QMatrixClient -{ - // Converters - - QJsonObject toJson(const QueryPublicRoomsJob::Filter& pod) - { - QJsonObject o; - o.insert("generic_search_term", toJson(pod.genericSearchTerm)); - - return o; - } - - template <> struct FromJson - { - QueryPublicRoomsJob::PublicRoomsChunk operator()(const QJsonValue& jv) - { - const auto& o = jv.toObject(); - QueryPublicRoomsJob::PublicRoomsChunk result; - result.aliases = - fromJson(o.value("aliases")); - result.canonicalAlias = - fromJson(o.value("canonical_alias")); - result.name = - fromJson(o.value("name")); - result.numJoinedMembers = - fromJson(o.value("num_joined_members")); - result.roomId = - fromJson(o.value("room_id")); - result.topic = - fromJson(o.value("topic")); - result.worldReadable = - fromJson(o.value("world_readable")); - result.guestCanJoin = - fromJson(o.value("guest_can_join")); - result.avatarUrl = - fromJson(o.value("avatar_url")); - - return result; - } - }; -} // namespace QMatrixClient - -class QueryPublicRoomsJob::Private -{ - public: - QVector chunk; - QString nextBatch; - QString prevBatch; - qint64 totalRoomCountEstimate; -}; - -BaseJob::Query queryToQueryPublicRooms(const QString& server) -{ - BaseJob::Query _q; - if (!server.isEmpty()) - _q.addQueryItem("server", server); - return _q; -} - -QueryPublicRoomsJob::QueryPublicRoomsJob(const QString& server, int 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::chunk() const -{ - return d->chunk; -} - -const QString& QueryPublicRoomsJob::nextBatch() const -{ - return d->nextBatch; -} - -const QString& QueryPublicRoomsJob::prevBatch() const -{ - return d->prevBatch; -} - -qint64 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>(json.value("chunk")); - d->nextBatch = fromJson(json.value("next_batch")); - d->prevBatch = fromJson(json.value("prev_batch")); - d->totalRoomCountEstimate = fromJson(json.value("total_room_count_estimate")); - return Success; -} - -- cgit v1.2.3