2019-03-14 21:25:28 +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.
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
static m::resource::response
|
2019-03-14 21:25:28 +01:00
|
|
|
get__list_room(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request);
|
2019-03-14 21:25:28 +01:00
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
static m::resource::response
|
2019-03-14 21:25:28 +01:00
|
|
|
put__list_room(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request);
|
2019-03-14 21:25:28 +01:00
|
|
|
|
|
|
|
mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Client 10.5 :Listing rooms"
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource
|
2019-03-14 21:25:28 +01:00
|
|
|
list_room_resource
|
|
|
|
{
|
|
|
|
"/_matrix/client/r0/directory/list/room/",
|
|
|
|
{
|
|
|
|
"(10.5) Listing rooms",
|
|
|
|
list_room_resource.DIRECTORY
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::method
|
2019-03-14 21:25:28 +01:00
|
|
|
list_room_put
|
|
|
|
{
|
|
|
|
list_room_resource, "PUT", put__list_room,
|
|
|
|
{
|
|
|
|
list_room_put.REQUIRES_AUTH
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2019-03-14 21:25:28 +01:00
|
|
|
put__list_room(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request)
|
2019-03-14 21:25:28 +01:00
|
|
|
{
|
|
|
|
if(request.parv.size() < 1)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"room_id path parameter required"
|
|
|
|
};
|
|
|
|
|
|
|
|
m::room::id::buf room_id
|
|
|
|
{
|
|
|
|
url::decode(room_id, request.parv[0])
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!exists(room))
|
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"Room %s is not known to this server",
|
|
|
|
string_view{room_id}
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room::power power
|
|
|
|
{
|
|
|
|
room
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool permitted
|
|
|
|
{
|
|
|
|
// is_oper(request.user_id) ||
|
|
|
|
power(request.user_id, {}, "m.room.history_visibility", "") &&
|
|
|
|
power(request.user_id, {}, "m.room.join_rules", "")
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!permitted)
|
|
|
|
throw m::ACCESS_DENIED
|
|
|
|
{
|
|
|
|
"You do not have permission to list the room on this server"
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::string &visibility
|
|
|
|
{
|
|
|
|
request.at("visibility")
|
|
|
|
};
|
|
|
|
|
2019-03-14 23:08:00 +01:00
|
|
|
switch(hash(visibility))
|
|
|
|
{
|
|
|
|
case "public"_:
|
|
|
|
// We set an empty summary for this room because
|
|
|
|
// we already have its state on this server;
|
2019-09-14 03:04:53 +02:00
|
|
|
m::rooms::summary::set(room.room_id);
|
2019-03-14 23:08:00 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "private"_:
|
2019-08-13 07:59:27 +02:00
|
|
|
m::rooms::summary::del(room.room_id);
|
2019-03-14 23:08:00 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: throw m::UNSUPPORTED
|
|
|
|
{
|
|
|
|
"visibility type '%s' is not supported here",
|
|
|
|
string_view{visibility}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
return m::resource::response
|
2019-03-14 21:25:28 +01:00
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::method
|
2019-03-14 21:25:28 +01:00
|
|
|
list_room_get
|
|
|
|
{
|
|
|
|
list_room_resource, "GET", get__list_room
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2019-03-14 21:25:28 +01:00
|
|
|
get__list_room(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request)
|
2019-03-14 21:25:28 +01:00
|
|
|
{
|
|
|
|
if(request.parv.size() < 1)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"room_id path parameter required"
|
|
|
|
};
|
|
|
|
|
|
|
|
m::room::id::buf room_id
|
|
|
|
{
|
|
|
|
url::decode(room_id, request.parv[0])
|
|
|
|
};
|
|
|
|
|
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!exists(room))
|
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"Room %s is not known to this server",
|
|
|
|
string_view{room_id}
|
|
|
|
};
|
|
|
|
|
|
|
|
const string_view &visibility
|
|
|
|
{
|
2019-08-13 07:59:27 +02:00
|
|
|
m::rooms::summary::has(room_id)? "public" : "private"
|
2019-03-14 21:25:28 +01:00
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
return m::resource::response
|
2019-03-14 21:25:28 +01:00
|
|
|
{
|
|
|
|
client, json::members
|
|
|
|
{
|
|
|
|
{ "visibility", visibility }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|