mirror of
https://github.com/matrix-org/matrix-hookshot.git
synced 2025-03-10 21:19:13 +00:00

* Refactor HookFilter to only support enabledEvents (and add a function to convert) * Convert connections to deprecate ignoreHooks * Update documentation * Split out EventHookCheckbox * Refactor frontend to support enableHooks only mode * drop old field name * changelog * Fix enabledHooks for widgets * Fixes across the board * Update test description * Cleanup * Fix HookFilter * Fixup checkboxes * Cleanup
32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
export class HookFilter<T extends string> {
|
|
static convertIgnoredHooksToEnabledHooks<T extends string>(explicitlyEnabledHooks: T[] = [], ignoredHooks: T[], defaultHooks: T[]): T[] {
|
|
const resultHookSet = new Set([
|
|
...explicitlyEnabledHooks,
|
|
...defaultHooks,
|
|
]);
|
|
|
|
// For each ignored hook, remove anything that matches.
|
|
for (const ignoredHook of ignoredHooks) {
|
|
resultHookSet.delete(ignoredHook);
|
|
// If the hook is a "root" hook name, remove all children.
|
|
for (const enabledHook of resultHookSet) {
|
|
if (enabledHook.startsWith(`${ignoredHook}.`)) {
|
|
resultHookSet.delete(enabledHook);
|
|
}
|
|
}
|
|
}
|
|
|
|
return [...resultHookSet];
|
|
}
|
|
|
|
constructor(
|
|
public enabledHooks: T[] = [],
|
|
) {
|
|
|
|
}
|
|
|
|
public shouldSkip(...hookName: T[]) {
|
|
// Should skip if all of the hook names are missing
|
|
return hookName.every(name => !this.enabledHooks.includes(name));
|
|
}
|
|
} |