0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-13 16:33:53 +01:00

modules/client/directory/room: Implement Client 10.2.3 DELETE roomAlias.

This commit is contained in:
Jason Volk 2019-08-13 22:09:42 -07:00
parent da495a8810
commit 623a283671

View file

@ -158,3 +158,95 @@ put__directory_room(client &client,
}
};
}
static resource::response
delete__directory_room(client &client,
const resource::request &request);
resource::method
directory_room_delete
{
directory_room_resource, "DELETE", delete__directory_room,
{
directory_room_delete.REQUIRES_AUTH
}
};
resource::response
delete__directory_room(client &client,
const resource::request &request)
{
if(request.parv.size() < 1)
throw m::NEED_MORE_PARAMS
{
"Room alias path parameter missing"
};
m::room::alias::buf room_alias
{
url::decode(room_alias, request.parv[0])
};
const m::room::id::buf room_id
{
m::room_id(room_alias)
};
const unique_mutable_buffer buf
{
48_KiB
};
// Generate the new content of the m.room.aliases
json::stack out{buf};
bool removed {false};
{
json::stack::object content
{
out
};
json::stack::array array
{
content, "aliases"
};
// Iterate existing aliases for host
const m::room::aliases aliases{room_id};
aliases.for_each(room_alias.host(), [&room_alias, &array, &removed]
(const m::room::alias &existing_alias)
{
// Check for existing
if(!iequals(existing_alias, room_alias))
array.append(existing_alias);
else
removed = true;
return true;
});
}
if(!removed)
return resource::response
{
client, http::OK
};
// Commit the new event
// TODO: ABA with another aliases event.
const auto eid
{
m::send(room_id, request.user_id, "m.room.aliases", room_alias.host(), json::object
{
out.completed()
})
};
return resource::response
{
client, json::members
{
{ "event_id", eid }
}
};
}