X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Fplugins%2Fhooks.service.ts;h=a6a444c326a4b3392f1cd651890c07894922b224;hb=8c7725dc3c01a73bf56a48c8b192d144bfdc3ffe;hp=24274183129ec55c5b5f26ab09ec624edc6a6bb3;hpb=c2023a9f027deb310248ad751cc96a21a8e1ed03;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 242741831..a6a444c32 100644 --- a/client/src/app/core/plugins/hooks.service.ts +++ b/client/src/app/core/plugins/hooks.service.ts @@ -18,11 +18,10 @@ export class HooksService { wrapObsFun - (fun: ObservableFunction, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) - { + (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)) ) @@ -30,11 +29,10 @@ export class HooksService { async wrapFun - (fun: RawFunction, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) - { + (fun: RawFunction, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) { await this.pluginService.ensurePluginsAreLoaded(scope) - const newParams = await this.wrapObject(params, hookParamName) + const newParams = await this.wrapObjectWithoutScopeLoad(params, hookParamName) const result = fun(newParams) return this.pluginService.runHook(hookResultName, result, params) @@ -46,7 +44,13 @@ export class HooksService { .catch((err: any) => console.error('Fatal hook error.', { err })) } - private wrapObject (result: T, hookName: U) { + 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) } }