mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 15:00:51 +01:00
modules/console: Improve room messages command; incorporate limit argument.
This commit is contained in:
parent
3f72b7ce19
commit
e35338b5b2
1 changed files with 17 additions and 5 deletions
|
@ -1886,19 +1886,31 @@ console_cmd__room__count(opt &out, const string_view &line)
|
||||||
bool
|
bool
|
||||||
console_cmd__room__messages(opt &out, const string_view &line)
|
console_cmd__room__messages(opt &out, const string_view &line)
|
||||||
{
|
{
|
||||||
|
const params param{line, " ",
|
||||||
|
{
|
||||||
|
"room_id", "depth|-limit", "order", "limit"
|
||||||
|
}};
|
||||||
|
|
||||||
const auto &room_id
|
const auto &room_id
|
||||||
{
|
{
|
||||||
m::room_id(token(line, ' ', 0))
|
m::room_id(param.at(0))
|
||||||
};
|
};
|
||||||
|
|
||||||
const int64_t depth
|
const int64_t depth
|
||||||
{
|
{
|
||||||
token_count(line, ' ') > 1? lex_cast<int64_t>(token(line, ' ', 1)) : -1
|
param.at<int64_t>(1, std::numeric_limits<int64_t>::max())
|
||||||
};
|
};
|
||||||
|
|
||||||
const char order
|
const char order
|
||||||
{
|
{
|
||||||
token_count(line, ' ') > 2? token(line, ' ', 2).at(0) : 'b'
|
param.at(2, "b"_sv).at(0)
|
||||||
|
};
|
||||||
|
|
||||||
|
ssize_t limit
|
||||||
|
{
|
||||||
|
depth < 0?
|
||||||
|
std::abs(depth):
|
||||||
|
param.at(3, ssize_t(32))
|
||||||
};
|
};
|
||||||
|
|
||||||
const m::room room
|
const m::room room
|
||||||
|
@ -1907,10 +1919,10 @@ console_cmd__room__messages(opt &out, const string_view &line)
|
||||||
};
|
};
|
||||||
|
|
||||||
m::room::messages it{room};
|
m::room::messages it{room};
|
||||||
if(depth >= 0)
|
if(depth >= 0 && depth < std::numeric_limits<int64_t>::max())
|
||||||
it.seek(depth);
|
it.seek(depth);
|
||||||
|
|
||||||
for(; it; order == 'b'? --it : ++it)
|
for(; it && limit >= 0; order == 'b'? --it : ++it, --limit)
|
||||||
out << pretty_oneline(*it) << std::endl;
|
out << pretty_oneline(*it) << std::endl;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue