From 83469b5695a551b4c491323754f771e5d4e46dce Mon Sep 17 00:00:00 2001 From: kamathmanu <manuriddle@gmail.com> Date: Fri, 11 Dec 2020 14:22:47 -0500 Subject: [PATCH] Request and Response payloads for GET & POST publicRooms endpoints. --- include/mtx/public_rooms_chunk.hpp | 45 ++++++++++++++++++++++++++ include/mtx/requests.hpp | 24 ++++++++++++++ include/mtx/responses.hpp | 1 + include/mtx/responses/public_rooms.hpp | 40 +++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 include/mtx/public_rooms_chunk.hpp create mode 100644 include/mtx/responses/public_rooms.hpp diff --git a/include/mtx/public_rooms_chunk.hpp b/include/mtx/public_rooms_chunk.hpp new file mode 100644 index 000000000..b2410935b --- /dev/null +++ b/include/mtx/public_rooms_chunk.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include <string> +#include <vector> + +#if __has_include(<nlohmann/json_fwd.hpp>) +#include <nlohmann/json_fwd.hpp> +#else +#include <nlohmann/json.hpp> +#endif + +namespace mtx { +namespace responses { +struct PublicRoomsChunk +{ + //! Aliases of the room. May be empty. + std::vector<std::string> aliases; + //! The canonical alias of the room, if any. + std::string canonical_alias + //! The name of the room, if any. + std::string name; + //! **Required.** The number of members joined to the room. + int num_joined_members; + //! **Required.** The ID of the room. + std::string room_id; + //! The topic of the room, if any. + std::string topic; + //! **Required.** Whether the room may be viewed by guest users without joining. + bool world_readable; + //! **Required.** Whether guest users may join the room + //! and participate in it. If they can, they will be subject + //! to ordinary power level rules like any other user. + bool guest_can_join; + //! The URL for the room's avatar, if one is set. + std::string avatar_url; +}; + +void +from_json(const nlohmann::json &obj, PublicRoomsChunk &res); + +void +to_json(nlohmann::json &obj, const PublicRoomsChunk &res); + +} // namespace responses +} // namespace mtx \ No newline at end of file diff --git a/include/mtx/requests.hpp b/include/mtx/requests.hpp index e73586b7c..940cf2037 100644 --- a/include/mtx/requests.hpp +++ b/include/mtx/requests.hpp @@ -5,6 +5,7 @@ #include <mtx/common.hpp> #include <mtx/events/collections.hpp> +#include <mtx/filters.hpp> #if __has_include(<nlohmann/json_fwd.hpp>) #include <nlohmann/json_fwd.hpp> #else @@ -137,6 +138,29 @@ struct TypingNotification void to_json(json &obj, const TypingNotification &request); +//! Request payload for the `POST /_matrix/client/r0/publicRooms` endpoint. +struct PublicRooms +{ + //! Limit the number of results returned. + int limit; + //! A pagination token from a previous request, allowing clients + //! to get the next (or previous) batch of rooms. The direction of + //! pagination is specified solely by which token is supplied, + //! rather than via an explicit flag. + std::string since; + //! Filter to apply to the results. + Filter filter; + //! Whether or not to include all known networks/protocols from + //! application services on the homeserver. Defaults to false. + bool include_all_networks = false; + //! The specific third party network/protocol to request from + //! the homeserver. Can only be used if include_all_networks is false. + std::string third_party_instance_id; +}; + +void +to_json(json &obj, const PostPublicRooms &request); + struct Empty {}; diff --git a/include/mtx/responses.hpp b/include/mtx/responses.hpp index 6f7d55784..4d3633631 100644 --- a/include/mtx/responses.hpp +++ b/include/mtx/responses.hpp @@ -16,3 +16,4 @@ #include "responses/turn_server.hpp" #include "responses/version.hpp" #include "responses/well-known.hpp" +#include "responses/public_rooms.hpp" diff --git a/include/mtx/responses/public_rooms.hpp b/include/mtx/responses/public_rooms.hpp new file mode 100644 index 000000000..c0df3419e --- /dev/null +++ b/include/mtx/responses/public_rooms.hpp @@ -0,0 +1,40 @@ +#pragma once + +#include <vector> +#include <string> + +#if __has_include(<nlohmann/json_fwd.hpp>) +#include <nlohmann/json_fwd.hpp> +#else +#include <nlohmann/json.hpp> +#endif + +#include "mtx/public_rooms_chunk.hpp" + +namespace mtx { +namespace responses { + +//! Response from the `GET /_matrix/client/r0/publicRooms` & +//! `POST /_matrix/client/r0/publicRooms` endpoints. +struct PublicRooms +{ + //! **Required**. A paginated chunk of public rooms. + std::vector<PublicRoomsChunk> chunk; + //! A pagination token for the response. The absence + //! of this token means there are no more results to + //! fetch and the client should stop paginating. + std::string next_batch; + //! A pagination token that allows fetching previous results. + //! The absence of this token means there are no results + //! before this batch, i.e. this is the first batch. + std::string prev_batch; + //! An estimate on the total number of public rooms, + //! if the server has an estimate. + int total_room_count_estimate; +}; + +void +from_json(const nlohmann::json &obj, PublicRooms &publicRooms); + +} // namespace responses +} // namespace mtx \ No newline at end of file -- GitLab