From 1a65c1ed47bb9e93dc5b5275a67f152b94f5d73c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 6 Mar 2018 06:43:32 -0800 Subject: [PATCH] modules/console: Add fed head command. --- modules/s_console.cc | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/modules/s_console.cc b/modules/s_console.cc index c36e4a8f1..5b1007a12 100644 --- a/modules/s_console.cc +++ b/modules/s_console.cc @@ -1505,6 +1505,7 @@ static bool console_cmd__fed__version(const string_view &line); static bool console_cmd__fed__query(const string_view &line); static bool console_cmd__fed__event(const string_view &line); static bool console_cmd__fed__state(const string_view &line); +static bool console_cmd__fed__head(const string_view &line); bool console_cmd__fed(const string_view &line) @@ -1528,6 +1529,9 @@ console_cmd__fed(const string_view &line) case hash("state"): return console_cmd__fed__state(args); + case hash("head"): + return console_cmd__fed__head(args); + default: throw bad_command{}; } @@ -1535,6 +1539,48 @@ console_cmd__fed(const string_view &line) return true; } +bool +console_cmd__fed__head(const string_view &line) +{ + const m::room::id &room_id + { + token(line, ' ', 0) + }; + + const net::hostport remote + { + token(line, ' ', 1) + }; + + thread_local char buf[16_KiB]; + m::v1::make_join request + { + room_id, m::me.user_id, buf + }; + + if(request.wait(seconds(5)) == ctx::future_status::timeout) + throw http::error{http::REQUEST_TIMEOUT}; + + request.get(); + const json::object proto + { + request.in.content + }; + + const json::array prev_events + { + proto.at({"event", "prev_events"}) + }; + + for(const json::array &prev_event : prev_events) + { + const string_view &id{prev_event.at(0)}; + out << id << " :" << string_view{prev_event.at(1)} << std::endl; + } + + return true; +} + bool console_cmd__fed__state(const string_view &line) {