diff --git a/spec/integ/sliding-sync.spec.ts b/spec/integ/sliding-sync.spec.ts index 5066329c2..29cd3443b 100644 --- a/spec/integ/sliding-sync.spec.ts +++ b/spec/integ/sliding-sync.spec.ts @@ -107,8 +107,8 @@ describe("SlidingSync", () => { onRequest: (initial) => { return { initial: initial }; }, - onResponse: (res) => { - return {}; + onResponse: async (res) => { + return; }, when: () => ExtensionState.PreProcess, }; @@ -1572,7 +1572,7 @@ describe("SlidingSync", () => { onPreExtensionRequest = () => { return extReq; }; - onPreExtensionResponse = (resp) => { + onPreExtensionResponse = async (resp) => { extensionOnResponseCalled = true; callbackOrder.push("onPreExtensionResponse"); expect(resp).toEqual(extResp); @@ -1613,7 +1613,7 @@ describe("SlidingSync", () => { return undefined; }; let responseCalled = false; - onPreExtensionResponse = (resp) => { + onPreExtensionResponse = async (resp) => { responseCalled = true; }; httpBackend! @@ -1649,7 +1649,7 @@ describe("SlidingSync", () => { }; let responseCalled = false; const callbackOrder: string[] = []; - onPostExtensionResponse = (resp) => { + onPostExtensionResponse = async (resp) => { expect(resp).toEqual(extResp); responseCalled = true; callbackOrder.push("onPostExtensionResponse"); diff --git a/src/sliding-sync-sdk.ts b/src/sliding-sync-sdk.ts index 2b3399664..e5a371e14 100644 --- a/src/sliding-sync-sdk.ts +++ b/src/sliding-sync-sdk.ts @@ -218,7 +218,7 @@ class ExtensionAccountData implements Extension { if (data.global && data.global.length > 0) { this.processGlobalAccountData(data.global); } @@ -288,7 +288,7 @@ class ExtensionTyping implements Extension { if (!data?.rooms) { return; } @@ -327,7 +327,7 @@ class ExtensionReceipts implements Extension { if (!data?.rooms) { return; } diff --git a/src/sliding-sync.ts b/src/sliding-sync.ts index a45a142d5..12da3d704 100644 --- a/src/sliding-sync.ts +++ b/src/sliding-sync.ts @@ -282,7 +282,7 @@ export interface Extension { * A function which is called when there is response JSON under this extension. * @param data - The response JSON under the extension name. */ - onResponse(data: Res): void; + onResponse(data: Res): Promise; /** * Controls when onResponse should be called. * @returns The state when it should be called. @@ -546,20 +546,24 @@ export class SlidingSync extends TypedEventEmitter): void { - Object.keys(ext).forEach((extName) => { - if (this.extensions[extName].when() == ExtensionState.PreProcess) { - this.extensions[extName].onResponse(ext[extName]); - } - }); + private async onPreExtensionsResponse(ext: Record): Promise { + await Promise.all( + Object.keys(ext).map(async (extName) => { + if (this.extensions[extName].when() == ExtensionState.PreProcess) { + await this.extensions[extName].onResponse(ext[extName]); + } + }), + ); } - private onPostExtensionsResponse(ext: Record): void { - Object.keys(ext).forEach((extName) => { - if (this.extensions[extName].when() == ExtensionState.PostProcess) { - this.extensions[extName].onResponse(ext[extName]); - } - }); + private async onPostExtensionsResponse(ext: Record): Promise { + await Promise.all( + Object.keys(ext).map(async (extName) => { + if (this.extensions[extName].when() == ExtensionState.PostProcess) { + await this.extensions[extName].onResponse(ext[extName]); + } + }), + ); } /** @@ -921,7 +925,7 @@ export class SlidingSync extends TypedEventEmitter { const list = this.lists.get(listKey); if (!list) {