mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd:Ⓜ️ Add room version query w/ console cmd.
This commit is contained in:
parent
0695584d2c
commit
2ae2bb0eef
3 changed files with 52 additions and 0 deletions
|
@ -28,6 +28,7 @@ namespace ircd::m
|
|||
bool exists(const room &);
|
||||
bool exists(const id::room &);
|
||||
bool exists(const id::room_alias &, const bool &remote = false);
|
||||
uint version(const id::room &);
|
||||
|
||||
// [GET]
|
||||
id::room room_id(const mutable_buffer &, const id::room_alias &);
|
||||
|
|
|
@ -134,6 +134,39 @@ ircd::m::top(std::nothrow_t,
|
|||
return ret;
|
||||
}
|
||||
|
||||
uint
|
||||
ircd::m::version(const id::room &room_id)
|
||||
{
|
||||
static const m::event::fetch::opts fopts
|
||||
{
|
||||
event::keys::include
|
||||
{
|
||||
"content",
|
||||
}
|
||||
};
|
||||
|
||||
const m::room::state state
|
||||
{
|
||||
room_id, &fopts
|
||||
};
|
||||
|
||||
uint ret;
|
||||
state.get("m.room.create", "", [&ret]
|
||||
(const m::event &event)
|
||||
{
|
||||
const auto version_string
|
||||
{
|
||||
unquote(json::get<"content"_>(event).get("version", "1"))
|
||||
};
|
||||
|
||||
ret = version_string?
|
||||
lex_cast<uint>(version_string):
|
||||
1;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::exists(const id::room &room_id)
|
||||
{
|
||||
|
|
|
@ -4407,6 +4407,7 @@ console_cmd__room__top(opt &out, const string_view &line)
|
|||
out << "idx: " << std::get<m::event::idx>(top) << std::endl;
|
||||
out << "depth: " << std::get<int64_t>(top) << std::endl;
|
||||
out << "event: " << std::get<m::event::id::buf>(top) << std::endl;
|
||||
out << "version: " << m::version(room_id) << std::endl;
|
||||
out << "m_state: " << std::endl;
|
||||
|
||||
const m::room::state state
|
||||
|
@ -4442,6 +4443,23 @@ console_id__room(opt &out,
|
|||
return console_cmd__room__top(out, line);
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__room__version(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"room_id",
|
||||
}};
|
||||
|
||||
const auto &room_id
|
||||
{
|
||||
m::room_id(param.at(0))
|
||||
};
|
||||
|
||||
out << m::version(room_id) << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__room__head(opt &out, const string_view &line)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue