mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 06:53:58 +01:00
modules/admin/rooms: Implement GET /forward_extremities.
This commit is contained in:
parent
4abe844c72
commit
cd78f802b2
3 changed files with 134 additions and 0 deletions
|
@ -183,6 +183,7 @@ ircd::m::module_names
|
|||
"admin_deactivate",
|
||||
"admin_server_version",
|
||||
"admin_federation",
|
||||
"admin_rooms",
|
||||
};
|
||||
|
||||
/// This is a list of modules that are considered "optional" and any loading
|
||||
|
|
|
@ -562,12 +562,14 @@ admin_admin_users_la_SOURCES = admin/users.cc
|
|||
admin_admin_deactivate_la_SOURCES = admin/deactivate.cc
|
||||
admin_admin_server_version_la_SOURCES = admin/server_version.cc
|
||||
admin_admin_federation_la_SOURCES = admin/federation.cc
|
||||
admin_admin_rooms_la_SOURCES = admin/rooms.cc
|
||||
|
||||
admin_module_LTLIBRARIES = \
|
||||
admin/admin_users.la \
|
||||
admin/admin_deactivate.la \
|
||||
admin/admin_server_version.la \
|
||||
admin/admin_federation.la \
|
||||
admin/admin_rooms.la \
|
||||
###
|
||||
|
||||
###############################################################################
|
||||
|
|
131
modules/admin/rooms.cc
Normal file
131
modules/admin/rooms.cc
Normal file
|
@ -0,0 +1,131 @@
|
|||
// The Construct
|
||||
//
|
||||
// Copyright (C) The Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2020 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.
|
||||
|
||||
namespace ircd::m::admin
|
||||
{
|
||||
static resource::response handle_get_forward_extremis(client &, const resource::request &, const room::id &);
|
||||
static resource::response handle_get(client &, const resource::request &);
|
||||
|
||||
extern resource::method get_method;
|
||||
extern resource rooms_resource;
|
||||
};
|
||||
|
||||
ircd::mapi::header
|
||||
IRCD_MODULE
|
||||
{
|
||||
"Admin (undocumented) :Rooms"
|
||||
};
|
||||
|
||||
decltype(ircd::m::admin::rooms_resource)
|
||||
ircd::m::admin::rooms_resource
|
||||
{
|
||||
"/_synapse/admin/v1/rooms/",
|
||||
{
|
||||
"(undocumented) Admin Rooms",
|
||||
resource::DIRECTORY
|
||||
}
|
||||
};
|
||||
|
||||
decltype(ircd::m::admin::get_method)
|
||||
ircd::m::admin::get_method
|
||||
{
|
||||
rooms_resource, "GET", handle_get,
|
||||
{
|
||||
get_method.REQUIRES_OPER
|
||||
}
|
||||
};
|
||||
|
||||
ircd::m::resource::response
|
||||
ircd::m::admin::handle_get(client &client,
|
||||
const resource::request &request)
|
||||
{
|
||||
char buf[768];
|
||||
const string_view &room_id_or_alias
|
||||
{
|
||||
request.parv[0]?
|
||||
url::decode(buf, request.parv[0]):
|
||||
string_view{}
|
||||
};
|
||||
|
||||
const m::room::id::buf room_id
|
||||
{
|
||||
room_id_or_alias?
|
||||
m::room_id(room_id_or_alias):
|
||||
m::room::id::buf{}
|
||||
};
|
||||
|
||||
const auto &cmd
|
||||
{
|
||||
request.parv[1]
|
||||
};
|
||||
|
||||
if(cmd == "forward_extremities")
|
||||
return handle_get_forward_extremis(client, request, room_id);
|
||||
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"/admin/rooms command not found"
|
||||
};
|
||||
}
|
||||
|
||||
ircd::m::resource::response
|
||||
ircd::m::admin::handle_get_forward_extremis(client &client,
|
||||
const resource::request &request,
|
||||
const room::id &room_id)
|
||||
{
|
||||
const m::room::head room_head
|
||||
{
|
||||
room_id
|
||||
};
|
||||
|
||||
m::resource::response::chunked::json response
|
||||
{
|
||||
client, http::OK
|
||||
};
|
||||
|
||||
json::stack::member
|
||||
{
|
||||
response, "count", json::value
|
||||
{
|
||||
long(room_head.count())
|
||||
}
|
||||
};
|
||||
|
||||
json::stack::array results
|
||||
{
|
||||
response, "results"
|
||||
};
|
||||
|
||||
room_head.for_each([&results]
|
||||
(const auto &event_idx, const auto &event_id)
|
||||
{
|
||||
json::stack::object result
|
||||
{
|
||||
results
|
||||
};
|
||||
|
||||
json::stack::member
|
||||
{
|
||||
result, "event_id", event_id
|
||||
};
|
||||
|
||||
json::stack::member
|
||||
{
|
||||
result, "depth", json::value
|
||||
{
|
||||
m::get(std::nothrow, event_idx, "depth", 0L)
|
||||
}
|
||||
};
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return response;
|
||||
}
|
Loading…
Reference in a new issue