Make the DeviceListener listen to KeyBackupDecryptionKeyCached events (#32811)

Fixes #31916
This commit is contained in:
Andy Balaam
2026-03-16 13:19:42 +00:00
committed by GitHub
parent cace9d918f
commit 35babd83d6
2 changed files with 30 additions and 0 deletions
@@ -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();
};
@@ -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(