Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/web/src/device-listener/DeviceListenerCurrentDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
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);
Expand All @@ -112,6 +113,7 @@
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);
Expand Down Expand Up @@ -309,6 +311,12 @@
this.deviceListener.recheck();
};

private onKeyBackupDecryptionKeyCached = (): void => {

Check warning on line 314 in apps/web/src/device-listener/DeviceListenerCurrentDevice.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Member 'onKeyBackupDecryptionKeyCached' is never reassigned; mark it as `readonly`.

See more on https://sonarcloud.io/project/issues?id=element-web&issues=AZz2vLISGOviLjPO9oj6&open=AZz2vLISGOviLjPO9oj6&pullRequest=32811
this.logger.info("Backup decryption key cached");
this.cachedKeyBackupUploadActive = undefined;
this.deviceListener.recheck();
};

private onCrossSigningKeysChanged = (): void => {
this.deviceListener.recheck();
};
Expand Down
22 changes: 22 additions & 0 deletions apps/web/test/unit-tests/DeviceListener-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading