mirror of
https://github.com/matrix-construct/construct
synced 2024-11-16 15:00:51 +01:00
modules/console: Update room count w/ standard event_filter jsons.
This commit is contained in:
parent
38d15a7f0c
commit
9168477e69
1 changed files with 18 additions and 9 deletions
|
@ -2648,14 +2648,19 @@ console_cmd__room__state(opt &out, const string_view &line)
|
||||||
bool
|
bool
|
||||||
console_cmd__room__count(opt &out, const string_view &line)
|
console_cmd__room__count(opt &out, const string_view &line)
|
||||||
{
|
{
|
||||||
|
const params param{line, " ",
|
||||||
|
{
|
||||||
|
"room_id", "{event_filter_json}"
|
||||||
|
}};
|
||||||
|
|
||||||
const auto &room_id
|
const auto &room_id
|
||||||
{
|
{
|
||||||
m::room_id(token(line, ' ', 0))
|
m::room_id(param.at(0))
|
||||||
};
|
};
|
||||||
|
|
||||||
const string_view &type
|
const m::event_filter filter
|
||||||
{
|
{
|
||||||
token_count(line, ' ') > 1? token(line, ' ', 1) : string_view{}
|
param[1]
|
||||||
};
|
};
|
||||||
|
|
||||||
const m::room room
|
const m::room room
|
||||||
|
@ -2663,16 +2668,20 @@ console_cmd__room__count(opt &out, const string_view &line)
|
||||||
room_id
|
room_id
|
||||||
};
|
};
|
||||||
|
|
||||||
const m::room::state state
|
auto limit
|
||||||
{
|
{
|
||||||
room
|
json::get<"limit"_>(filter)?: -1
|
||||||
};
|
};
|
||||||
|
|
||||||
if(type)
|
size_t count{0};
|
||||||
out << state.count(type) << std::endl;
|
m::room::messages it{room};
|
||||||
else
|
for(; it && limit; --it, --limit)
|
||||||
out << state.count() << std::endl;
|
{
|
||||||
|
const m::event &event{*it};
|
||||||
|
count += match(filter, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
out << count << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue