0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 15:04:10 +01:00

modules/m_room_aliases: Move for_each impl to module.

This commit is contained in:
Jason Volk 2019-03-30 16:02:40 -07:00
parent 317fa612fb
commit 276ba9941d
3 changed files with 67 additions and 31 deletions

View file

@ -20,8 +20,11 @@ struct ircd::m::room::aliases
{
using closure_bool = std::function<bool (const alias &)>;
static bool for_each(const m::room &, const string_view &server, const closure_bool &);
m::room room;
public:
bool for_each(const string_view &server, const closure_bool &) const;
bool for_each(const closure_bool &) const;
bool has(const alias &) const;

View file

@ -2420,40 +2420,22 @@ const
if(!server)
return for_each(closure);
const room::state state
return for_each(room, server, closure);
}
bool
ircd::m::room::aliases::for_each(const m::room &room,
const string_view &server,
const closure_bool &closure)
{
using prototype = bool (const m::room &, const string_view &, const closure_bool &);
static mods::import<prototype> call
{
room
"m_room_aliases", "ircd::m::room::aliases::for_each"
};
const event::idx &event_idx
{
state.get(std::nothrow, "m.room.aliases", server)
};
if(!event_idx)
return true;
bool ret{true};
m::get(std::nothrow, event_idx, "content", [&closure, &ret]
(const json::object &content)
{
const json::array &aliases
{
content["aliases"]
};
for(auto it(begin(aliases)); it != end(aliases) && ret; ++it)
{
const json::string &alias(*it);
if(!valid(m::id::ROOM_ALIAS, alias))
continue;
if(!closure(alias))
ret = false;
}
});
return ret;
return call(room, server, closure);
}
//

View file

@ -28,6 +28,57 @@ alias_room
alias_room_id
};
//
// m::room::aliases impl
//
bool
IRCD_MODULE_EXPORT
ircd::m::room::aliases::for_each(const m::room &room,
const string_view &server,
const closure_bool &closure)
{
const room::state state
{
room
};
assert(server);
const event::idx &event_idx
{
state.get(std::nothrow, "m.room.aliases", server)
};
if(!event_idx)
return true;
bool ret{true};
m::get(std::nothrow, event_idx, "content", [&closure, &ret]
(const json::object &content)
{
const json::array &aliases
{
content["aliases"]
};
for(auto it(begin(aliases)); it != end(aliases) && ret; ++it)
{
const json::string &alias(*it);
if(!valid(m::id::ROOM_ALIAS, alias))
continue;
if(!closure(alias))
ret = false;
}
});
return ret;
}
//
// hook handlers
//
void
_changed_aliases(const m::event &event,
m::vm::eval &)