mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd:Ⓜ️:room Update version query based on spec room version grammar (string type).
This commit is contained in:
parent
dd961fc53d
commit
85c041c27b
3 changed files with 36 additions and 24 deletions
|
@ -34,10 +34,11 @@ 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 &);
|
||||
bool federate(const id::room &);
|
||||
id::user::buf creator(const id::room &);
|
||||
bool creator(const id::room &, const id::user &);
|
||||
string_view version(const mutable_buffer &, const room &, std::nothrow_t);
|
||||
string_view version(const mutable_buffer &, const room &);
|
||||
|
||||
// [GET]
|
||||
id::room room_id(const mutable_buffer &, const id::room_alias &);
|
||||
|
|
|
@ -134,34 +134,43 @@ ircd::m::top(std::nothrow_t,
|
|||
return ret;
|
||||
}
|
||||
|
||||
uint
|
||||
ircd::m::version(const id::room &room_id)
|
||||
ircd::string_view
|
||||
ircd::m::version(const mutable_buffer &buf,
|
||||
const room &room)
|
||||
{
|
||||
static const m::event::fetch::opts fopts
|
||||
const auto ret
|
||||
{
|
||||
event::keys::include
|
||||
{
|
||||
"content",
|
||||
}
|
||||
version(buf, room, std::nothrow)
|
||||
};
|
||||
|
||||
const m::room::state state
|
||||
{
|
||||
room_id, &fopts
|
||||
};
|
||||
|
||||
uint ret;
|
||||
state.get("m.room.create", "", [&ret]
|
||||
(const m::event &event)
|
||||
{
|
||||
const auto version_string
|
||||
if(!ret)
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
unquote(json::get<"content"_>(event).get("version", "1"))
|
||||
"Failed to find room %s to query its version",
|
||||
string_view{room.room_id}
|
||||
};
|
||||
|
||||
ret = version_string?
|
||||
lex_cast<uint>(version_string):
|
||||
1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::version(const mutable_buffer &buf,
|
||||
const room &room,
|
||||
std::nothrow_t)
|
||||
{
|
||||
string_view ret;
|
||||
const auto event_idx
|
||||
{
|
||||
room.get(std::nothrow, "m.room.create", "")
|
||||
};
|
||||
|
||||
if(!event_idx)
|
||||
return ret;
|
||||
|
||||
m::get(std::nothrow, event_idx, "content", [&ret]
|
||||
(const json::object &content)
|
||||
{
|
||||
ret = unquote(content.get("version", "1"));
|
||||
});
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -6683,8 +6683,9 @@ console_cmd__room__top(opt &out, const string_view &line)
|
|||
room_id
|
||||
};
|
||||
|
||||
char version_buf[32];
|
||||
out << "index: " << m::room::index(room_id) << std::endl;
|
||||
out << "version: " << m::version(room_id) << std::endl;
|
||||
out << "version: " << m::version(version_buf, room_id) << std::endl;
|
||||
out << "federate: " << std::boolalpha << m::federate(room_id) << std::endl;
|
||||
out << "top index: " << std::get<m::event::idx>(top) << std::endl;
|
||||
out << "top depth: " << std::get<int64_t>(top) << std::endl;
|
||||
|
@ -6737,7 +6738,8 @@ console_cmd__room__version(opt &out, const string_view &line)
|
|||
m::room_id(param.at(0))
|
||||
};
|
||||
|
||||
out << m::version(room_id) << std::endl;
|
||||
char buf[32];
|
||||
out << m::version(buf, room_id) << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue