0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-25 21:38:18 +02:00

ircd:Ⓜ️:room: Add basic count() suite.

This commit is contained in:
Jason Volk 2019-08-18 08:07:38 -07:00
parent 7016241df2
commit e38371d50c
2 changed files with 54 additions and 0 deletions

View file

@ -156,6 +156,9 @@ struct ircd::m::room
void get(const string_view &type, const event::closure &) const;
event::idx get(std::nothrow_t, const string_view &type) const;
event::idx get(const string_view &type) const;
size_t count(const string_view &type, const string_view &state_key) const;
size_t count(const string_view &type) const;
size_t count() const;
room(const id &room_id,
const string_view &event_id,

View file

@ -1400,6 +1400,57 @@ ircd::m::room::index(const room::id &room_id,
// room::room
//
size_t
ircd::m::room::count()
const
{
size_t ret(0);
for_each(event::closure_idx_bool{[&ret]
(const event::idx &event_idx)
{
++ret;
return true;
}});
return ret;
}
size_t
ircd::m::room::count(const string_view &type)
const
{
size_t ret(0);
for_each(type, event::closure_idx_bool{[&ret]
(const event::idx &event_idx)
{
++ret;
return true;
}});
return ret;
}
size_t
ircd::m::room::count(const string_view &type,
const string_view &state_key)
const
{
size_t ret(0);
for_each(type, event::closure_idx_bool{[&state_key, &ret]
(const event::idx &event_idx)
{
ret += query(std::nothrow, event_idx, "state_key", [&state_key]
(const string_view &_state_key) -> bool
{
return state_key == _state_key;
});
return true;
}});
return ret;
}
bool
ircd::m::room::has(const string_view &type)
const