diff --git a/modules/console.cc b/modules/console.cc index a2f7f85b5..17d9fa712 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -5241,6 +5241,52 @@ console_cmd__room__events(opt &out, const string_view &line) return true; } +bool +console_cmd__room__messages(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "room_id", "depth|-limit", "order", "limit" + }}; + + const auto &room_id + { + m::room_id(param.at(0)) + }; + + const int64_t depth + { + param.at(1, std::numeric_limits::max()) + }; + + const char order + { + 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 + { + room_id + }; + + m::room::messages it{room}; + if(depth >= 0 && depth < std::numeric_limits::max()) + it.seek(depth); + + for(; it && limit >= 0; order == 'b'? --it : ++it, --limit) + out << pretty_msgline(*it) + << std::endl; + + return true; +} + bool console_cmd__room__roots(opt &out, const string_view &line) {