0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd:Ⓜ️:v1: Support query for user_devices; add console command.

This commit is contained in:
Jason Volk 2018-03-09 09:39:56 -08:00
parent 08fc944021
commit 9b6ef1189b
3 changed files with 79 additions and 0 deletions

View file

@ -22,6 +22,7 @@ struct ircd::m::v1::query
struct opts; struct opts;
struct profile; struct profile;
struct directory; struct directory;
struct user_devices;
explicit operator json::object() const 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 &, opts);
directory(const id::room_alias &room_alias, const mutable_buffer &); 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 &);
};

View file

@ -483,6 +483,32 @@ ircd::m::v1::make_join::make_join(const room::id &room_id,
namespace ircd::m::v1 namespace ircd::m::v1
{ {
thread_local char query_arg_buf[1024]; 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, ircd::m::v1::query::directory::directory(const id::room_alias &room_alias,

View file

@ -1748,6 +1748,7 @@ console_cmd__fed__event(const string_view &line)
return true; 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__directory(const string_view &line);
static bool console_cmd__fed__query__profile(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"): case hash("directory"):
return console_cmd__fed__query__directory(args); return console_cmd__fed__query__directory(args);
case hash("user_devices"):
return console_cmd__fed__query__user_devices(args);
default: default:
throw bad_command{}; throw bad_command{};
} }
@ -1848,6 +1852,47 @@ console_cmd__fed__query__directory(const string_view &line)
return true; 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 bool
console_cmd__fed__version(const string_view &line) console_cmd__fed__version(const string_view &line)
{ {