Skip to content
Snippets Groups Projects
Verified Commit f664dbbd authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Add function to knock on rooms

parent a368db30
No related branches found
No related tags found
No related merge requests found
......@@ -338,6 +338,12 @@ public:
Callback<mtx::responses::RoomId> cb);
//! Leave a room by its room_id.
void leave_room(const std::string &room_id, Callback<mtx::responses::Empty> cb);
//! Knock on a room.
void knock_room(const std::string &room_id,
const std::vector<std::string> &via,
Callback<mtx::responses::RoomId> cb,
const std::string &reason = "");
//! Invite a user to a room.
void invite_user(const std::string &room_id,
const std::string &user_id,
......
......@@ -541,6 +541,29 @@ Client::join_room(const std::string &room,
post<std::string, mtx::responses::RoomId>(api_path, "{}", callback);
}
void
Client::knock_room(const std::string &room,
const std::vector<std::string> &via,
Callback<mtx::responses::RoomId> cb,
const std::string &reason)
{
using mtx::client::utils::url_encode;
std::string query;
if (!via.empty()) {
query = "?server_name=" + url_encode(via[0]);
for (size_t i = 1; i < via.size(); i++) {
query += "&server_name=" + url_encode(via[i]);
}
}
auto api_path = "/client/r0/knock/" + url_encode(room) + query;
auto body = nlohmann::json::object();
if (!reason.empty())
body["reason"] = reason;
post<std::string, mtx::responses::RoomId>(api_path, body.dump(), cb);
}
void
Client::leave_room(const std::string &room_id, Callback<mtx::responses::Empty> callback)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment