@@ -140,7 +140,7 @@ import { cleanUpDraftsIfRequired } from "../../DraftCleaner";
140140// legacy export
141141export { default as Views } from "../../Views" ;
142142
143- const AUTH_SCREENS = [ "register" , "login" , "forgot_password" , "start_sso" , "start_cas" , "welcome" ] ;
143+ const AUTH_SCREENS = [ "register" , "mobile_register" , " login", "forgot_password" , "start_sso" , "start_cas" , "welcome" ] ;
144144
145145// Actions that are redirected through the onboarding process prior to being
146146// re-dispatched. NOTE: some actions are non-trivial and would require
@@ -189,6 +189,7 @@ interface IState {
189189 register_session_id ?: string ;
190190 // eslint-disable-next-line camelcase
191191 register_id_sid ?: string ;
192+ isMobileRegistration ?: boolean ;
192193 // When showing Modal dialogs we need to set aria-hidden on the root app element
193194 // and disable it when there are no dialogs
194195 hideToSRUsers : boolean ;
@@ -243,6 +244,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
243244 currentUserId : null ,
244245
245246 hideToSRUsers : false ,
247+ isMobileRegistration : false ,
246248
247249 syncError : null , // If the current syncing status is ERROR, the error object, otherwise null.
248250 resizeNotifier : new ResizeNotifier ( ) ,
@@ -650,6 +652,9 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
650652 case "require_registration" :
651653 startAnyRegistrationFlow ( payload as any ) ;
652654 break ;
655+ case "start_mobile_registration" :
656+ this . startRegistration ( payload . params || { } , true ) ;
657+ break ;
653658 case "start_registration" :
654659 if ( Lifecycle . isSoftLogout ( ) ) {
655660 this . onSoftLogout ( ) ;
@@ -946,19 +951,28 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
946951 } ) ;
947952 }
948953
949- private async startRegistration ( params : { [ key : string ] : string } ) : Promise < void > {
954+ private async startRegistration ( params : { [ key : string ] : string } , isMobileRegistration ?: boolean ) : Promise < void > {
950955 if ( ! SettingsStore . getValue ( UIFeature . Registration ) ) {
951956 this . showScreen ( "welcome" ) ;
952957 return ;
953958 }
959+ const isMobileRegistrationAllowed =
960+ isMobileRegistration && SettingsStore . getValue ( "Registration.mobileRegistrationHelper" ) ;
954961
955962 const newState : Partial < IState > = {
956963 view : Views . REGISTER ,
957964 } ;
958965
959- // Only honour params if they are all present, otherwise we reset
960- // HS and IS URLs when switching to registration.
961- if ( params . client_secret && params . session_id && params . hs_url && params . is_url && params . sid ) {
966+ if ( isMobileRegistrationAllowed && params . hs_url ) {
967+ try {
968+ const config = await AutoDiscoveryUtils . validateServerConfigWithStaticUrls ( params . hs_url ) ;
969+ newState . serverConfig = config ;
970+ } catch ( err ) {
971+ logger . warn ( "Failed to load hs_url param:" , params . hs_url ) ;
972+ }
973+ } else if ( params . client_secret && params . session_id && params . hs_url && params . is_url && params . sid ) {
974+ // Only honour params if they are all present, otherwise we reset
975+ // HS and IS URLs when switching to registration.
962976 newState . serverConfig = await AutoDiscoveryUtils . validateServerConfigWithStaticUrls (
963977 params . hs_url ,
964978 params . is_url ,
@@ -978,10 +992,12 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
978992 newState . register_id_sid = params . sid ;
979993 }
980994
995+ newState . isMobileRegistration = isMobileRegistrationAllowed ;
996+
981997 this . setStateForNewView ( newState ) ;
982998 ThemeController . isLogin = true ;
983999 this . themeWatcher . recheck ( ) ;
984- this . notifyNewScreen ( "register" ) ;
1000+ this . notifyNewScreen ( isMobileRegistrationAllowed ? "mobile_register" : "register" ) ;
9851001 }
9861002
9871003 // switch view to the given room
@@ -1721,6 +1737,11 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
17211737 params : params ,
17221738 } ) ;
17231739 PerformanceMonitor . instance . start ( PerformanceEntryNames . REGISTER ) ;
1740+ } else if ( screen === "mobile_register" ) {
1741+ dis . dispatch ( {
1742+ action : "start_mobile_registration" ,
1743+ params : params ,
1744+ } ) ;
17241745 } else if ( screen === "login" ) {
17251746 dis . dispatch ( {
17261747 action : "start_login" ,
@@ -2080,6 +2101,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
20802101 onServerConfigChange = { this . onServerConfigChange }
20812102 defaultDeviceDisplayName = { this . props . defaultDeviceDisplayName }
20822103 fragmentAfterLogin = { fragmentAfterLogin }
2104+ mobileRegister = { this . state . isMobileRegistration }
20832105 { ...this . getServerProperties ( ) }
20842106 />
20852107 ) ;
0 commit comments