2017-12-04 18:24:21 +00:00
|
|
|
import { takeLatest, select } from 'redux-saga/effects';
|
2018-12-05 20:52:08 +00:00
|
|
|
import { FOREGROUND, BACKGROUND } from 'redux-enhancer-react-native-appstate';
|
2017-11-28 11:01:18 +00:00
|
|
|
|
2017-12-04 18:24:21 +00:00
|
|
|
import RocketChat from '../lib/rocketchat';
|
2018-10-31 18:40:39 +00:00
|
|
|
import { setBadgeCount } from '../push';
|
2019-05-28 16:18:46 +00:00
|
|
|
import log from '../utils/log';
|
2017-12-04 18:24:21 +00:00
|
|
|
|
2017-11-28 11:01:18 +00:00
|
|
|
const appHasComeBackToForeground = function* appHasComeBackToForeground() {
|
2018-08-01 19:35:06 +00:00
|
|
|
const appRoot = yield select(state => state.app.root);
|
|
|
|
if (appRoot === 'outside') {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-04 18:24:21 +00:00
|
|
|
const auth = yield select(state => state.login.isAuthenticated);
|
|
|
|
if (!auth) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
2018-10-31 18:40:39 +00:00
|
|
|
setBadgeCount();
|
2018-05-18 17:55:08 +00:00
|
|
|
return yield RocketChat.setUserPresenceOnline();
|
|
|
|
} catch (e) {
|
2019-05-28 16:18:46 +00:00
|
|
|
log('err_app_has_come_back_to_foreground', e);
|
2018-05-18 17:55:08 +00:00
|
|
|
}
|
2017-12-04 18:24:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const appHasComeBackToBackground = function* appHasComeBackToBackground() {
|
2018-08-01 19:35:06 +00:00
|
|
|
const appRoot = yield select(state => state.app.root);
|
|
|
|
if (appRoot === 'outside') {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-04 18:24:21 +00:00
|
|
|
const auth = yield select(state => state.login.isAuthenticated);
|
|
|
|
if (!auth) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
|
|
|
return yield RocketChat.setUserPresenceAway();
|
|
|
|
} catch (e) {
|
2019-05-28 16:18:46 +00:00
|
|
|
log('err_app_has_come_back_to_background', e);
|
2018-05-18 17:55:08 +00:00
|
|
|
}
|
2017-11-28 11:01:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const root = function* root() {
|
|
|
|
yield takeLatest(
|
|
|
|
FOREGROUND,
|
|
|
|
appHasComeBackToForeground
|
|
|
|
);
|
|
|
|
yield takeLatest(
|
|
|
|
BACKGROUND,
|
2017-12-04 18:24:21 +00:00
|
|
|
appHasComeBackToBackground
|
2017-11-28 11:01:18 +00:00
|
|
|
);
|
2018-12-05 20:52:08 +00:00
|
|
|
// yield takeLatest(
|
|
|
|
// INACTIVE,
|
|
|
|
// appHasComeBackToBackground
|
|
|
|
// );
|
2017-11-28 11:01:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default root;
|