X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Fplugins%2Fhooks.service.ts;h=a6a444c326a4b3392f1cd651890c07894922b224;hb=0912f1b4caaa7394516567044f896132ad991131;hp=93dac1167cdecb8d6ee009089a8b5ea99c0652a8;hpb=23bdacf8ec24ce47a15529830e116911d7478598;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/plugins/hooks.service.ts b/client/src/app/core/plugins/hooks.service.ts index 93dac1167..a6a444c32 100644 --- a/client/src/app/core/plugins/hooks.service.ts +++ b/client/src/app/core/plugins/hooks.service.ts @@ -16,25 +16,26 @@ export class HooksService { private pluginService: PluginService ) { } - wrapObject (result: T, hookName: U) { - return this.pluginService.runHook(hookName, result) - } - wrapObsFun (fun: ObservableFunction, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) { return from(this.pluginService.ensurePluginsAreLoaded(scope)) .pipe( - mergeMap(() => this.wrapObject(params, hookParamName)), + mergeMap(() => this.wrapObjectWithoutScopeLoad(params, hookParamName)), switchMap(params => fun(params)), mergeMap(result => this.pluginService.runHook(hookResultName, result, params)) ) } - async wrapFun (fun: RawFunction, params: U, hookName: V) { - const result = fun(params) + async wrapFun + + (fun: RawFunction, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) { + await this.pluginService.ensurePluginsAreLoaded(scope) + + const newParams = await this.wrapObjectWithoutScopeLoad(params, hookParamName) + const result = fun(newParams) - return this.pluginService.runHook(hookName, result, params) + return this.pluginService.runHook(hookResultName, result, params) } runAction (hookName: U, scope: PluginClientScope, params?: T) { @@ -42,4 +43,14 @@ export class HooksService { .then(() => this.pluginService.runHook(hookName, undefined, params)) .catch((err: any) => console.error('Fatal hook error.', { err })) } + + async wrapObject (result: T, scope: PluginClientScope, hookName: U) { + await this.pluginService.ensurePluginsAreLoaded(scope) + + return this.wrapObjectWithoutScopeLoad(result, hookName) + } + + private wrapObjectWithoutScopeLoad (result: T, hookName: U) { + return this.pluginService.runHook(hookName, result) + } }