0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-16 17:08:20 +02:00

imrcd:Ⓜ️:room::members: Add empty() to interface.

This commit is contained in:
Jason Volk 2019-07-19 13:56:08 -07:00
parent 4de54ff00d
commit bdc88e6c7e
2 changed files with 61 additions and 0 deletions

View file

@ -37,6 +37,9 @@ struct ircd::m::room::members
bool for_each(const closure_bool &) const;
void for_each(const closure &) const;
bool empty(const string_view &membership) const;
bool empty() const;
size_t count(const string_view &membership) const;
size_t count() const;

View file

@ -3129,6 +3129,64 @@ ircd::m::room::state::space::rebuild::rebuild()
// room::members
//
bool
ircd::m::room::members::empty()
const
{
const room::state state
{
room
};
// for_each() returns true when it reaches the end of the iteration.
return state.for_each("m.room.member", state::closure_bool{[]
(const auto &type, const auto &state_key, const auto &event_idx)
{
return false;
}});
}
bool
ircd::m::room::members::empty(const string_view &membership)
const
{
const room::state state
{
room
};
// joined members optimization. Only possible when seeking
// membership="join" on the present state of the room.
if(membership == "join" && state.present())
{
// _for_each() returns true when it reaches the end of the iteration.
const room::origins origins{room};
return origins._for_each(origins, []
(const string_view &)
{
// closure returns false to break causing _for_each() to return false.
return false;
});
}
// for_each() returns true when it reaches the end of the iteration.
return state.for_each("m.room.member", state::closure_bool{[&membership]
(const auto &type, const auto &state_key, const auto &event_idx)
{
// return false if the query succeeds, breaking the iteration.
return !m::query(std::nothrow, event_idx, "content", [&membership]
(const json::object &content)
{
const json::string &content_membership
{
content["membership"]
};
return !membership || content_membership == membership;
});
}});
}
size_t
ircd::m::room::members::count()
const