@@ -38,6 +38,7 @@ import {
38
38
MatrixError ,
39
39
ISearchResults ,
40
40
THREAD_RELATION_TYPE ,
41
+ MatrixClient ,
41
42
} from "matrix-js-sdk/src/matrix" ;
42
43
import { KnownMembership } from "matrix-js-sdk/src/types" ;
43
44
import { logger } from "matrix-js-sdk/src/logger" ;
@@ -431,7 +432,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
431
432
canAskToJoin : this . askToJoinEnabled ,
432
433
promptAskToJoin : false ,
433
434
viewRoomOpts : { buttons : [ ] } ,
434
- isRoomEncrypted : false ,
435
+ isRoomEncrypted : null ,
435
436
} ;
436
437
}
437
438
@@ -929,7 +930,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
929
930
const callState = call ?. state ;
930
931
this . setState ( {
931
932
callState,
932
- isRoomEncrypted : await this . getIsRoomEncrypted ( ) ,
933
933
} ) ;
934
934
935
935
this . context . legacyCallHandler . on ( LegacyCallHandlerEvent . CallState , this . onCallState ) ;
@@ -1358,13 +1358,12 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
1358
1358
this . context . widgetLayoutStore . on ( WidgetLayoutStore . emissionForRoom ( room ) , this . onWidgetLayoutChange ) ;
1359
1359
1360
1360
this . calculatePeekRules ( room ) ;
1361
- this . updatePreviewUrlVisibility ( room ) ;
1362
1361
this . loadMembersIfJoined ( room ) ;
1363
1362
this . calculateRecommendedVersion ( room ) ;
1364
- this . updateE2EStatus ( room ) ;
1365
1363
this . updatePermissions ( room ) ;
1366
1364
this . checkWidgets ( room ) ;
1367
1365
this . loadVirtualRoom ( room ) ;
1366
+ this . updateRoomEncrypted ( room ) ;
1368
1367
1369
1368
if (
1370
1369
this . getMainSplitContentType ( room ) !== MainSplitContentType . Timeline &&
@@ -1432,12 +1431,15 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
1432
1431
} ) ;
1433
1432
}
1434
1433
1435
- private updatePreviewUrlVisibility ( { roomId } : Room ) : void {
1436
- // URL Previews in E2EE rooms can be a privacy leak so use a different setting which is per-room explicit
1437
- const key = this . state . isRoomEncrypted ? "urlPreviewsEnabled_e2ee" : "urlPreviewsEnabled" ;
1438
- this . setState ( {
1439
- showUrlPreview : SettingsStore . getValue ( key , roomId ) ,
1440
- } ) ;
1434
+ private updatePreviewUrlVisibility ( room : Room ) : void {
1435
+ this . setState ( ( { isRoomEncrypted } ) => ( {
1436
+ showUrlPreview : this . getPreviewUrlVisibility ( room , isRoomEncrypted ) ,
1437
+ } ) ) ;
1438
+ }
1439
+
1440
+ private getPreviewUrlVisibility ( { roomId } : Room , isRoomEncrypted : boolean | null ) : boolean {
1441
+ const key = isRoomEncrypted ? "urlPreviewsEnabled_e2ee" : "urlPreviewsEnabled" ;
1442
+ return SettingsStore . getValue ( key , roomId ) ;
1441
1443
}
1442
1444
1443
1445
private onRoom = ( room : Room ) : void => {
@@ -1490,13 +1492,18 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
1490
1492
1491
1493
if ( this . context . client . getCrypto ( ) ) {
1492
1494
/* At this point, the user has encryption on and cross-signing on */
1493
- e2eStatus = await shieldStatusForRoom ( this . context . client , room ) ;
1494
- RoomView . e2eStatusCache . set ( room . roomId , e2eStatus ) ;
1495
+ e2eStatus = await this . cacheAndGetE2EStatus ( room , this . context . client ) ;
1495
1496
if ( this . unmounted ) return ;
1496
1497
this . setState ( { e2eStatus } ) ;
1497
1498
}
1498
1499
}
1499
1500
1501
+ private async cacheAndGetE2EStatus ( room : Room , client : MatrixClient ) : Promise < E2EStatus > {
1502
+ const e2eStatus = await shieldStatusForRoom ( client , room ) ;
1503
+ RoomView . e2eStatusCache . set ( room . roomId , e2eStatus ) ;
1504
+ return e2eStatus ;
1505
+ }
1506
+
1500
1507
private onUrlPreviewsEnabledChange = ( ) : void => {
1501
1508
if ( this . state . room ) {
1502
1509
this . updatePreviewUrlVisibility ( this . state . room ) ;
@@ -1505,25 +1512,34 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
1505
1512
1506
1513
private onRoomStateEvents = async ( ev : MatrixEvent , state : RoomState ) : Promise < void > => {
1507
1514
// ignore if we don't have a room yet
1508
- if ( ! this . state . room || this . state . room . roomId !== state . roomId ) return ;
1515
+ if ( ! this . state . room || this . state . room . roomId !== state . roomId || ! this . context . client ) return ;
1509
1516
1510
1517
switch ( ev . getType ( ) ) {
1511
1518
case EventType . RoomTombstone :
1512
1519
this . setState ( { tombstone : this . getRoomTombstone ( ) } ) ;
1513
1520
break ;
1514
- case EventType . RoomEncryption :
1515
- this . setState ( { isRoomEncrypted : await this . getIsRoomEncrypted ( ) } , ( ) => {
1516
- if ( this . state . room ) {
1517
- this . updatePreviewUrlVisibility ( this . state . room ) ;
1518
- this . updateE2EStatus ( this . state . room ) ;
1519
- }
1520
- } ) ;
1521
+ case EventType . RoomEncryption : {
1522
+ await this . updateRoomEncrypted ( ) ;
1521
1523
break ;
1524
+ }
1522
1525
default :
1523
1526
this . updatePermissions ( this . state . room ) ;
1524
1527
}
1525
1528
} ;
1526
1529
1530
+ private async updateRoomEncrypted ( room = this . state . room ) : Promise < void > {
1531
+ if ( ! room || ! this . context . client ) return ;
1532
+
1533
+ const isRoomEncrypted = await this . getIsRoomEncrypted ( room . roomId ) ;
1534
+ const newE2EStatus = isRoomEncrypted ? await this . cacheAndGetE2EStatus ( room , this . context . client ) : null ;
1535
+
1536
+ this . setState ( {
1537
+ isRoomEncrypted,
1538
+ showUrlPreview : this . getPreviewUrlVisibility ( room , isRoomEncrypted ) ,
1539
+ ...( newE2EStatus && { e2eStatus : newE2EStatus } ) ,
1540
+ } ) ;
1541
+ }
1542
+
1527
1543
private onRoomStateUpdate = ( state : RoomState ) : void => {
1528
1544
// ignore members in other rooms
1529
1545
if ( state . roomId !== this . state . room ?. roomId ) {
0 commit comments