1
1
/*
2
- Copyright 2015, 2016 OpenMarket Ltd
3
- Copyright 2017 Vector Creations Ltd
4
- Copyright 2018, 2019 New Vector Ltd
5
- Copyright 2019 - 2022 The Matrix.org Foundation C.I.C.
2
+ Copyright 2015, 2017 - 2023 The Matrix.org Foundation C.I.C.
6
3
7
4
Licensed under the Apache License, Version 2.0 (the "License");
8
5
you may not use this file except in compliance with the License.
@@ -33,6 +30,7 @@ import { CryptoEvent } from "matrix-js-sdk/src/crypto";
33
30
import { THREAD_RELATION_TYPE } from "matrix-js-sdk/src/models/thread" ;
34
31
import { HistoryVisibility } from "matrix-js-sdk/src/@types/partials" ;
35
32
import { ISearchResults } from "matrix-js-sdk/src/@types/search" ;
33
+ import { IRoomTimelineData } from "matrix-js-sdk/src/matrix" ;
36
34
37
35
import shouldHideEvent from "../../shouldHideEvent" ;
38
36
import { _t } from "../../languageHandler" ;
@@ -360,8 +358,8 @@ function LocalRoomCreateLoader(props: ILocalRoomCreateLoaderProps): ReactElement
360
358
}
361
359
362
360
export class RoomView extends React . Component < IRoomProps , IRoomState > {
363
- private readonly dispatcherRef : string ;
364
- private settingWatchers : string [ ] ;
361
+ private dispatcherRef : string | undefined = undefined ;
362
+ private settingWatchers : string [ ] = [ ] ;
365
363
366
364
private unmounted = false ;
367
365
private permalinkCreators : Record < string , RoomPermalinkCreator > = { } ;
@@ -417,57 +415,6 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
417
415
narrow : false ,
418
416
visibleDecryptionFailures : [ ] ,
419
417
} ;
420
-
421
- this . dispatcherRef = dis . register ( this . onAction ) ;
422
- context . client . on ( ClientEvent . Room , this . onRoom ) ;
423
- context . client . on ( RoomEvent . Timeline , this . onRoomTimeline ) ;
424
- context . client . on ( RoomEvent . TimelineReset , this . onRoomTimelineReset ) ;
425
- context . client . on ( RoomEvent . Name , this . onRoomName ) ;
426
- context . client . on ( RoomStateEvent . Events , this . onRoomStateEvents ) ;
427
- context . client . on ( RoomStateEvent . Update , this . onRoomStateUpdate ) ;
428
- context . client . on ( RoomEvent . MyMembership , this . onMyMembership ) ;
429
- context . client . on ( CryptoEvent . KeyBackupStatus , this . onKeyBackupStatus ) ;
430
- context . client . on ( CryptoEvent . DeviceVerificationChanged , this . onDeviceVerificationChanged ) ;
431
- context . client . on ( CryptoEvent . UserTrustStatusChanged , this . onUserVerificationChanged ) ;
432
- context . client . on ( CryptoEvent . KeysChanged , this . onCrossSigningKeysChanged ) ;
433
- context . client . on ( MatrixEventEvent . Decrypted , this . onEventDecrypted ) ;
434
- // Start listening for RoomViewStore updates
435
- context . roomViewStore . on ( UPDATE_EVENT , this . onRoomViewStoreUpdate ) ;
436
-
437
- context . rightPanelStore . on ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
438
-
439
- WidgetEchoStore . on ( UPDATE_EVENT , this . onWidgetEchoStoreUpdate ) ;
440
- context . widgetStore . on ( UPDATE_EVENT , this . onWidgetStoreUpdate ) ;
441
-
442
- CallStore . instance . on ( CallStoreEvent . ActiveCalls , this . onActiveCalls ) ;
443
-
444
- this . props . resizeNotifier . on ( "isResizing" , this . onIsResizing ) ;
445
-
446
- this . settingWatchers = [
447
- SettingsStore . watchSetting ( "layout" , null , ( ...[ , , , value ] ) =>
448
- this . setState ( { layout : value as Layout } ) ,
449
- ) ,
450
- SettingsStore . watchSetting ( "lowBandwidth" , null , ( ...[ , , , value ] ) =>
451
- this . setState ( { lowBandwidth : value as boolean } ) ,
452
- ) ,
453
- SettingsStore . watchSetting ( "alwaysShowTimestamps" , null , ( ...[ , , , value ] ) =>
454
- this . setState ( { alwaysShowTimestamps : value as boolean } ) ,
455
- ) ,
456
- SettingsStore . watchSetting ( "showTwelveHourTimestamps" , null , ( ...[ , , , value ] ) =>
457
- this . setState ( { showTwelveHourTimestamps : value as boolean } ) ,
458
- ) ,
459
- SettingsStore . watchSetting ( "readMarkerInViewThresholdMs" , null , ( ...[ , , , value ] ) =>
460
- this . setState ( { readMarkerInViewThresholdMs : value as number } ) ,
461
- ) ,
462
- SettingsStore . watchSetting ( "readMarkerOutOfViewThresholdMs" , null , ( ...[ , , , value ] ) =>
463
- this . setState ( { readMarkerOutOfViewThresholdMs : value as number } ) ,
464
- ) ,
465
- SettingsStore . watchSetting ( "showHiddenEventsInTimeline" , null , ( ...[ , , , value ] ) =>
466
- this . setState ( { showHiddenEvents : value as boolean } ) ,
467
- ) ,
468
- SettingsStore . watchSetting ( "urlPreviewsEnabled" , null , this . onUrlPreviewsEnabledChange ) ,
469
- SettingsStore . watchSetting ( "urlPreviewsEnabled_e2ee" , null , this . onUrlPreviewsEnabledChange ) ,
470
- ] ;
471
418
}
472
419
473
420
private onIsResizing = ( resizing : boolean ) : void => {
@@ -621,7 +568,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
621
568
}
622
569
623
570
// Add watchers for each of the settings we just looked up
624
- this . settingWatchers = this . settingWatchers . concat ( [
571
+ this . settingWatchers . push (
625
572
SettingsStore . watchSetting ( "showReadReceipts" , roomId , ( ...[ , , , value ] ) =>
626
573
this . setState ( { showReadReceipts : value as boolean } ) ,
627
574
) ,
@@ -637,7 +584,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
637
584
SettingsStore . watchSetting ( "showDisplaynameChanges" , roomId , ( ...[ , , , value ] ) =>
638
585
this . setState ( { showDisplaynameChanges : value as boolean } ) ,
639
586
) ,
640
- ] ) ;
587
+ ) ;
641
588
642
589
if ( ! initial && this . state . shouldPeek && ! newState . shouldPeek ) {
643
590
// Stop peeking because we have joined this room now
@@ -765,8 +712,8 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
765
712
peekLoading : true ,
766
713
isPeeking : true , // this will change to false if peeking fails
767
714
} ) ;
768
- this . context . client
769
- . peekInRoom ( roomId )
715
+ this . context
716
+ . client ! . peekInRoom ( roomId )
770
717
. then ( ( room ) => {
771
718
if ( this . unmounted ) {
772
719
return ;
@@ -801,7 +748,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
801
748
} ) ;
802
749
} else if ( room ) {
803
750
// Stop peeking because we have joined this room previously
804
- this . context . client . stopPeeking ( ) ;
751
+ this . context . client ! . stopPeeking ( ) ;
805
752
this . setState ( { isPeeking : false } ) ;
806
753
}
807
754
}
@@ -824,6 +771,59 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
824
771
}
825
772
826
773
public componentDidMount ( ) : void {
774
+ const context = this . context ;
775
+ const client = context . client ! ;
776
+ this . dispatcherRef = dis . register ( this . onAction ) ;
777
+ client . on ( ClientEvent . Room , this . onRoom ) ;
778
+ client . on ( RoomEvent . Timeline , this . onRoomTimeline ) ;
779
+ client . on ( RoomEvent . TimelineReset , this . onRoomTimelineReset ) ;
780
+ client . on ( RoomEvent . Name , this . onRoomName ) ;
781
+ client . on ( RoomStateEvent . Events , this . onRoomStateEvents ) ;
782
+ client . on ( RoomStateEvent . Update , this . onRoomStateUpdate ) ;
783
+ client . on ( RoomEvent . MyMembership , this . onMyMembership ) ;
784
+ client . on ( CryptoEvent . KeyBackupStatus , this . onKeyBackupStatus ) ;
785
+ client . on ( CryptoEvent . DeviceVerificationChanged , this . onDeviceVerificationChanged ) ;
786
+ client . on ( CryptoEvent . UserTrustStatusChanged , this . onUserVerificationChanged ) ;
787
+ client . on ( CryptoEvent . KeysChanged , this . onCrossSigningKeysChanged ) ;
788
+ client . on ( MatrixEventEvent . Decrypted , this . onEventDecrypted ) ;
789
+ // Start listening for RoomViewStore updates
790
+ context . roomViewStore . on ( UPDATE_EVENT , this . onRoomViewStoreUpdate ) ;
791
+
792
+ context . rightPanelStore . on ( UPDATE_EVENT , this . onRightPanelStoreUpdate ) ;
793
+
794
+ WidgetEchoStore ! . on ( UPDATE_EVENT , this . onWidgetEchoStoreUpdate ) ;
795
+ context . widgetStore . on ( UPDATE_EVENT , this . onWidgetStoreUpdate ) ;
796
+
797
+ CallStore . instance . on ( CallStoreEvent . ActiveCalls , this . onActiveCalls ) ;
798
+
799
+ this . props . resizeNotifier . on ( "isResizing" , this . onIsResizing ) ;
800
+
801
+ this . settingWatchers = [
802
+ SettingsStore . watchSetting ( "layout" , null , ( ...[ , , , value ] ) =>
803
+ this . setState ( { layout : value as Layout } ) ,
804
+ ) ,
805
+ SettingsStore . watchSetting ( "lowBandwidth" , null , ( ...[ , , , value ] ) =>
806
+ this . setState ( { lowBandwidth : value as boolean } ) ,
807
+ ) ,
808
+ SettingsStore . watchSetting ( "alwaysShowTimestamps" , null , ( ...[ , , , value ] ) =>
809
+ this . setState ( { alwaysShowTimestamps : value as boolean } ) ,
810
+ ) ,
811
+ SettingsStore . watchSetting ( "showTwelveHourTimestamps" , null , ( ...[ , , , value ] ) =>
812
+ this . setState ( { showTwelveHourTimestamps : value as boolean } ) ,
813
+ ) ,
814
+ SettingsStore . watchSetting ( "readMarkerInViewThresholdMs" , null , ( ...[ , , , value ] ) =>
815
+ this . setState ( { readMarkerInViewThresholdMs : value as number } ) ,
816
+ ) ,
817
+ SettingsStore . watchSetting ( "readMarkerOutOfViewThresholdMs" , null , ( ...[ , , , value ] ) =>
818
+ this . setState ( { readMarkerOutOfViewThresholdMs : value as number } ) ,
819
+ ) ,
820
+ SettingsStore . watchSetting ( "showHiddenEventsInTimeline" , null , ( ...[ , , , value ] ) =>
821
+ this . setState ( { showHiddenEvents : value as boolean } ) ,
822
+ ) ,
823
+ SettingsStore . watchSetting ( "urlPreviewsEnabled" , null , this . onUrlPreviewsEnabledChange ) ,
824
+ SettingsStore . watchSetting ( "urlPreviewsEnabled_e2ee" , null , this . onUrlPreviewsEnabledChange ) ,
825
+ ] ;
826
+
827
827
this . onRoomViewStoreUpdate ( true ) ;
828
828
829
829
const call = this . getCallForRoom ( ) ;
@@ -883,7 +883,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
883
883
// stop tracking room changes to format permalinks
884
884
this . stopAllPermalinkCreators ( ) ;
885
885
886
- dis . unregister ( this . dispatcherRef ) ;
886
+ if ( this . dispatcherRef ) dis . unregister ( this . dispatcherRef ) ;
887
887
if ( this . context . client ) {
888
888
this . context . client . removeListener ( ClientEvent . Room , this . onRoom ) ;
889
889
this . context . client . removeListener ( RoomEvent . Timeline , this . onRoomTimeline ) ;
@@ -1106,11 +1106,17 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
1106
1106
} ;
1107
1107
1108
1108
private onLocalRoomEvent ( roomId : string ) : void {
1109
- if ( roomId !== this . state . room . roomId ) return ;
1110
- createRoomFromLocalRoom ( this . context . client , this . state . room as LocalRoom ) ;
1109
+ if ( roomId !== this . state . room ? .roomId ) return ;
1110
+ createRoomFromLocalRoom ( this . context . client ! , this . state . room as LocalRoom ) ;
1111
1111
}
1112
1112
1113
- private onRoomTimeline = ( ev : MatrixEvent , room : Room | null , toStartOfTimeline : boolean , removed , data ) : void => {
1113
+ private onRoomTimeline = (
1114
+ ev : MatrixEvent ,
1115
+ room : Room | undefined ,
1116
+ toStartOfTimeline : boolean | undefined ,
1117
+ _removed : boolean ,
1118
+ data : IRoomTimelineData ,
1119
+ ) : void => {
1114
1120
if ( this . unmounted ) return ;
1115
1121
1116
1122
// ignore events for other rooms or the notification timeline set
@@ -1371,7 +1377,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
1371
1377
this . updateRoomMembers ( ) ;
1372
1378
} ;
1373
1379
1374
- private onMyMembership = ( room : Room , membership : string , oldMembership : string ) : void => {
1380
+ private onMyMembership = ( room : Room ) : void => {
1375
1381
if ( room . roomId === this . state . roomId ) {
1376
1382
this . forceUpdate ( ) ;
1377
1383
this . loadMembersIfJoined ( room ) ;
0 commit comments