diff --git a/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts b/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts index 92895663b09..a814824d506 100644 --- a/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts +++ b/apps/web/src/device-listener/DeviceListenerCurrentDevice.ts @@ -94,6 +94,7 @@ export class DeviceListenerCurrentDevice { this.client.on(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged); this.client.on(CryptoEvent.KeysChanged, this.onCrossSigningKeysChanged); this.client.on(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatusChanged); + this.client.on(CryptoEvent.KeyBackupDecryptionKeyCached, this.onKeyBackupDecryptionKeyCached); this.client.on(ClientEvent.AccountData, this.onAccountData); this.client.on(ClientEvent.Sync, this.onSync); this.client.on(RoomStateEvent.Events, this.onRoomStateEvents); @@ -112,6 +113,7 @@ export class DeviceListenerCurrentDevice { this.client.removeListener(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged); this.client.removeListener(CryptoEvent.KeysChanged, this.onCrossSigningKeysChanged); this.client.removeListener(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatusChanged); + this.client.removeListener(CryptoEvent.KeyBackupDecryptionKeyCached, this.onKeyBackupDecryptionKeyCached); this.client.removeListener(ClientEvent.AccountData, this.onAccountData); this.client.removeListener(ClientEvent.Sync, this.onSync); this.client.removeListener(RoomStateEvent.Events, this.onRoomStateEvents); @@ -309,6 +311,12 @@ export class DeviceListenerCurrentDevice { this.deviceListener.recheck(); }; + private onKeyBackupDecryptionKeyCached = (): void => { + this.logger.info("Backup decryption key cached"); + this.cachedKeyBackupUploadActive = undefined; + this.deviceListener.recheck(); + }; + private onCrossSigningKeysChanged = (): void => { this.deviceListener.recheck(); }; diff --git a/apps/web/test/unit-tests/DeviceListener-test.ts b/apps/web/test/unit-tests/DeviceListener-test.ts index 713221928cf..5b1e5dd1664 100644 --- a/apps/web/test/unit-tests/DeviceListener-test.ts +++ b/apps/web/test/unit-tests/DeviceListener-test.ts @@ -161,6 +161,28 @@ describe("DeviceListener", () => { expect(unwatchSettingSpy).toHaveBeenCalled(); }); + it("responds to KeyBackupDecryptionKeyCached events", async () => { + // Given a Device Listener + const recheck = jest.fn(); + const deviceListener = await createAndStart(); + deviceListener.recheck = recheck; + + // When a KeyBackupDecryptionKeyCached event happens + mockClient.emit(CryptoEvent.KeyBackupDecryptionKeyCached, "3"); + + // Then we rechecked the device information + expect(recheck).toHaveBeenCalled(); + + // And when we stop our device listener + const removeListener = jest.fn(() => {}); + // @ts-ignore overwriting with a mock + mockClient.removeListener = removeListener; + deviceListener.stop(); + + // Then it should stop listening + expect(removeListener).toHaveBeenCalledWith(CryptoEvent.KeyBackupDecryptionKeyCached, expect.any(Function)); + }); + describe("when device client information feature is enabled", () => { beforeEach(() => { jest.spyOn(SettingsStore, "getValue").mockImplementation(