diff --git a/include/mtxclient/http/client.hpp b/include/mtxclient/http/client.hpp index b82e7c0df74dd30f419e96998683f617389083f7..7b960e43d355640b1c967dc04377036764221f06 100644 --- a/include/mtxclient/http/client.hpp +++ b/include/mtxclient/http/client.hpp @@ -43,6 +43,7 @@ struct Login; struct QueryKeys; struct ClaimKeys; struct UploadKeys; +struct PublicRooms; } namespace responses { struct AvatarUrl; @@ -69,6 +70,7 @@ struct TurnServer; struct UploadKeys; struct Versions; struct WellKnown; +struct PublicRooms; namespace backup { struct SessionBackup; struct RoomKeysBackup; @@ -446,6 +448,12 @@ public: const std::map<mtx::identifiers::User, std::map<std::string, EventContent>> &messages, ErrCallback callback); + //! POST a new room listing to the public rooms directory. + void post_public_rooms(const std::string &server, const nhlomann::json &j, + Callback<mtx::responses::PublicRooms> cb); + //! GET the public rooms directory listing. + void get_public_rooms(int limit, const std::string &since, const std::string &server, + Callback<mtx::responses::PublicRooms> cb); // // Group related endpoints. // diff --git a/lib/http/client.cpp b/lib/http/client.cpp index d3f29975aba97e6f03a392c44dd3d955bb25562b..0ead749393d4a96d5b79a91df41fbfc8c200141a 100644 --- a/lib/http/client.cpp +++ b/lib/http/client.cpp @@ -962,6 +962,25 @@ Client::send_to_device(const std::string &event_type, put<nlohmann::json>(api_path, body, callback); } +void +Client::post_public_rooms(const std::string &server, const nhlomann::json &j, + Callback<mtx::responses::PublicRooms> cb) +{ + const auto api_path = "/client/r0/publicRooms" + " " + server; + post<mtx::requests::PublicRooms, mtx::responses::PublicRooms>( + api_path, j, cb); +} + +void +Client::get_public_rooms(int limit, const std::string &since, const std::string &server, + Callback<mtx::responses::PublicRooms> cb) +{ + const auto api_path = + "/client/r0/publicRooms" + " " + std::to_string(limit) + " " + since + " " + server; + get<mtx::requests::PublicRooms, mtx::responses::PublicRooms>(api_path, cb); +} + + // // Group related endpoints. //