Make the DeviceListener listen to KeyBackupDecryptionKeyCached events (#32811)
Fixes #31916
This commit is contained in:
@@ -94,6 +94,7 @@ export class DeviceListenerCurrentDevice {
|
|||||||
this.client.on(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
|
this.client.on(CryptoEvent.UserTrustStatusChanged, this.onUserTrustStatusChanged);
|
||||||
this.client.on(CryptoEvent.KeysChanged, this.onCrossSigningKeysChanged);
|
this.client.on(CryptoEvent.KeysChanged, this.onCrossSigningKeysChanged);
|
||||||
this.client.on(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatusChanged);
|
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.AccountData, this.onAccountData);
|
||||||
this.client.on(ClientEvent.Sync, this.onSync);
|
this.client.on(ClientEvent.Sync, this.onSync);
|
||||||
this.client.on(RoomStateEvent.Events, this.onRoomStateEvents);
|
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.UserTrustStatusChanged, this.onUserTrustStatusChanged);
|
||||||
this.client.removeListener(CryptoEvent.KeysChanged, this.onCrossSigningKeysChanged);
|
this.client.removeListener(CryptoEvent.KeysChanged, this.onCrossSigningKeysChanged);
|
||||||
this.client.removeListener(CryptoEvent.KeyBackupStatus, this.onKeyBackupStatusChanged);
|
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.AccountData, this.onAccountData);
|
||||||
this.client.removeListener(ClientEvent.Sync, this.onSync);
|
this.client.removeListener(ClientEvent.Sync, this.onSync);
|
||||||
this.client.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
|
this.client.removeListener(RoomStateEvent.Events, this.onRoomStateEvents);
|
||||||
@@ -309,6 +311,12 @@ export class DeviceListenerCurrentDevice {
|
|||||||
this.deviceListener.recheck();
|
this.deviceListener.recheck();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private onKeyBackupDecryptionKeyCached = (): void => {
|
||||||
|
this.logger.info("Backup decryption key cached");
|
||||||
|
this.cachedKeyBackupUploadActive = undefined;
|
||||||
|
this.deviceListener.recheck();
|
||||||
|
};
|
||||||
|
|
||||||
private onCrossSigningKeysChanged = (): void => {
|
private onCrossSigningKeysChanged = (): void => {
|
||||||
this.deviceListener.recheck();
|
this.deviceListener.recheck();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -161,6 +161,28 @@ describe("DeviceListener", () => {
|
|||||||
expect(unwatchSettingSpy).toHaveBeenCalled();
|
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", () => {
|
describe("when device client information feature is enabled", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.spyOn(SettingsStore, "getValue").mockImplementation(
|
jest.spyOn(SettingsStore, "getValue").mockImplementation(
|
||||||
|
|||||||
Reference in New Issue
Block a user