Skip to content

Commit 3a34fa3

Browse files
committed
Changes to logic
1 parent e1af190 commit 3a34fa3

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

app/sagas/login.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { getUserPresence, subscribeUsersPresence } from '../lib/methods/getUsers
3232
import { logout, removeServerData, removeServerDatabase } from '../lib/methods/logout';
3333
import { subscribeSettings } from '../lib/methods/getSettings';
3434
import { connect, loginWithPassword, login } from '../lib/services/connect';
35-
import { saveUserProfile, registerPushToken, getUsersRoles } from '../lib/services/restApi';
35+
import { saveUserProfile, registerPushToken, getUsersRoles, setUserPresenceAway } from '../lib/services/restApi';
3636
import { setUsersRoles } from '../actions/usersRoles';
3737
import { getServerById } from '../lib/database/services/Server';
3838
import appNavigation from '../lib/navigation/appNavigation';
@@ -223,6 +223,17 @@ const fetchUsersRoles = function* fetchRoomsFork() {
223223
}
224224
};
225225

226+
const checkBackgroundAndSetAway = function* checkBackgroundAndSetAway() {
227+
try {
228+
const isBackground = yield select(state => state.app.background);
229+
if (isBackground) {
230+
yield setUserPresenceAway();
231+
}
232+
} catch (e) {
233+
log(e);
234+
}
235+
};
236+
226237
const handleLoginSuccess = function* handleLoginSuccess({ user }) {
227238
try {
228239
getUserPresence(user.id);
@@ -239,6 +250,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
239250
yield fork(fetchEnterpriseModulesFork, { user });
240251
yield fork(subscribeSettingsFork);
241252
yield fork(fetchUsersRoles);
253+
yield fork(checkBackgroundAndSetAway);
242254

243255
setLanguage(user?.language);
244256

app/sagas/state.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { select, takeLatest } from 'redux-saga/effects';
22

3-
import Navigation from '../lib/navigation/appNavigation';
43
import log from '../lib/methods/helpers/log';
54
import { localAuthenticate, saveLastLocalAuthenticationSession } from '../lib/methods/helpers/localAuthentication';
65
import { APP_STATE } from '../actions/actionsTypes';
@@ -9,25 +8,24 @@ import { checkAndReopen } from '../lib/services/connect';
98
import { setUserPresenceOnline, setUserPresenceAway } from '../lib/services/restApi';
109
import { 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+
1217
const 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

4240
const 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

Comments
 (0)