Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 81098b9

Browse files
author
Kerry
authored
Add config setting to disable bulk unverified sessions nag (#9657)
* test bulk unverified sessions toast behaviour * unverified sessions toast text tweak * only show bulk unverified sessions toast when current device is verified * add Setting for BulkUnverifiedSessionsReminder * add build config for BulkUnverifiedSessionsReminder * add more assertions for show/hide toast, fix strict errors * fix strict error
1 parent 5742c24 commit 81098b9

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

src/DeviceListener.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
removeClientInformation,
4848
} from "./utils/device/clientInformation";
4949
import SettingsStore, { CallbackFn } from "./settings/SettingsStore";
50+
import { UIFeature } from "./settings/UIFeature";
5051

5152
const KEY_BACKUP_POLL_INTERVAL = 5 * 60 * 1000;
5253

@@ -68,6 +69,7 @@ export default class DeviceListener {
6869
private displayingToastsForDeviceIds = new Set<string>();
6970
private running = false;
7071
private shouldRecordClientInformation = false;
72+
private enableBulkUnverifiedSessionsReminder = true;
7173
private deviceClientInformationSettingWatcherRef: string | undefined;
7274

7375
public static sharedInstance() {
@@ -86,6 +88,8 @@ export default class DeviceListener {
8688
MatrixClientPeg.get().on(ClientEvent.Sync, this.onSync);
8789
MatrixClientPeg.get().on(RoomStateEvent.Events, this.onRoomStateEvents);
8890
this.shouldRecordClientInformation = SettingsStore.getValue('deviceClientInformationOptIn');
91+
// only configurable in config, so we don't need to watch the value
92+
this.enableBulkUnverifiedSessionsReminder = SettingsStore.getValue(UIFeature.BulkUnverifiedSessionsReminder);
8993
this.deviceClientInformationSettingWatcherRef = SettingsStore.watchSetting(
9094
'deviceClientInformationOptIn',
9195
null,
@@ -333,7 +337,11 @@ export default class DeviceListener {
333337

334338
// Display or hide the batch toast for old unverified sessions
335339
// don't show the toast if the current device is unverified
336-
if (oldUnverifiedDeviceIds.size > 0 && isCurrentDeviceTrusted) {
340+
if (
341+
oldUnverifiedDeviceIds.size > 0
342+
&& isCurrentDeviceTrusted
343+
&& this.enableBulkUnverifiedSessionsReminder
344+
) {
337345
showBulkUnverifiedSessionsToast(oldUnverifiedDeviceIds);
338346
} else {
339347
hideBulkUnverifiedSessionsToast();

src/settings/Settings.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,10 @@ export const SETTINGS: {[setting: string]: ISetting} = {
11491149
supportedLevels: LEVELS_UI_FEATURE,
11501150
default: true,
11511151
},
1152+
[UIFeature.BulkUnverifiedSessionsReminder]: {
1153+
supportedLevels: LEVELS_UI_FEATURE,
1154+
default: true,
1155+
},
11521156

11531157
// Electron-specific settings, they are stored by Electron and set/read over an IPC.
11541158
// We store them over there are they are necessary to know before the renderer process launches.

src/settings/UIFeature.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export enum UIFeature {
3131
AdvancedSettings = "UIFeature.advancedSettings",
3232
RoomHistorySettings = "UIFeature.roomHistorySettings",
3333
TimelineEnableRelativeDates = "UIFeature.timelineEnableRelativeDates",
34+
BulkUnverifiedSessionsReminder = "UIFeature.BulkUnverifiedSessionsReminder",
3435
}
3536

3637
export enum UIComponent {

test/DeviceListener-test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { Action } from "../src/dispatcher/actions";
3434
import SettingsStore from "../src/settings/SettingsStore";
3535
import { SettingLevel } from "../src/settings/SettingLevel";
3636
import { getMockClientWithEventEmitter, mockPlatformPeg } from "./test-utils";
37+
import { UIFeature } from "../src/settings/UIFeature";
3738

3839
// don't litter test console with logs
3940
jest.mock("matrix-js-sdk/src/logger");
@@ -399,6 +400,9 @@ describe('DeviceListener', () => {
399400
// all devices verified by default
400401
mockClient!.checkDeviceTrust.mockReturnValue(deviceTrustVerified);
401402
mockClient!.deviceId = currentDevice.deviceId;
403+
jest.spyOn(SettingsStore, 'getValue').mockImplementation(
404+
settingName => settingName === UIFeature.BulkUnverifiedSessionsReminder,
405+
);
402406
});
403407
describe('bulk unverified sessions toasts', () => {
404408
it('hides toast when cross signing is not ready', async () => {
@@ -414,6 +418,24 @@ describe('DeviceListener', () => {
414418
expect(BulkUnverifiedSessionsToast.showToast).not.toHaveBeenCalled();
415419
});
416420

421+
it('hides toast when feature is disabled', async () => {
422+
// BulkUnverifiedSessionsReminder set to false
423+
jest.spyOn(SettingsStore, 'getValue').mockReturnValue(false);
424+
// currentDevice, device2 are verified, device3 is unverified
425+
// ie if reminder was enabled it should be shown
426+
mockClient!.checkDeviceTrust.mockImplementation((_userId, deviceId) => {
427+
switch (deviceId) {
428+
case currentDevice.deviceId:
429+
case device2.deviceId:
430+
return deviceTrustVerified;
431+
default:
432+
return deviceTrustUnverified;
433+
}
434+
});
435+
await createAndStart();
436+
expect(BulkUnverifiedSessionsToast.hideToast).toHaveBeenCalled();
437+
});
438+
417439
it('hides toast when current device is unverified', async () => {
418440
// device2 verified, current and device3 unverified
419441
mockClient!.checkDeviceTrust.mockImplementation((_userId, deviceId) => {

0 commit comments

Comments
 (0)