0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd:Ⓜ️:room: Start a spec faithful display_name(room) diagnostic.

This commit is contained in:
Jason Volk 2019-08-25 15:55:47 -07:00
parent 42b689a7a0
commit 885499ad99
3 changed files with 95 additions and 1 deletions

View file

@ -44,6 +44,7 @@ namespace ircd::m
string_view version(const mutable_buffer &, const room &);
string_view join_rule(const mutable_buffer &out, const room &);
string_view membership(const mutable_buffer &out, const room &, const m::id::user &);
string_view display_name(const mutable_buffer &out, const room &);
id::user::buf any_user(const room &, const string_view &host, const string_view &memshp = "join");
id::room room_id(const mutable_buffer &, const id::room_alias &);

View file

@ -7842,7 +7842,7 @@ console_cmd__room__top(opt &out, const string_view &line)
out << std::endl;
char version_buf[32];
char version_buf[32], display_buf[256];
out << "index: " << m::room::index(room_id) << std::endl;
out << "version: " << m::version(version_buf, room_id) << std::endl;
out << "federated: " << std::boolalpha << m::federated(room_id) << std::endl;
@ -7858,6 +7858,7 @@ console_cmd__room__top(opt &out, const string_view &line)
out << "top depth: " << std::get<int64_t>(top) << std::endl;
out << "top index: " << std::get<m::event::idx>(top) << std::endl;
out << "top event: " << std::get<m::event::id::buf>(top) << std::endl;
out << "display name: " << m::display_name(display_buf, room_id) << std::endl;
return true;
}

View file

@ -18,3 +18,95 @@ IRCD_MODULE
{
"Matrix room library"
};
ircd::string_view
IRCD_MODULE_EXPORT
ircd::m::display_name(const mutable_buffer &out,
const room &room)
{
const room::state state
{
room
};
// 1. If the room has an m.room.name state event with a non-empty name
// field, use the name given by that field.
string_view ret;
{
const event::idx event_idx
{
state.get(std::nothrow, "m.room.name", "")
};
m::get(std::nothrow, event_idx, "content", [&out, &ret]
(const json::object &content)
{
const json::string &name
{
content.get("name")
};
ret = strlcpy
{
out, name
};
});
}
// 2. If the room has an m.room.canonical_alias state event with a
// non-empty alias field, use the alias given by that field as the name.
if(!ret)
{
const event::idx event_idx
{
state.get(std::nothrow, "m.room.canonical_alias", "")
};
m::get(std::nothrow, event_idx, "content", [&out, &ret]
(const json::object &content)
{
const json::string &alias
{
content.get("alias")
};
ret = strlcpy
{
out, alias
};
});
}
// 3. If neither of the above conditions are met, the client can optionally
// guess an alias from the m.room.alias events in the room. This is a
// temporary measure while clients do not promote canonical aliases as
// prominently. This step may be removed in a future version of the
// specification.
// 4. If none of the above conditions are met, a name should be composed
// based on the members of the room. Clients should consider m.room.member
// events for users other than the logged-in user, as defined below.
// i. If the number of m.heroes for the room are greater or equal to
// m.joined_member_count + m.invited_member_count - 1, then use the
// membership events for the heroes to calculate display names for the
// users (disambiguating them if required) and concatenating them. For
// example, the client may choose to show "Alice, Bob, and Charlie
// (@charlie:example.org)" as the room name. The client may optionally
// limit the number of users it uses to generate a room name.
// ii. If there are fewer heroes than m.joined_member_count +
// m.invited_member_count - 1, and m.joined_member_count +
// m.invited_member_count is greater than 1, the client should use the
// heroes to calculate display names for the users (disambiguating them if
// required) and concatenating them alongside a count of the remaining
// users. For example, "Alice, Bob, and 1234 others".
// iii. If m.joined_member_count + m.invited_member_count is less than or
// equal to 1 (indicating the member is alone), the client should use the
// rules above to indicate that the room was empty. For example, "Empty Room
// (was Alice)", "Empty Room (was Alice and 1234 others)", or "Empty Room"
// if there are no heroes.
return ret;
}