0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-10-02 21:59:02 +02:00

modules/console: Add fed query_auth cmd.

This commit is contained in:
Jason Volk 2019-02-16 15:18:02 -08:00
parent f275cf8c83
commit 73f57f70a3

View file

@ -10436,6 +10436,104 @@ console_cmd__fed__event_auth(opt &out, const string_view &line)
return true;
}
bool
console_cmd__fed__query_auth(opt &out, const string_view &line)
{
const params param{line, " ",
{
"room_id", "event_id", "remote"
}};
const auto room_id
{
m::room_id(param.at(0))
};
const m::event::id &event_id
{
param.at(1)
};
const net::hostport remote
{
param.at(2, event_id.host())
};
m::v1::query_auth::opts opts;
opts.remote = remote;
const unique_buffer<mutable_buffer> buf
{
128_KiB
};
json::stack ost{buf};
{
json::stack::object top{ost};
json::stack::array auth_chain
{
top, "auth_chain"
};
const m::event::auth::chain chain
{
m::index(event_id)
};
m::event::fetch event;
chain.for_each([&auth_chain, &event]
(const m::event::idx &event_idx)
{
if(seek(event, event_idx, std::nothrow))
auth_chain.append(event);
});
}
const json::object content
{
ost.completed()
};
m::v1::query_auth request
{
room_id, event_id, content, buf + size(ost.completed()), std::move(opts)
};
request.wait(out.timeout);
request.get();
const json::object response{request};
const json::array &auth_chain
{
response["auth_chain"]
};
const json::array &missing
{
response["missing"]
};
const json::object &rejects
{
response["rejects"]
};
out << "auth_chain: " << std::endl;
for(const json::object &event : auth_chain)
out << pretty_oneline(m::event{event}) << std::endl;
out << std::endl;
out << "missing: " << std::endl;
for(const string_view &event_id : missing)
out << event_id << std::endl;
out << std::endl;
out << "rejects: " << std::endl;
for(const auto &member : rejects)
out << member.first << ": " << member.second << std::endl;
return true;
}
bool
console_cmd__fed__query__profile(opt &out, const string_view &line)
{