diff --git a/include/ircd/m/hook.h b/include/ircd/m/hook.h index d3ea5238c..573257a52 100644 --- a/include/ircd/m/hook.h +++ b/include/ircd/m/hook.h @@ -66,6 +66,7 @@ struct ircd::m::hook::site std::multimap sender; std::multimap state_key; std::multimap type; + std::vector always; std::set hooks; friend class hook; diff --git a/ircd/m/m.cc b/ircd/m/m.cc index 22181e82f..ec82473ce 100644 --- a/ircd/m/m.cc +++ b/ircd/m/m.cc @@ -3094,7 +3094,11 @@ noexcept void ircd::m::hook::site::operator()(const event &event) { - std::set matching; //TODO: allocator + std::set 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));