0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-11 06:28:55 +02:00

ircd:Ⓜ️🪝 Add the always matching vector.

This commit is contained in:
Jason Volk 2018-05-12 19:58:08 -07:00
parent 1cea146098
commit 77d2c06ded
2 changed files with 14 additions and 1 deletions

View file

@ -66,6 +66,7 @@ struct ircd::m::hook::site
std::multimap<string_view, hook *> sender;
std::multimap<string_view, hook *> state_key;
std::multimap<string_view, hook *> type;
std::vector<hook *> always;
std::set<hook *> hooks;
friend class hook;

View file

@ -3094,7 +3094,11 @@ noexcept
void
ircd::m::hook::site::operator()(const event &event)
{
std::set<hook *> matching; //TODO: allocator
std::set<hook *> matching //TODO: allocator
{
begin(always), end(always)
};
const auto site_match{[&matching]
(auto &map, const string_view &key)
{
@ -3190,6 +3194,11 @@ ircd::m::hook::site::add(hook &hook)
if(json::get<"type"_>(hook.matching))
map(type, at<"type"_>(hook.matching));
// Hook had no mappings which means it will match everything.
// We don't increment the matcher count for this case.
if(!hook.matchers)
always.emplace_back(&hook);
++count;
hook.registered = true;
return true;
@ -3216,6 +3225,9 @@ ircd::m::hook::site::del(hook &hook)
return end(map);
}};
// Unconditional attempt to remove from always.
std::remove(begin(always), end(always), &hook);
if(json::get<"origin"_>(hook.matching))
unmap(origin, at<"origin"_>(hook.matching));