0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-13 07:28:58 +02:00

modules/console: Add room text cmd.

This commit is contained in:
Jason Volk 2022-08-15 17:24:25 -07:00
parent 727749e9de
commit f06be9ac8e

View file

@ -11547,6 +11547,68 @@ console_cmd__room__messages(opt &out, const string_view &line)
return true;
}
bool
console_cmd__room__text(opt &out, const string_view &line)
{
const params param{line, " ",
{
"room_id", "start_depth", "end_depth", "limit"
}};
const auto &room_id
{
m::room_id(param.at(0))
};
const int64_t start_depth
{
param.at<int64_t>("start_depth", std::numeric_limits<int64_t>::max())
};
const int64_t end_depth
{
param.at<int64_t>("end_depth", -1)
};
const auto limit
{
start_depth == std::numeric_limits<int64_t>::max()?
param.at("limit", 48U): -1U
};
const m::room::messages messages
{
room_id, { start_depth, end_depth },
};
size_t i(0);
messages.for_each([&out, &i, &limit]
(const m::room::message &msg, const uint64_t &depth, m::event::idx event_idx)
{
if(json::get<"msgtype"_>(msg) != "m.text")
return true;
long ots {0};
m::get<long>(event_idx, "origin_server_ts", ots);
char buf[1][48];
out
<< std::setw(9) << std::right << event_idx
<< ' '
<< std::setw(7) << std::right << depth
<< ' '
<< std::setw(8) << ago(buf[0], system_point(milliseconds(ots)), 0x3)
<< " <"
<< m::get(std::nothrow, event_idx, "sender")
<< "> "
<< msg.body()
<< std::endl;
return ++i < limit;
});
return true;
}
bool
console_cmd__room__type(opt &out, const string_view &line)
{