mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-11-06 22:48:21 +00:00
Replace MatrixClient.isRoomEncrypted by MatrixClient.CryptoApi.isEncryptionEnabledInRoom in DeviceListener.ts
This commit is contained in:
@@ -46,6 +46,7 @@ import SettingsStore, { CallbackFn } from "./settings/SettingsStore";
|
|||||||
import { UIFeature } from "./settings/UIFeature";
|
import { UIFeature } from "./settings/UIFeature";
|
||||||
import { isBulkUnverifiedDeviceReminderSnoozed } from "./utils/device/snoozeBulkUnverifiedDeviceReminder";
|
import { isBulkUnverifiedDeviceReminderSnoozed } from "./utils/device/snoozeBulkUnverifiedDeviceReminder";
|
||||||
import { getUserDeviceIds } from "./utils/crypto/deviceInfo";
|
import { getUserDeviceIds } from "./utils/crypto/deviceInfo";
|
||||||
|
import { asyncSome } from "./utils/arrays.ts";
|
||||||
|
|
||||||
const KEY_BACKUP_POLL_INTERVAL = 5 * 60 * 1000;
|
const KEY_BACKUP_POLL_INTERVAL = 5 * 60 * 1000;
|
||||||
|
|
||||||
@@ -244,13 +245,16 @@ export default class DeviceListener {
|
|||||||
return this.keyBackupInfo;
|
return this.keyBackupInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private shouldShowSetupEncryptionToast(): boolean {
|
private shouldShowSetupEncryptionToast(): Promise<boolean> | boolean {
|
||||||
// If we're in the middle of a secret storage operation, we're likely
|
// If we're in the middle of a secret storage operation, we're likely
|
||||||
// modifying the state involved here, so don't add new toasts to setup.
|
// modifying the state involved here, so don't add new toasts to setup.
|
||||||
if (isSecretStorageBeingAccessed()) return false;
|
if (isSecretStorageBeingAccessed()) return false;
|
||||||
// Show setup toasts once the user is in at least one encrypted room.
|
// Show setup toasts once the user is in at least one encrypted room.
|
||||||
const cli = this.client;
|
const cli = this.client;
|
||||||
return cli?.getRooms().some((r) => cli.isRoomEncrypted(r.roomId)) ?? false;
|
const cryptoApi = cli?.getCrypto();
|
||||||
|
if (!cli || !cryptoApi) return false;
|
||||||
|
|
||||||
|
return asyncSome(cli.getRooms(), ({ roomId }) => cryptoApi.isEncryptionEnabledInRoom(roomId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private recheck(): void {
|
private recheck(): void {
|
||||||
@@ -287,7 +291,7 @@ export default class DeviceListener {
|
|||||||
hideSetupEncryptionToast();
|
hideSetupEncryptionToast();
|
||||||
|
|
||||||
this.checkKeyBackupStatus();
|
this.checkKeyBackupStatus();
|
||||||
} else if (this.shouldShowSetupEncryptionToast()) {
|
} else if (await this.shouldShowSetupEncryptionToast()) {
|
||||||
// make sure our keys are finished downloading
|
// make sure our keys are finished downloading
|
||||||
await crypto.getUserDeviceInfo([cli.getSafeUserId()]);
|
await crypto.getUserDeviceInfo([cli.getSafeUserId()]);
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ describe("DeviceListener", () => {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
getSessionBackupPrivateKey: jest.fn(),
|
getSessionBackupPrivateKey: jest.fn(),
|
||||||
|
isEncryptionEnabledInRoom: jest.fn(),
|
||||||
} as unknown as Mocked<CryptoApi>;
|
} as unknown as Mocked<CryptoApi>;
|
||||||
mockClient = getMockClientWithEventEmitter({
|
mockClient = getMockClientWithEventEmitter({
|
||||||
isGuest: jest.fn(),
|
isGuest: jest.fn(),
|
||||||
@@ -104,7 +105,6 @@ describe("DeviceListener", () => {
|
|||||||
isVersionSupported: jest.fn().mockResolvedValue(true),
|
isVersionSupported: jest.fn().mockResolvedValue(true),
|
||||||
isInitialSyncComplete: jest.fn().mockReturnValue(true),
|
isInitialSyncComplete: jest.fn().mockReturnValue(true),
|
||||||
waitForClientWellKnown: jest.fn(),
|
waitForClientWellKnown: jest.fn(),
|
||||||
isRoomEncrypted: jest.fn(),
|
|
||||||
getClientWellKnown: jest.fn(),
|
getClientWellKnown: jest.fn(),
|
||||||
getDeviceId: jest.fn().mockReturnValue(deviceId),
|
getDeviceId: jest.fn().mockReturnValue(deviceId),
|
||||||
setAccountData: jest.fn(),
|
setAccountData: jest.fn(),
|
||||||
@@ -291,7 +291,7 @@ describe("DeviceListener", () => {
|
|||||||
mockCrypto!.isCrossSigningReady.mockResolvedValue(false);
|
mockCrypto!.isCrossSigningReady.mockResolvedValue(false);
|
||||||
mockCrypto!.isSecretStorageReady.mockResolvedValue(false);
|
mockCrypto!.isSecretStorageReady.mockResolvedValue(false);
|
||||||
mockClient!.getRooms.mockReturnValue(rooms);
|
mockClient!.getRooms.mockReturnValue(rooms);
|
||||||
mockClient!.isRoomEncrypted.mockReturnValue(true);
|
jest.spyOn(mockClient.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("hides setup encryption toast when cross signing and secret storage are ready", async () => {
|
it("hides setup encryption toast when cross signing and secret storage are ready", async () => {
|
||||||
@@ -316,7 +316,7 @@ describe("DeviceListener", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("does not show any toasts when no rooms are encrypted", async () => {
|
it("does not show any toasts when no rooms are encrypted", async () => {
|
||||||
mockClient!.isRoomEncrypted.mockReturnValue(false);
|
jest.spyOn(mockClient.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(false);
|
||||||
await createAndStart();
|
await createAndStart();
|
||||||
|
|
||||||
expect(SetupEncryptionToast.showToast).not.toHaveBeenCalled();
|
expect(SetupEncryptionToast.showToast).not.toHaveBeenCalled();
|
||||||
|
|||||||
Reference in New Issue
Block a user