mirror of
https://github.com/matrix-construct/construct
synced 2025-01-15 17:16:49 +01:00
ircd:Ⓜ️:room::origins: Improve origins::random import definition.
This commit is contained in:
parent
7bcc40f13f
commit
43b8ea9de7
3 changed files with 19 additions and 16 deletions
|
@ -33,6 +33,7 @@ struct ircd::m::room::origins
|
|||
size_t count() const;
|
||||
|
||||
// select an origin in the room at random; use proffer to refuse and try another.
|
||||
static bool random(const origins &, const closure &, const closure_bool &);
|
||||
string_view random(const mutable_buffer &buf, const closure_bool &proffer = nullptr) const;
|
||||
bool random(const closure &, const closure_bool &proffer = nullptr) const;
|
||||
|
||||
|
|
|
@ -1861,16 +1861,22 @@ ircd::m::room::origins::random(const closure &view,
|
|||
const closure_bool &proffer)
|
||||
const
|
||||
{
|
||||
using prototype = bool (const m::room &,
|
||||
const m::room::origins::closure &,
|
||||
const m::room::origins::closure_bool &);
|
||||
return random(*this, view, proffer);
|
||||
}
|
||||
|
||||
static mods::import<prototype> random_origin
|
||||
bool
|
||||
ircd::m::room::origins::random(const origins &o,
|
||||
const closure &view,
|
||||
const closure_bool &proffer)
|
||||
{
|
||||
using prototype = bool (const origins &, const closure &, const closure_bool &);
|
||||
|
||||
static mods::import<prototype> call
|
||||
{
|
||||
"m_room", "random_origin"
|
||||
"m_room", "ircd::m::room::origins::random"
|
||||
};
|
||||
|
||||
return random_origin(room, view, proffer);
|
||||
return call(o, view, proffer);
|
||||
}
|
||||
|
||||
size_t
|
||||
|
|
|
@ -88,17 +88,13 @@ ircd::m::count_since(const m::room &room,
|
|||
return ret;
|
||||
}
|
||||
|
||||
extern "C" bool
|
||||
random_origin(const m::room &room,
|
||||
const m::room::origins::closure &view,
|
||||
const m::room::origins::closure_bool &proffer = nullptr)
|
||||
bool
|
||||
IRCD_MODULE_EXPORT
|
||||
ircd::m::room::origins::random(const origins &origins,
|
||||
const closure &view,
|
||||
const closure_bool &proffer)
|
||||
{
|
||||
bool ret{false};
|
||||
const m::room::origins origins
|
||||
{
|
||||
room
|
||||
};
|
||||
|
||||
const size_t max
|
||||
{
|
||||
origins.count()
|
||||
|
@ -112,7 +108,7 @@ random_origin(const m::room &room,
|
|||
ssize_t(rand::integer(0, max - 1))
|
||||
};
|
||||
|
||||
const m::room::origins::closure_bool closure{[&proffer, &view, &select]
|
||||
const closure_bool closure{[&proffer, &view, &select]
|
||||
(const string_view &origin)
|
||||
{
|
||||
if(select-- > 0)
|
||||
|
|
Loading…
Reference in a new issue