diff --git a/include/mtxclient/http/client.hpp b/include/mtxclient/http/client.hpp index 7dbd280f6af1b5b51cd2bd0431aac3f2486c6aa3..7f693889b45dc36403bcfd2d0031b75e77f2b438 100644 --- a/include/mtxclient/http/client.hpp +++ b/include/mtxclient/http/client.hpp @@ -592,6 +592,13 @@ public: const std::map<mtx::identifiers::User, std::map<std::string, EventContent>> &messages, ErrCallback callback); + //! Resolve the specified roomalias to a roomid. + void resolve_room_alias(const std::string &alias, Callback<mtx::responses::RoomId> cb); + //! Add an alias to a room. + void add_room_alias(const std::string &alias, const std::string &roomid, ErrCallback cb); + //! Delete an alias from a room. + void delete_room_alias(const std::string &alias, ErrCallback cb); + //! Gets the visibility of a given room on the server's public room directory. void get_room_visibility(const std::string &room_id, Callback<mtx::responses::PublicRoomVisibility> cb); diff --git a/lib/http/client.cpp b/lib/http/client.cpp index 293ff80001e9088f96e3d53dd73a041ff4d01ef8..cd8a29457d2a4cb7cb66e62d13fa25835bb9bbe0 100644 --- a/lib/http/client.cpp +++ b/lib/http/client.cpp @@ -1103,6 +1103,31 @@ Client::send_to_device(const std::string &event_type, put<nlohmann::json>(api_path, body, std::move(callback)); } +void +Client::resolve_room_alias(const std::string &alias, Callback<mtx::responses::RoomId> cb) +{ + const auto api_path = "/client/r0/directory/room/" + mtx::client::utils::url_encode(alias); + + get<mtx::responses::RoomId>(api_path, + [cb = std::move(cb)](const mtx::responses::RoomId &res, + HeaderFields, + RequestErr err) { cb(res, err); }); +} +void +Client::add_room_alias(const std::string &alias, const std::string &roomid, ErrCallback cb) +{ + const auto api_path = "/client/r0/directory/room/" + mtx::client::utils::url_encode(alias); + auto body = nlohmann::json::object(); + body["room_id"] = roomid; + put<nlohmann::json>(api_path, body, std::move(cb)); +} + +void +Client::delete_room_alias(const std::string &alias, ErrCallback cb) +{ + delete_("/client/r0/directory/room/" + mtx::client::utils::url_encode(alias), std::move(cb)); +} + void Client::get_room_visibility(const std::string &room_id, Callback<mtx::responses::PublicRoomVisibility> cb)