getSessionFunctionHooks method
Get all session function hooks for a specific event.
Implementation
Map<HookEvent, List<FunctionHookMatcher>> getSessionFunctionHooks(
String sessionId, {
HookEvent? event,
}) {
final store = _stores[sessionId];
if (store == null) return {};
final result = <HookEvent, List<FunctionHookMatcher>>{};
List<FunctionHookMatcher> extractFunctionHooks(
List<SessionHookMatcher> matchers,
) {
return matchers
.map((sm) {
final funcHooks = sm.hooks
.map((h) => h.hook)
.whereType<FunctionHook>()
.toList();
return FunctionHookMatcher(matcher: sm.matcher, hooks: funcHooks);
})
.where((m) => m.hooks.isNotEmpty)
.toList();
}
if (event != null) {
final matchers = store.hooks[event];
if (matchers != null) {
final funcMatchers = extractFunctionHooks(matchers);
if (funcMatchers.isNotEmpty) {
result[event] = funcMatchers;
}
}
} else {
for (final evt in hookEvents) {
final matchers = store.hooks[evt];
if (matchers != null) {
final funcMatchers = extractFunctionHooks(matchers);
if (funcMatchers.isNotEmpty) {
result[evt] = funcMatchers;
}
}
}
}
return result;
}