0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-01 19:22:53 +01:00

ircd:Ⓜ️:user::highlight: Add for_each() to interface; simplify stack (#87).

This commit is contained in:
Jason Volk 2019-08-12 04:10:28 -07:00
parent a4d61ba51b
commit 76889eab6e
2 changed files with 21 additions and 12 deletions

View file

@ -30,6 +30,7 @@ struct ircd::m::user::highlight
bool has(const event &) const; bool has(const event &) const;
bool has(const event::idx &) const; bool has(const event::idx &) const;
bool for_each(const m::room &, const event::idx_range &, const event::closure_idx_bool &) const;
size_t count_between(const m::room &, const event::idx_range &) const; size_t count_between(const m::room &, const event::idx_range &) const;
size_t count_to(const m::room &, const event::idx &) const; size_t count_to(const m::room &, const event::idx &) const;
size_t count(const m::room &) const; size_t count(const m::room &) const;

View file

@ -117,17 +117,27 @@ ircd::m::user::highlight::count_between(const m::room &room,
const event::idx_range &range) const event::idx_range &range)
const const
{ {
static const event::fetch::opts fopts{[] size_t ret(0);
for_each(room, range, [this, &ret]
(const m::event::idx &event_idx)
{ {
event::fetch::opts ret; ret += has(event_idx);
ret.keys = event::keys::include {"type", "content"}; return true;
ret.query_json_force = true; });
return ret;
}()};
return ret;
}
bool
IRCD_MODULE_EXPORT
ircd::m::user::highlight::for_each(const m::room &room,
const event::idx_range &range,
const event::closure_idx_bool &closure)
const
{
m::room::messages it m::room::messages it
{ {
room, &fopts room
}; };
assert(range.first <= range.second); assert(range.first <= range.second);
@ -150,13 +160,11 @@ const
string_view{user.user_id}, string_view{user.user_id},
}; };
size_t ret{0};
for(++it; it && it.event_idx() < range.second; ++it) for(++it; it && it.event_idx() < range.second; ++it)
ret += cached(it.event_idx(), fopts)? if(!closure(it.event_idx()))
has(*it): return false;
has(it.event_idx());
return ret; return true;
} }
bool bool