@@ -50,6 +50,11 @@ module.exports = {
5050 this . focusComposer = false ;
5151 document . addEventListener ( "keydown" , this . onKeyDown ) ;
5252 window . addEventListener ( "focus" , this . onFocus ) ;
53+ if ( this . state . logged_in ) {
54+ this . notifyNewScreen ( '' ) ;
55+ } else {
56+ this . notifyNewScreen ( 'login' ) ;
57+ }
5358 } ,
5459
5560 componentWillUnmount : function ( ) {
@@ -69,14 +74,45 @@ module.exports = {
6974
7075 switch ( payload . action ) {
7176 case 'logout' :
72- this . setState ( {
77+ this . replaceState ( {
7378 logged_in : false ,
7479 ready : false
7580 } ) ;
81+ localStorage . removeItem ( "mx_hs_url" ) ;
82+ localStorage . removeItem ( "mx_user_id" ) ;
83+ localStorage . removeItem ( "mx_access_token" ) ;
7684 Notifier . stop ( ) ;
7785 MatrixClientPeg . get ( ) . removeAllListeners ( ) ;
7886 MatrixClientPeg . replace ( null ) ;
7987 break ;
88+ case 'start_registration' :
89+ if ( this . state . logged_in ) return ;
90+ var newState = payload . params || { } ;
91+ newState . screen = 'register' ;
92+ if (
93+ payload . params &&
94+ payload . params . client_secret &&
95+ payload . params . session_id &&
96+ payload . params . hs_url &&
97+ payload . params . is_url &&
98+ payload . params . sid
99+ ) {
100+ newState . register_client_secret = payload . params . client_secret ;
101+ newState . register_session_id = payload . params . session_id ;
102+ newState . register_hs_url = payload . params . hs_url ;
103+ newState . register_is_url = payload . params . is_url ;
104+ newState . register_id_sid = payload . params . sid ;
105+ }
106+ this . replaceState ( newState ) ;
107+ this . notifyNewScreen ( 'register' ) ;
108+ break ;
109+ case 'start_login' :
110+ if ( this . state . logged_in ) return ;
111+ this . replaceState ( {
112+ screen : 'login'
113+ } ) ;
114+ this . notifyNewScreen ( 'login' ) ;
115+ break ;
80116 case 'view_room' :
81117 this . focusComposer = true ;
82118 this . setState ( {
@@ -111,8 +147,12 @@ module.exports = {
111147 } ,
112148
113149 onLoggedIn : function ( ) {
114- this . setState ( { logged_in : true } ) ;
150+ this . setState ( {
151+ screen : undefined ,
152+ logged_in : true
153+ } ) ;
115154 this . startMatrixClient ( ) ;
155+ this . notifyNewScreen ( '' ) ;
116156 } ,
117157
118158 startMatrixClient : function ( ) {
@@ -149,5 +189,25 @@ module.exports = {
149189
150190 onFocus : function ( ev ) {
151191 dis . dispatch ( { action : 'focus_composer' } ) ;
192+ } ,
193+
194+ showScreen ( screen , params ) {
195+ if ( screen == 'register' ) {
196+ dis . dispatch ( {
197+ action : 'start_registration' ,
198+ params : params
199+ } ) ;
200+ } else if ( screen == 'login' ) {
201+ dis . dispatch ( {
202+ action : 'start_login' ,
203+ params : params
204+ } ) ;
205+ }
206+ } ,
207+
208+ notifyNewScreen : function ( screen ) {
209+ if ( this . props . onNewScreen ) {
210+ this . props . onNewScreen ( screen ) ;
211+ }
152212 }
153213} ;
0 commit comments