mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 23:40:57 +01:00
ircd:Ⓜ️:v1: Support query for user_devices; add console command.
This commit is contained in:
parent
08fc944021
commit
9b6ef1189b
3 changed files with 79 additions and 0 deletions
|
@ -22,6 +22,7 @@ struct ircd::m::v1::query
|
|||
struct opts;
|
||||
struct profile;
|
||||
struct directory;
|
||||
struct user_devices;
|
||||
|
||||
explicit operator json::object() const
|
||||
{
|
||||
|
@ -63,3 +64,10 @@ struct ircd::m::v1::query::directory
|
|||
directory(const id::room_alias &room_alias, const mutable_buffer &, opts);
|
||||
directory(const id::room_alias &room_alias, const mutable_buffer &);
|
||||
};
|
||||
|
||||
struct ircd::m::v1::query::user_devices
|
||||
:query
|
||||
{
|
||||
user_devices(const id::user &, const mutable_buffer &, opts);
|
||||
user_devices(const id::user &, const mutable_buffer &);
|
||||
};
|
||||
|
|
26
ircd/m/v1.cc
26
ircd/m/v1.cc
|
@ -483,6 +483,32 @@ ircd::m::v1::make_join::make_join(const room::id &room_id,
|
|||
namespace ircd::m::v1
|
||||
{
|
||||
thread_local char query_arg_buf[1024];
|
||||
thread_local char query_url_buf[1024];
|
||||
}
|
||||
|
||||
ircd::m::v1::query::user_devices::user_devices(const id::user &user_id,
|
||||
const mutable_buffer &buf)
|
||||
:user_devices
|
||||
{
|
||||
user_id, buf, opts{user_id.host()}
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ircd::m::v1::query::user_devices::user_devices(const id::user &user_id,
|
||||
const mutable_buffer &buf,
|
||||
opts opts)
|
||||
:query
|
||||
{
|
||||
"user_devices",
|
||||
fmt::sprintf
|
||||
{
|
||||
query_arg_buf, "user_id=%s", url::encode(user_id, query_url_buf)
|
||||
},
|
||||
buf,
|
||||
std::move(opts)
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
ircd::m::v1::query::directory::directory(const id::room_alias &room_alias,
|
||||
|
|
|
@ -1748,6 +1748,7 @@ console_cmd__fed__event(const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool console_cmd__fed__query__user_devices(const string_view &line);
|
||||
static bool console_cmd__fed__query__directory(const string_view &line);
|
||||
static bool console_cmd__fed__query__profile(const string_view &line);
|
||||
|
||||
|
@ -1767,6 +1768,9 @@ console_cmd__fed__query(const string_view &line)
|
|||
case hash("directory"):
|
||||
return console_cmd__fed__query__directory(args);
|
||||
|
||||
case hash("user_devices"):
|
||||
return console_cmd__fed__query__user_devices(args);
|
||||
|
||||
default:
|
||||
throw bad_command{};
|
||||
}
|
||||
|
@ -1848,6 +1852,47 @@ console_cmd__fed__query__directory(const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__fed__query__user_devices(const string_view &line)
|
||||
{
|
||||
const m::id::user &user_id
|
||||
{
|
||||
token(line, ' ', 0)
|
||||
};
|
||||
|
||||
const net::hostport remote
|
||||
{
|
||||
token(line, ' ', 1, user_id.host())
|
||||
};
|
||||
|
||||
m::v1::query::opts opts;
|
||||
opts.remote = remote;
|
||||
|
||||
const unique_buffer<mutable_buffer> buf
|
||||
{
|
||||
32_KiB
|
||||
};
|
||||
|
||||
m::v1::query::user_devices request
|
||||
{
|
||||
user_id, buf, std::move(opts)
|
||||
};
|
||||
|
||||
request.wait(seconds(10));
|
||||
const auto code
|
||||
{
|
||||
request.get()
|
||||
};
|
||||
|
||||
const json::object &response
|
||||
{
|
||||
request
|
||||
};
|
||||
|
||||
out << string_view{response} << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__fed__version(const string_view &line)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue