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

Commit 5742c24

Browse files
author
Kerry
authored
Only display bulk unverified sessions nag when current session is verified (PSG-893) (#9656)
* test bulk unverified sessions toast behaviour * unverified sessions toast text tweak * only show bulk unverified sessions toast when current device is verified * add more assertions for show/hide toast, fix strict errors * fix strict error * really fix strict error
1 parent 8996bf0 commit 5742c24

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

src/DeviceListener.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,17 @@ export default class DeviceListener {
306306
// Unverified devices that have appeared since then
307307
const newUnverifiedDeviceIds = new Set<string>();
308308

309+
const isCurrentDeviceTrusted = crossSigningReady &&
310+
await (cli.checkDeviceTrust(cli.getUserId()!, cli.deviceId!)).isCrossSigningVerified();
311+
309312
// as long as cross-signing isn't ready,
310313
// you can't see or dismiss any device toasts
311314
if (crossSigningReady) {
312315
const devices = cli.getStoredDevicesForUser(cli.getUserId());
313316
for (const device of devices) {
314317
if (device.deviceId === cli.deviceId) continue;
315318

316-
const deviceTrust = await cli.checkDeviceTrust(cli.getUserId(), device.deviceId);
319+
const deviceTrust = await cli.checkDeviceTrust(cli.getUserId()!, device.deviceId!);
317320
if (!deviceTrust.isCrossSigningVerified() && !this.dismissed.has(device.deviceId)) {
318321
if (this.ourDeviceIdsAtStart.has(device.deviceId)) {
319322
oldUnverifiedDeviceIds.add(device.deviceId);
@@ -329,7 +332,8 @@ export default class DeviceListener {
329332
logger.debug("Currently showing toasts for: " + Array.from(this.displayingToastsForDeviceIds).join(','));
330333

331334
// Display or hide the batch toast for old unverified sessions
332-
if (oldUnverifiedDeviceIds.size > 0) {
335+
// don't show the toast if the current device is unverified
336+
if (oldUnverifiedDeviceIds.size > 0 && isCurrentDeviceTrusted) {
333337
showBulkUnverifiedSessionsToast(oldUnverifiedDeviceIds);
334338
} else {
335339
hideBulkUnverifiedSessionsToast();

src/i18n/strings/en_EN.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@
809809
"Yes": "Yes",
810810
"No": "No",
811811
"Help improve %(analyticsOwner)s": "Help improve %(analyticsOwner)s",
812-
"You have unverified logins": "You have unverified logins",
812+
"You have unverified sessions": "You have unverified sessions",
813813
"Review to ensure your account is safe": "Review to ensure your account is safe",
814814
"Review": "Review",
815815
"Later": "Later",

src/toasts/BulkUnverifiedSessionsToast.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const showToast = (deviceIds: Set<string>) => {
3838

3939
ToastStore.sharedInstance().addOrReplaceToast({
4040
key: TOAST_KEY,
41-
title: _t("You have unverified logins"),
41+
title: _t("You have unverified sessions"),
4242
icon: "verification_warning",
4343
props: {
4444
description: _t("Review to ensure your account is safe"),

test/DeviceListener-test.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,16 @@ describe('DeviceListener', () => {
414414
expect(BulkUnverifiedSessionsToast.showToast).not.toHaveBeenCalled();
415415
});
416416

417-
it('hides toast when only unverified device is the current device', async () => {
418-
mockClient!.getStoredDevicesForUser.mockReturnValue([
419-
currentDevice,
420-
]);
421-
mockClient!.checkDeviceTrust.mockReturnValue(deviceTrustUnverified);
417+
it('hides toast when current device is unverified', async () => {
418+
// device2 verified, current and device3 unverified
419+
mockClient!.checkDeviceTrust.mockImplementation((_userId, deviceId) => {
420+
switch (deviceId) {
421+
case device2.deviceId:
422+
return deviceTrustVerified;
423+
default:
424+
return deviceTrustUnverified;
425+
}
426+
});
422427
await createAndStart();
423428
expect(BulkUnverifiedSessionsToast.hideToast).toHaveBeenCalled();
424429
expect(BulkUnverifiedSessionsToast.showToast).not.toHaveBeenCalled();

0 commit comments

Comments
 (0)