2017-12-04 18:24:21 +00:00
|
|
|
import { takeLatest, select } from 'redux-saga/effects';
|
2017-11-28 11:01:18 +00:00
|
|
|
import { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate';
|
|
|
|
|
2017-12-04 18:24:21 +00:00
|
|
|
import RocketChat from '../lib/rocketchat';
|
2018-05-18 17:55:08 +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() {
|
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.setUserPresenceOnline();
|
|
|
|
} catch (e) {
|
|
|
|
log('appHasComeBackToForeground', e);
|
|
|
|
}
|
2017-12-04 18:24:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const appHasComeBackToBackground = function* appHasComeBackToBackground() {
|
|
|
|
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) {
|
|
|
|
log('appHasComeBackToBackground', e);
|
|
|
|
}
|
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
|
|
|
);
|
|
|
|
yield takeLatest(
|
|
|
|
INACTIVE,
|
2017-12-04 18:24:21 +00:00
|
|
|
appHasComeBackToBackground
|
2017-11-28 11:01:18 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default root;
|