mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 00:14:07 +01:00
ircd:Ⓜ️:events: Add a filtered iteration.
This commit is contained in:
parent
e57b85cb36
commit
1397091b7c
3 changed files with 51 additions and 1 deletions
|
@ -19,8 +19,10 @@ namespace ircd::m::events
|
||||||
// counts up from start
|
// counts up from start
|
||||||
bool for_each(const uint64_t &start, const id_closure_bool &);
|
bool for_each(const uint64_t &start, const id_closure_bool &);
|
||||||
bool for_each(const uint64_t &start, const closure_bool &);
|
bool for_each(const uint64_t &start, const closure_bool &);
|
||||||
|
bool for_each(const uint64_t &start, const event_filter &, const closure_bool &);
|
||||||
|
|
||||||
// -1 starts at newest event; counts down
|
// -1 starts at newest event; counts down
|
||||||
bool rfor_each(const uint64_t &start, const id_closure_bool &);
|
bool rfor_each(const uint64_t &start, const id_closure_bool &);
|
||||||
bool rfor_each(const uint64_t &start, const closure_bool &);
|
bool rfor_each(const uint64_t &start, const closure_bool &);
|
||||||
|
bool rfor_each(const uint64_t &start, const event_filter &, const closure_bool &);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,13 +61,13 @@ namespace ircd
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "user.h"
|
#include "user.h"
|
||||||
#include "rooms.h"
|
#include "rooms.h"
|
||||||
|
#include "filter.h"
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
#include "login.h"
|
#include "login.h"
|
||||||
#include "register.h"
|
#include "register.h"
|
||||||
#include "invite_3pid.h"
|
#include "invite_3pid.h"
|
||||||
#include "createroom.h"
|
#include "createroom.h"
|
||||||
#include "filter.h"
|
|
||||||
#include "request.h"
|
#include "request.h"
|
||||||
#include "v1/v1.h"
|
#include "v1/v1.h"
|
||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
|
|
48
ircd/m/m.cc
48
ircd/m/m.cc
|
@ -927,6 +927,30 @@ ircd::m::node::room::room(const m::node &node)
|
||||||
// m/events.h
|
// m/events.h
|
||||||
//
|
//
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::events::rfor_each(const uint64_t &start,
|
||||||
|
const event_filter &filter,
|
||||||
|
const closure_bool &closure)
|
||||||
|
{
|
||||||
|
uint limit
|
||||||
|
{
|
||||||
|
json::get<"limit"_>(filter)?: 32U
|
||||||
|
};
|
||||||
|
|
||||||
|
return rfor_each(start, [&filter, &closure, &limit]
|
||||||
|
(const event::idx &event_idx, const m::event &event)
|
||||||
|
-> bool
|
||||||
|
{
|
||||||
|
if(!match(filter, event))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if(!closure(event_idx, event))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return --limit;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::m::events::rfor_each(const uint64_t &start,
|
ircd::m::events::rfor_each(const uint64_t &start,
|
||||||
const closure_bool &closure)
|
const closure_bool &closure)
|
||||||
|
@ -977,6 +1001,30 @@ ircd::m::events::rfor_each(const uint64_t &start,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ircd::m::events::for_each(const uint64_t &start,
|
||||||
|
const event_filter &filter,
|
||||||
|
const closure_bool &closure)
|
||||||
|
{
|
||||||
|
uint limit
|
||||||
|
{
|
||||||
|
json::get<"limit"_>(filter)?: 32U
|
||||||
|
};
|
||||||
|
|
||||||
|
return for_each(start, [&filter, &closure, &limit]
|
||||||
|
(const event::idx &event_idx, const m::event &event)
|
||||||
|
-> bool
|
||||||
|
{
|
||||||
|
if(!match(filter, event))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if(!closure(event_idx, event))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return --limit;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::m::events::for_each(const uint64_t &start,
|
ircd::m::events::for_each(const uint64_t &start,
|
||||||
const closure_bool &closure)
|
const closure_bool &closure)
|
||||||
|
|
Loading…
Reference in a new issue