@@ -114,6 +114,7 @@ import GenericToast from "../views/toasts/GenericToast";
114
114
import InfoDialog from "../views/dialogs/InfoDialog" ;
115
115
import FeedbackDialog from "../views/dialogs/FeedbackDialog" ;
116
116
import AccessibleButton from "../views/elements/AccessibleButton" ;
117
+ import { ActionPayload } from "../../dispatcher/payloads" ;
117
118
118
119
/** constants for MatrixChat.state.view */
119
120
export enum Views {
@@ -542,13 +543,11 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
542
543
this . setState ( newState ) ;
543
544
}
544
545
545
- onAction = ( payload ) => {
546
+ private onAction = ( payload : ActionPayload ) => {
546
547
// console.log(`MatrixClientPeg.onAction: ${payload.action}`);
547
548
548
549
// Start the onboarding process for certain actions
549
- if ( MatrixClientPeg . get ( ) && MatrixClientPeg . get ( ) . isGuest ( ) &&
550
- ONBOARDING_FLOW_STARTERS . includes ( payload . action )
551
- ) {
550
+ if ( MatrixClientPeg . get ( ) ?. isGuest ( ) && ONBOARDING_FLOW_STARTERS . includes ( payload . action ) ) {
552
551
// This will cause `payload` to be dispatched later, once a
553
552
// sync has reached the "prepared" state. Setting a matrix ID
554
553
// will cause a full login and sync and finally the deferred
@@ -590,7 +589,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
590
589
Lifecycle . logout ( ) ;
591
590
break ;
592
591
case 'require_registration' :
593
- startAnyRegistrationFlow ( payload ) ;
592
+ startAnyRegistrationFlow ( payload as any ) ;
594
593
break ;
595
594
case 'start_registration' :
596
595
if ( Lifecycle . isSoftLogout ( ) ) {
@@ -666,7 +665,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
666
665
// known to be in (eg. user clicks on a room in the recents panel), supply the ID
667
666
// If the user is clicking on a room in the context of the alias being presented
668
667
// to them, supply the room alias. If both are supplied, the room ID will be ignored.
669
- const promise = this . viewRoom ( payload ) ;
668
+ const promise = this . viewRoom ( payload as any ) ;
670
669
if ( payload . deferred_action ) {
671
670
promise . then ( ( ) => {
672
671
dis . dispatch ( payload . deferred_action ) ;
@@ -897,73 +896,73 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
897
896
// @param {Object= } roomInfo.oob_data Object of additional data about the room
898
897
// that has been passed out-of-band (eg.
899
898
// room name and avatar from an invite email)
900
- private viewRoom ( roomInfo : IRoomInfo ) {
899
+ private async viewRoom ( roomInfo : IRoomInfo ) {
901
900
this . focusComposer = true ;
902
901
903
902
if ( roomInfo . room_alias ) {
904
- logger . log (
905
- `Switching to room alias ${ roomInfo . room_alias } at event ` +
906
- roomInfo . event_id ,
907
- ) ;
903
+ logger . log ( `Switching to room alias ${ roomInfo . room_alias } at event ${ roomInfo . event_id } ` ) ;
908
904
} else {
909
- logger . log ( `Switching to room id ${ roomInfo . room_id } at event ` +
910
- roomInfo . event_id ,
911
- ) ;
905
+ logger . log ( `Switching to room id ${ roomInfo . room_id } at event ${ roomInfo . event_id } ` ) ;
912
906
}
913
907
914
908
// Wait for the first sync to complete so that if a room does have an alias,
915
909
// it would have been retrieved.
916
- let waitFor = Promise . resolve ( null ) ;
917
910
if ( ! this . firstSyncComplete ) {
918
911
if ( ! this . firstSyncPromise ) {
919
912
logger . warn ( 'Cannot view a room before first sync. room_id:' , roomInfo . room_id ) ;
920
913
return ;
921
914
}
922
- waitFor = this . firstSyncPromise . promise ;
915
+ await this . firstSyncPromise . promise ;
923
916
}
924
917
925
- return waitFor . then ( ( ) => {
926
- let presentedId = roomInfo . room_alias || roomInfo . room_id ;
927
- const room = MatrixClientPeg . get ( ) . getRoom ( roomInfo . room_id ) ;
928
- if ( room ) {
929
- // Not all timeline events are decrypted ahead of time anymore
930
- // Only the critical ones for a typical UI are
931
- // This will start the decryption process for all events when a
932
- // user views a room
933
- room . decryptAllEvents ( ) ;
934
- const theAlias = Rooms . getDisplayAliasForRoom ( room ) ;
935
- if ( theAlias ) {
936
- presentedId = theAlias ;
937
- // Store display alias of the presented room in cache to speed future
938
- // navigation.
939
- storeRoomAliasInCache ( theAlias , room . roomId ) ;
940
- }
918
+ let presentedId = roomInfo . room_alias || roomInfo . room_id ;
919
+ const room = MatrixClientPeg . get ( ) . getRoom ( roomInfo . room_id ) ;
920
+ if ( room ) {
921
+ // Not all timeline events are decrypted ahead of time anymore
922
+ // Only the critical ones for a typical UI are
923
+ // This will start the decryption process for all events when a
924
+ // user views a room
925
+ room . decryptAllEvents ( ) ;
926
+ const theAlias = Rooms . getDisplayAliasForRoom ( room ) ;
927
+ if ( theAlias ) {
928
+ presentedId = theAlias ;
929
+ // Store display alias of the presented room in cache to speed future
930
+ // navigation.
931
+ storeRoomAliasInCache ( theAlias , room . roomId ) ;
932
+ }
941
933
942
- // Store this as the ID of the last room accessed. This is so that we can
943
- // persist which room is being stored across refreshes and browser quits.
944
- if ( localStorage ) {
945
- localStorage . setItem ( 'mx_last_room_id' , room . roomId ) ;
946
- }
934
+ // Store this as the ID of the last room accessed. This is so that we can
935
+ // persist which room is being stored across refreshes and browser quits.
936
+ if ( localStorage ) {
937
+ localStorage . setItem ( 'mx_last_room_id' , room . roomId ) ;
947
938
}
939
+ }
948
940
949
- // If we are redirecting to a Room Alias and it is for the room we already showing then replace history item
950
- const replaceLast = presentedId [ 0 ] === "#" && roomInfo . room_id === this . state . currentRoomId ;
941
+ // If we are redirecting to a Room Alias and it is for the room we already showing then replace history item
942
+ const replaceLast = presentedId [ 0 ] === "#" && roomInfo . room_id === this . state . currentRoomId ;
951
943
952
- if ( roomInfo . event_id && roomInfo . highlighted ) {
953
- presentedId += "/" + roomInfo . event_id ;
954
- }
955
- this . setState ( {
956
- view : Views . LOGGED_IN ,
957
- currentRoomId : roomInfo . room_id || null ,
958
- page_type : PageType . RoomView ,
959
- threepidInvite : roomInfo . threepid_invite ,
960
- roomOobData : roomInfo . oob_data ,
961
- forceTimeline : roomInfo . forceTimeline ,
962
- ready : true ,
963
- roomJustCreatedOpts : roomInfo . justCreatedOpts ,
964
- } , ( ) => {
965
- this . notifyNewScreen ( 'room/' + presentedId , replaceLast ) ;
966
- } ) ;
944
+ if ( roomInfo . room_id === this . state . currentRoomId ) {
945
+ // if we are re-viewing the same room then copy any state we already know
946
+ roomInfo . threepid_invite = roomInfo . threepid_invite ?? this . state . threepidInvite ;
947
+ roomInfo . oob_data = roomInfo . oob_data ?? this . state . roomOobData ;
948
+ roomInfo . forceTimeline = roomInfo . forceTimeline ?? this . state . forceTimeline ;
949
+ roomInfo . justCreatedOpts = roomInfo . justCreatedOpts ?? this . state . roomJustCreatedOpts ;
950
+ }
951
+
952
+ if ( roomInfo . event_id && roomInfo . highlighted ) {
953
+ presentedId += "/" + roomInfo . event_id ;
954
+ }
955
+ this . setState ( {
956
+ view : Views . LOGGED_IN ,
957
+ currentRoomId : roomInfo . room_id || null ,
958
+ page_type : PageType . RoomView ,
959
+ threepidInvite : roomInfo . threepid_invite ,
960
+ roomOobData : roomInfo . oob_data ,
961
+ forceTimeline : roomInfo . forceTimeline ,
962
+ ready : true ,
963
+ roomJustCreatedOpts : roomInfo . justCreatedOpts ,
964
+ } , ( ) => {
965
+ this . notifyNewScreen ( 'room/' + presentedId , replaceLast ) ;
967
966
} ) ;
968
967
}
969
968
0 commit comments