11import { select , takeLatest } from 'redux-saga/effects' ;
22
3- import Navigation from '../lib/navigation/appNavigation' ;
43import log from '../lib/methods/helpers/log' ;
54import { localAuthenticate , saveLastLocalAuthenticationSession } from '../lib/methods/helpers/localAuthentication' ;
65import { APP_STATE } from '../actions/actionsTypes' ;
@@ -9,25 +8,24 @@ import { checkAndReopen } from '../lib/services/connect';
98import { setUserPresenceOnline , setUserPresenceAway } from '../lib/services/restApi' ;
109import { checkPendingNotification } from '../lib/notifications' ;
1110
11+ const isAuthAndConnected = function * isAuthAndConnected ( ) {
12+ const login = yield select ( state => state . login ) ;
13+ const meteor = yield select ( state => state . meteor ) ;
14+ return login . isAuthenticated && meteor . connected ;
15+ } ;
16+
1217const appHasComeBackToForeground = function * appHasComeBackToForeground ( ) {
1318 const appRoot = yield select ( state => state . app . root ) ;
14- if ( appRoot === RootEnum . ROOT_OUTSIDE ) {
19+ if ( appRoot !== RootEnum . ROOT_INSIDE ) {
1520 return ;
1621 }
17- const login = yield select ( state => state . login ) ;
18- const server = yield select ( state => state . server ) ;
19- if (
20- ! login . isAuthenticated ||
21- login . isFetching ||
22- server . connecting ||
23- server . loading ||
24- server . changingServer ||
25- ! Navigation . navigationRef . current
26- ) {
22+ const isReady = yield isAuthAndConnected ( ) ;
23+ if ( ! isReady ) {
2724 return ;
2825 }
2926 try {
30- yield localAuthenticate ( server . server ) ;
27+ const server = yield select ( state => state . server . server ) ;
28+ yield localAuthenticate ( server ) ;
3129 checkAndReopen ( ) ;
3230 // Check for pending notification when app comes to foreground (Android - notification tap while in background)
3331 checkPendingNotification ( ) . catch ( ( e ) => {
@@ -41,13 +39,16 @@ const appHasComeBackToForeground = function* appHasComeBackToForeground() {
4139
4240const appHasComeBackToBackground = function * appHasComeBackToBackground ( ) {
4341 const appRoot = yield select ( state => state . app . root ) ;
44- if ( appRoot === RootEnum . ROOT_OUTSIDE ) {
42+ if ( appRoot !== RootEnum . ROOT_INSIDE ) {
43+ return ;
44+ }
45+ const isReady = yield isAuthAndConnected ( ) ;
46+ if ( ! isReady ) {
4547 return ;
4648 }
4749 try {
4850 const server = yield select ( state => state . server . server ) ;
4951 yield saveLastLocalAuthenticationSession ( server ) ;
50-
5152 yield setUserPresenceAway ( ) ;
5253 } catch ( e ) {
5354 log ( e ) ;
0 commit comments