0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 23:44:01 +01:00

ircd:Ⓜ️:room Update version query based on spec room version grammar (string type).

This commit is contained in:
Jason Volk 2019-03-06 11:03:06 -08:00
parent dd961fc53d
commit 85c041c27b
3 changed files with 36 additions and 24 deletions

View file

@ -34,10 +34,11 @@ namespace ircd::m
bool exists(const room &); bool exists(const room &);
bool exists(const id::room &); bool exists(const id::room &);
bool exists(const id::room_alias &, const bool &remote = false); bool exists(const id::room_alias &, const bool &remote = false);
uint version(const id::room &);
bool federate(const id::room &); bool federate(const id::room &);
id::user::buf creator(const id::room &); id::user::buf creator(const id::room &);
bool creator(const id::room &, const id::user &); 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] // [GET]
id::room room_id(const mutable_buffer &, const id::room_alias &); id::room room_id(const mutable_buffer &, const id::room_alias &);

View file

@ -134,34 +134,43 @@ ircd::m::top(std::nothrow_t,
return ret; return ret;
} }
uint ircd::string_view
ircd::m::version(const id::room &room_id) ircd::m::version(const mutable_buffer &buf,
const room &room)
{ {
static const m::event::fetch::opts fopts const auto ret
{ {
event::keys::include version(buf, room, std::nothrow)
{
"content",
}
}; };
const m::room::state state if(!ret)
{ throw m::NOT_FOUND
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")) "Failed to find room %s to query its version",
string_view{room.room_id}
}; };
ret = version_string? return ret;
lex_cast<uint>(version_string): }
1;
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; return ret;

View file

@ -6683,8 +6683,9 @@ console_cmd__room__top(opt &out, const string_view &line)
room_id room_id
}; };
char version_buf[32];
out << "index: " << m::room::index(room_id) << std::endl; 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 << "federate: " << std::boolalpha << m::federate(room_id) << std::endl;
out << "top index: " << std::get<m::event::idx>(top) << std::endl; out << "top index: " << std::get<m::event::idx>(top) << std::endl;
out << "top depth: " << std::get<int64_t>(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)) 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; return true;
} }