mirror of
https://github.com/matrix-construct/construct
synced 2024-07-11 04:58:40 +02:00
modules/client/rooms/forget: Implement 10.4.3.2 POST forget.
This commit is contained in:
parent
57f28374c9
commit
3fdb3a420a
|
@ -17,6 +17,77 @@ post__forget(client &client,
|
|||
const resource::request &request,
|
||||
const m::room::id &room_id)
|
||||
{
|
||||
const m::room room
|
||||
{
|
||||
room_id
|
||||
};
|
||||
|
||||
const m::user::room user_room
|
||||
{
|
||||
request.user_id
|
||||
};
|
||||
|
||||
const auto event_idx
|
||||
{
|
||||
user_room.get(std::nothrow, "ircd.member", room_id)
|
||||
};
|
||||
|
||||
if(!event_idx)
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"No user membership found for room %s.",
|
||||
string_view{room_id}
|
||||
};
|
||||
|
||||
char room_membuf[32];
|
||||
const string_view &room_membership
|
||||
{
|
||||
room.membership(room_membuf, request.user_id)
|
||||
};
|
||||
|
||||
char user_membuf[32];
|
||||
string_view user_membership;
|
||||
m::get(std::nothrow, event_idx, "content", [&user_membuf, &user_membership]
|
||||
(const json::object &content)
|
||||
{
|
||||
const json::string &membership
|
||||
{
|
||||
content.get("membership")
|
||||
};
|
||||
|
||||
user_membership =
|
||||
{
|
||||
user_membuf, copy(user_membuf, membership)
|
||||
};
|
||||
});
|
||||
|
||||
if(room_membership != user_membership)
|
||||
log::critical
|
||||
{
|
||||
"Membership mismatch for user %s in room %s: user:%s vs. room:%s",
|
||||
string_view{request.user_id},
|
||||
string_view{room_id},
|
||||
user_membership,
|
||||
room_membership
|
||||
};
|
||||
|
||||
if(user_membership != "leave")
|
||||
throw m::error
|
||||
{
|
||||
http::OK, "M_MEMBERSHIP_NOT_LEAVE",
|
||||
"You must leave the room first to forget it"
|
||||
};
|
||||
|
||||
const auto event_id
|
||||
{
|
||||
m::event_id(event_idx)
|
||||
};
|
||||
|
||||
const auto redact_id
|
||||
{
|
||||
redact(user_room, request.user_id, event_id, "forget")
|
||||
};
|
||||
|
||||
return resource::response
|
||||
{
|
||||
client, http::OK
|
||||
|
|
Loading…
Reference in a new issue