diff --git a/include/ircd/m/v1/query.h b/include/ircd/m/v1/query.h index 1cc0ab7e5..3d969b9f4 100644 --- a/include/ircd/m/v1/query.h +++ b/include/ircd/m/v1/query.h @@ -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 &); +}; diff --git a/ircd/m/v1.cc b/ircd/m/v1.cc index e5d91fa54..0fc96db70 100644 --- a/ircd/m/v1.cc +++ b/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, diff --git a/modules/console.cc b/modules/console.cc index 129d2cf9c..437718476 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -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 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) {