getSessionHooks method

Map<HookEvent, List<SessionDerivedHookMatcher>> getSessionHooks(
  1. String sessionId, {
  2. HookEvent? event,
})

Get all session hooks for a specific event (excluding function hooks).

Implementation

Map<HookEvent, List<SessionDerivedHookMatcher>> getSessionHooks(
  String sessionId, {
  HookEvent? event,
}) {
  final store = _stores[sessionId];
  if (store == null) return {};

  final result = <HookEvent, List<SessionDerivedHookMatcher>>{};

  List<SessionDerivedHookMatcher> convertMatchers(
    List<SessionHookMatcher> matchers,
  ) {
    return matchers.map((sm) {
      final nonFunctionHooks = sm.hooks
          .map((h) => h.hook)
          .where((h) => h is! FunctionHook)
          .toList();
      return SessionDerivedHookMatcher(
        matcher: sm.matcher,
        hooks: nonFunctionHooks,
        skillRoot: sm.skillRoot,
      );
    }).toList();
  }

  if (event != null) {
    final matchers = store.hooks[event];
    if (matchers != null) {
      result[event] = convertMatchers(matchers);
    }
  } else {
    for (final evt in hookEvents) {
      final matchers = store.hooks[evt];
      if (matchers != null) {
        result[evt] = convertMatchers(matchers);
      }
    }
  }

  return result;
}