From 0721d282542e3dd2697a513fa354218613cdc834 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 26 Feb 2018 00:25:48 -0800 Subject: [PATCH] ircd::m::hook: Minor cleanup: move event_match function to hook::. --- include/ircd/m/hook.h | 1 + ircd/m/m.cc | 65 ++++++++++++++++++++++--------------------- 2 files changed, 35 insertions(+), 31 deletions(-) diff --git a/include/ircd/m/hook.h b/include/ircd/m/hook.h index 2dfc32f63..64d89e884 100644 --- a/include/ircd/m/hook.h +++ b/include/ircd/m/hook.h @@ -32,6 +32,7 @@ struct ircd::m::hook bool registered; string_view site_name() const; + bool match(const m::event &) const; public: hook(const json::members &, decltype(function)); diff --git a/ircd/m/m.cc b/ircd/m/m.cc index 77bc0cf14..a90bcacbb 100644 --- a/ircd/m/m.cc +++ b/ircd/m/m.cc @@ -517,6 +517,38 @@ catch(const std::out_of_range &e) }; } +bool +ircd::m::hook::match(const m::event &event) +const +{ + if(json::get<"origin"_>(matching)) + if(at<"origin"_>(matching) != at<"origin"_>(event)) + return false; + + if(json::get<"room_id"_>(matching)) + if(at<"room_id"_>(matching) != at<"room_id"_>(event)) + return false; + + if(json::get<"sender"_>(matching)) + if(at<"sender"_>(matching) != at<"sender"_>(event)) + return false; + + if(json::get<"type"_>(matching)) + if(at<"type"_>(matching) != at<"type"_>(event)) + return false; + + if(json::get<"state_key"_>(matching)) + if(at<"state_key"_>(matching) != json::get<"state_key"_>(event)) + return false; + + if(json::get<"membership"_>(matching)) + if(at<"membership"_>(matching) != json::get<"membership"_>(event)) + return false; + + return true; +} + + // // hook::site // @@ -569,40 +601,11 @@ ircd::m::hook::site::operator()(const event &event) if(json::get<"state_key"_>(event)) site_match(state_key, at<"state_key"_>(event)); - const auto event_match{[&event](const hook &hook) - { - if(json::get<"origin"_>(hook.matching)) - if(at<"origin"_>(hook.matching) != at<"origin"_>(event)) - return false; - - if(json::get<"room_id"_>(hook.matching)) - if(at<"room_id"_>(hook.matching) != at<"room_id"_>(event)) - return false; - - if(json::get<"sender"_>(hook.matching)) - if(at<"sender"_>(hook.matching) != at<"sender"_>(event)) - return false; - - if(json::get<"type"_>(hook.matching)) - if(at<"type"_>(hook.matching) != at<"type"_>(event)) - return false; - - if(json::get<"state_key"_>(hook.matching)) - if(at<"state_key"_>(hook.matching) != json::get<"state_key"_>(event)) - return false; - - if(json::get<"membership"_>(hook.matching)) - if(at<"membership"_>(hook.matching) != json::get<"membership"_>(event)) - return false; - - return true; - }}; - auto it(begin(matching)); while(it != end(matching)) { - const auto *const &hook(*it); - if(!event_match(*hook)) + const hook &hook(**it); + if(!hook.match(event)) it = matching.erase(it); else ++it;