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

Commit

Permalink
Only display bulk unverified sessions nag when current session is ver…
Browse files Browse the repository at this point in the history
…ified (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
  • Loading branch information
Kerry authored Dec 2, 2022
1 parent 8996bf0 commit 5742c24
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/DeviceListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,17 @@ export default class DeviceListener {
// Unverified devices that have appeared since then
const newUnverifiedDeviceIds = new Set<string>();

const isCurrentDeviceTrusted = crossSigningReady &&
await (cli.checkDeviceTrust(cli.getUserId()!, cli.deviceId!)).isCrossSigningVerified();

// as long as cross-signing isn't ready,
// you can't see or dismiss any device toasts
if (crossSigningReady) {
const devices = cli.getStoredDevicesForUser(cli.getUserId());
for (const device of devices) {
if (device.deviceId === cli.deviceId) continue;

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

// Display or hide the batch toast for old unverified sessions
if (oldUnverifiedDeviceIds.size > 0) {
// don't show the toast if the current device is unverified
if (oldUnverifiedDeviceIds.size > 0 && isCurrentDeviceTrusted) {
showBulkUnverifiedSessionsToast(oldUnverifiedDeviceIds);
} else {
hideBulkUnverifiedSessionsToast();
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@
"Yes": "Yes",
"No": "No",
"Help improve %(analyticsOwner)s": "Help improve %(analyticsOwner)s",
"You have unverified logins": "You have unverified logins",
"You have unverified sessions": "You have unverified sessions",
"Review to ensure your account is safe": "Review to ensure your account is safe",
"Review": "Review",
"Later": "Later",
Expand Down
2 changes: 1 addition & 1 deletion src/toasts/BulkUnverifiedSessionsToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const showToast = (deviceIds: Set<string>) => {

ToastStore.sharedInstance().addOrReplaceToast({
key: TOAST_KEY,
title: _t("You have unverified logins"),
title: _t("You have unverified sessions"),
icon: "verification_warning",
props: {
description: _t("Review to ensure your account is safe"),
Expand Down
15 changes: 10 additions & 5 deletions test/DeviceListener-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,16 @@ describe('DeviceListener', () => {
expect(BulkUnverifiedSessionsToast.showToast).not.toHaveBeenCalled();
});

it('hides toast when only unverified device is the current device', async () => {
mockClient!.getStoredDevicesForUser.mockReturnValue([
currentDevice,
]);
mockClient!.checkDeviceTrust.mockReturnValue(deviceTrustUnverified);
it('hides toast when current device is unverified', async () => {
// device2 verified, current and device3 unverified
mockClient!.checkDeviceTrust.mockImplementation((_userId, deviceId) => {
switch (deviceId) {
case device2.deviceId:
return deviceTrustVerified;
default:
return deviceTrustUnverified;
}
});
await createAndStart();
expect(BulkUnverifiedSessionsToast.hideToast).toHaveBeenCalled();
expect(BulkUnverifiedSessionsToast.showToast).not.toHaveBeenCalled();
Expand Down

0 comments on commit 5742c24

Please sign in to comment.