@@ -44,6 +44,11 @@ module.exports = {
4444 this . focusComposer = false ;
4545 document . addEventListener ( "keydown" , this . onKeyDown ) ;
4646 window . addEventListener ( "focus" , this . onFocus ) ;
47+ if ( this . state . logged_in ) {
48+ this . notifyNewScreen ( '' ) ;
49+ } else {
50+ this . notifyNewScreen ( 'login' ) ;
51+ }
4752 } ,
4853
4954 componentWillUnmount : function ( ) {
@@ -63,14 +68,45 @@ module.exports = {
6368
6469 switch ( payload . action ) {
6570 case 'logout' :
66- this . setState ( {
71+ this . replaceState ( {
6772 logged_in : false ,
6873 ready : false
6974 } ) ;
75+ localStorage . removeItem ( "mx_hs_url" ) ;
76+ localStorage . removeItem ( "mx_user_id" ) ;
77+ localStorage . removeItem ( "mx_access_token" ) ;
7078 Notifier . stop ( ) ;
7179 MatrixClientPeg . get ( ) . removeAllListeners ( ) ;
7280 MatrixClientPeg . replace ( null ) ;
7381 break ;
82+ case 'start_registration' :
83+ if ( this . state . logged_in ) return ;
84+ var newState = payload . params || { } ;
85+ newState . screen = 'register' ;
86+ if (
87+ payload . params &&
88+ payload . params . client_secret &&
89+ payload . params . session_id &&
90+ payload . params . hs_url &&
91+ payload . params . is_url &&
92+ payload . params . sid
93+ ) {
94+ newState . register_client_secret = payload . params . client_secret ;
95+ newState . register_session_id = payload . params . session_id ;
96+ newState . register_hs_url = payload . params . hs_url ;
97+ newState . register_is_url = payload . params . is_url ;
98+ newState . register_id_sid = payload . params . sid ;
99+ }
100+ this . replaceState ( newState ) ;
101+ this . notifyNewScreen ( 'register' ) ;
102+ break ;
103+ case 'start_login' :
104+ if ( this . state . logged_in ) return ;
105+ this . replaceState ( {
106+ screen : 'login'
107+ } ) ;
108+ this . notifyNewScreen ( 'login' ) ;
109+ break ;
74110 case 'view_room' :
75111 this . focusComposer = true ;
76112 this . setState ( {
@@ -99,8 +135,12 @@ module.exports = {
99135 } ,
100136
101137 onLoggedIn : function ( ) {
102- this . setState ( { logged_in : true } ) ;
138+ this . setState ( {
139+ screen : undefined ,
140+ logged_in : true
141+ } ) ;
103142 this . startMatrixClient ( ) ;
143+ this . notifyNewScreen ( '' ) ;
104144 } ,
105145
106146 startMatrixClient : function ( ) {
@@ -137,6 +177,26 @@ module.exports = {
137177
138178 onFocus : function ( ev ) {
139179 dis . dispatch ( { action : 'focus_composer' } ) ;
180+ } ,
181+
182+ showScreen ( screen , params ) {
183+ if ( screen == 'register' ) {
184+ dis . dispatch ( {
185+ action : 'start_registration' ,
186+ params : params
187+ } ) ;
188+ } else if ( screen == 'login' ) {
189+ dis . dispatch ( {
190+ action : 'start_login' ,
191+ params : params
192+ } ) ;
193+ }
194+ } ,
195+
196+ notifyNewScreen : function ( screen ) {
197+ if ( this . props . onNewScreen ) {
198+ this . props . onNewScreen ( screen ) ;
199+ }
140200 }
141201} ;
142202
0 commit comments