0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-07 12:38:56 +02:00

ircd:Ⓜ️ Add room version query w/ console cmd.

This commit is contained in:
Jason Volk 2018-09-12 23:21:40 -07:00
parent 0695584d2c
commit 2ae2bb0eef
3 changed files with 52 additions and 0 deletions

View file

@ -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 &);

View file

@ -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)
{

View file

@ -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)
{