mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 18:22:50 +01:00
ircd:Ⓜ️ Improve room::membership() convenience query interface.
This commit is contained in:
parent
59cad48ce5
commit
c31b072a82
2 changed files with 13 additions and 3 deletions
|
@ -107,6 +107,7 @@ struct ircd::m::room
|
|||
|
||||
// misc
|
||||
bool membership(const m::id::user &, const string_view &membership = "join") const;
|
||||
string_view membership(const mutable_buffer &out, const m::id::user &) const;
|
||||
|
||||
room(const id &room_id, const event::id &event_id = {})
|
||||
:room_id{room_id}
|
||||
|
|
|
@ -109,13 +109,22 @@ ircd::m::room::membership(const m::id::user &user_id,
|
|||
const string_view &membership)
|
||||
const
|
||||
{
|
||||
bool ret{false};
|
||||
char buf[64];
|
||||
return this->membership(buf, user_id) == membership;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::m::room::membership(const mutable_buffer &out,
|
||||
const m::id::user &user_id)
|
||||
const
|
||||
{
|
||||
string_view ret;
|
||||
const state state{*this};
|
||||
state.get(std::nothrow, "m.room.member"_sv, user_id, [&membership, &ret]
|
||||
state.get(std::nothrow, "m.room.member"_sv, user_id, [&out, &ret]
|
||||
(const m::event &event)
|
||||
{
|
||||
assert(json::get<"type"_>(event) == "m.room.member");
|
||||
ret = unquote(at<"membership"_>(event)) == membership;
|
||||
ret = { data(out), copy(out, unquote(at<"membership"_>(event))) };
|
||||
});
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Reference in a new issue