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;
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2018-02-22 00:22:04 +01:00
|
|
|
post__leave(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request,
|
2019-08-26 03:39:01 +02:00
|
|
|
const m::room::id &room_id)
|
2018-02-22 00:22:04 +01:00
|
|
|
{
|
2019-03-08 19:07:17 +01:00
|
|
|
const m::room room
|
2018-02-22 00:22:04 +01:00
|
|
|
{
|
2019-03-08 19:07:17 +01:00
|
|
|
room_id
|
2018-02-22 00:22:04 +01:00
|
|
|
};
|
2018-02-23 04:43:23 +01:00
|
|
|
|
2019-06-22 01:45:42 +02:00
|
|
|
if(!room.has("m.room.member", request.user_id))
|
2019-09-21 00:18:39 +02:00
|
|
|
{
|
|
|
|
const m::user::room user_room
|
|
|
|
{
|
|
|
|
request.user_id
|
|
|
|
};
|
|
|
|
|
|
|
|
// In case the user's user room falls out of sync with the real room
|
|
|
|
// state; we directly set the user's user room state.
|
|
|
|
if(!user_room.has("ircd.member", room_id))
|
|
|
|
throw m::error
|
|
|
|
{
|
|
|
|
http::NOT_MODIFIED, "M_TARGET_NOT_IN_ROOM",
|
|
|
|
"The user %s has no membership state in %s",
|
|
|
|
string_view{request.user_id},
|
|
|
|
string_view{room_id},
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto event_id
|
|
|
|
{
|
|
|
|
send(user_room, request.user_id, "ircd.member", room_id, json::members
|
|
|
|
{
|
|
|
|
{ "membership", "leave" }
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
return m::resource::response
|
2019-06-22 01:45:42 +02:00
|
|
|
{
|
2019-09-21 00:18:39 +02:00
|
|
|
client, http::OK, json::members
|
|
|
|
{
|
|
|
|
{ "event_id", event_id }
|
|
|
|
}
|
2019-06-22 01:45:42 +02:00
|
|
|
};
|
2019-09-21 00:18:39 +02:00
|
|
|
}
|
2019-06-22 01:45:42 +02:00
|
|
|
|
2019-03-08 19:07:17 +01:00
|
|
|
const auto event_id
|
2018-02-23 04:43:23 +01:00
|
|
|
{
|
2019-04-22 22:29:03 +02:00
|
|
|
m::leave(room, request.user_id)
|
2018-02-23 04:43:23 +01:00
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
return m::resource::response
|
2019-03-08 19:07:17 +01:00
|
|
|
{
|
|
|
|
client, http::OK, json::members
|
|
|
|
{
|
|
|
|
{ "event_id", event_id }
|
|
|
|
}
|
|
|
|
};
|
2018-02-23 04:43:23 +01:00
|
|
|
}
|