0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-05 10:08:36 +02:00

modules/console: Add command to iterate messages forward and backward with seek to depth.

This commit is contained in:
Jason Volk 2018-02-13 14:32:49 -08:00
parent 26d25c0db0
commit 5a73e631a6

View file

@ -774,6 +774,7 @@ console_cmd__exec_file(const string_view &line)
// room
//
static bool console_cmd__room__messages(const string_view &line);
static bool console_cmd__room__members(const string_view &line);
static bool console_cmd__room__state(const string_view &line);
static bool console_cmd__room__depth(const string_view &line);
@ -800,6 +801,9 @@ console_cmd__room(const string_view &line)
case hash("members"):
return console_cmd__room__members(args);
case hash("messages"):
return console_cmd__room__messages(args);
}
return true;
@ -890,3 +894,36 @@ console_cmd__room__state(const string_view &line)
return true;
}
bool
console_cmd__room__messages(const string_view &line)
{
const m::room::id room_id
{
token(line, ' ', 0)
};
const int64_t depth
{
token_count(line, ' ') > 1? lex_cast<int64_t>(token(line, ' ', 1)) : -1
};
const char order
{
token_count(line, ' ') > 2? token(line, ' ', 2).at(0) : 'b'
};
const m::room room
{
room_id
};
m::room::messages it{room};
if(depth >= 0)
it.seek(depth);
for(; it; order == 'b'? --it : ++it)
out << pretty_oneline(*it) << std::endl;
return true;
}