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

ircd:Ⓜ️:events: Add a filtered iteration.

This commit is contained in:
Jason Volk 2018-04-19 13:48:45 -07:00
parent e57b85cb36
commit 1397091b7c
3 changed files with 51 additions and 1 deletions

View file

@ -19,8 +19,10 @@ namespace ircd::m::events
// counts up from start
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 event_filter &, const closure_bool &);
// -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 closure_bool &);
bool rfor_each(const uint64_t &start, const event_filter &, const closure_bool &);
}

View file

@ -61,13 +61,13 @@ namespace ircd
#include "room.h"
#include "user.h"
#include "rooms.h"
#include "filter.h"
#include "events.h"
#include "node.h"
#include "login.h"
#include "register.h"
#include "invite_3pid.h"
#include "createroom.h"
#include "filter.h"
#include "request.h"
#include "v1/v1.h"
#include "keys.h"

View file

@ -927,6 +927,30 @@ ircd::m::node::room::room(const m::node &node)
// 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
ircd::m::events::rfor_each(const uint64_t &start,
const closure_bool &closure)
@ -977,6 +1001,30 @@ ircd::m::events::rfor_each(const uint64_t &start,
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
ircd::m::events::for_each(const uint64_t &start,
const closure_bool &closure)