2018-02-22 00:22:04 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#include "rooms.h"
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
resource::response
|
|
|
|
post__forget(client &client,
|
|
|
|
const resource::request &request,
|
|
|
|
const m::room::id &room_id)
|
|
|
|
{
|
2019-03-08 01:05:38 +01:00
|
|
|
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}
|
|
|
|
};
|
|
|
|
|
2019-07-25 23:02:25 +02:00
|
|
|
char room_membuf[m::room::MEMBERSHIP_MAX_SIZE];
|
2019-03-08 01:05:38 +01:00
|
|
|
const string_view &room_membership
|
|
|
|
{
|
2019-08-14 10:01:46 +02:00
|
|
|
membership(room_membuf, room, request.user_id)
|
2019-03-08 01:05:38 +01:00
|
|
|
};
|
|
|
|
|
2019-07-25 23:02:25 +02:00
|
|
|
char user_membuf[m::room::MEMBERSHIP_MAX_SIZE];
|
2019-03-08 01:05:38 +01:00
|
|
|
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")
|
|
|
|
};
|
|
|
|
|
2018-02-22 00:22:04 +01:00
|
|
|
return resource::response
|
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
|
|
|
}
|