vn-verdnaturachat/app/sagas/state.js

57 lines
1.3 KiB
JavaScript
Raw Normal View History

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