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

Commit 24e3e08

Browse files
authored
Cache e2eStatus to avoid concerning unencrypted flicker when changing rooms (#12606)
* Cache e2eStatus to avoid concerning unencrypted flicker when changing rooms Signed-off-by: Michael Telatynski <[email protected]> * Update src/components/structures/RoomView.tsx --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent 347229b commit 24e3e08

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/components/structures/RoomView.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ function LocalRoomCreateLoader(props: ILocalRoomCreateLoaderProps): ReactElement
400400
}
401401

402402
export class RoomView extends React.Component<IRoomProps, IRoomState> {
403+
// We cache the latest computed e2eStatus per room to show as soon as we switch rooms otherwise defaulting to
404+
// unencrypted causes a flicker which can yield confusion/concern in a larger room.
405+
private static e2eStatusCache = new Map<string, E2EStatus>();
406+
403407
private readonly askToJoinEnabled: boolean;
404408
private readonly dispatcherRef: string;
405409
private settingWatchers: string[];
@@ -1530,14 +1534,18 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
15301534
// If crypto is not currently enabled, we aren't tracking devices at all,
15311535
// so we don't know what the answer is. Let's error on the safe side and show
15321536
// a warning for this case.
1533-
let e2eStatus = E2EStatus.Warning;
1537+
let e2eStatus = RoomView.e2eStatusCache.get(room.roomId) ?? E2EStatus.Warning;
1538+
// set the state immediately then update, so we don't scare the user into thinking the room is unencrypted
1539+
this.setState({ e2eStatus });
1540+
15341541
if (this.context.client.isCryptoEnabled()) {
1542+
this.setState({ e2eStatus: E2EStatus.Normal });
15351543
/* At this point, the user has encryption on and cross-signing on */
15361544
e2eStatus = await shieldStatusForRoom(this.context.client, room);
1545+
RoomView.e2eStatusCache.set(room.roomId, e2eStatus);
1546+
if (this.unmounted) return;
1547+
this.setState({ e2eStatus });
15371548
}
1538-
1539-
if (this.unmounted) return;
1540-
this.setState({ e2eStatus });
15411549
}
15421550

15431551
private onUrlPreviewsEnabledChange = (): void => {

0 commit comments

Comments
 (0)