Set user presence (online/away) (#127)
* - User presence away when app goes to background - User presence online when app comes back to foreground * test if user is connected before call userpresence * Update state.js
This commit is contained in:
parent
1edce04840
commit
b62596ac3f
|
@ -520,6 +520,12 @@ const RocketChat = {
|
||||||
emitTyping(room, t = true) {
|
emitTyping(room, t = true) {
|
||||||
const { login } = reduxStore.getState();
|
const { login } = reduxStore.getState();
|
||||||
return call('stream-notify-room', `${ room }/typing`, login.user.username, t);
|
return call('stream-notify-room', `${ room }/typing`, login.user.username, t);
|
||||||
|
},
|
||||||
|
setUserPresenceAway() {
|
||||||
|
return call('UserPresence:away');
|
||||||
|
},
|
||||||
|
setUserPresenceOnline() {
|
||||||
|
return call('UserPresence:online');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,22 @@
|
||||||
import { takeLatest } from 'redux-saga/effects';
|
import { takeLatest, select } from 'redux-saga/effects';
|
||||||
import { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate';
|
import { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate';
|
||||||
|
|
||||||
|
import RocketChat from '../lib/rocketchat';
|
||||||
|
|
||||||
const appHasComeBackToForeground = function* appHasComeBackToForeground() {
|
const appHasComeBackToForeground = function* appHasComeBackToForeground() {
|
||||||
yield console.log('appHasComeBackToForeground');
|
const auth = yield select(state => state.login.isAuthenticated);
|
||||||
|
if (!auth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return yield RocketChat.setUserPresenceOnline();
|
||||||
|
};
|
||||||
|
|
||||||
|
const appHasComeBackToBackground = function* appHasComeBackToBackground() {
|
||||||
|
const auth = yield select(state => state.login.isAuthenticated);
|
||||||
|
if (!auth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return yield RocketChat.setUserPresenceAway();
|
||||||
};
|
};
|
||||||
|
|
||||||
const root = function* root() {
|
const root = function* root() {
|
||||||
|
@ -12,11 +26,11 @@ const root = function* root() {
|
||||||
);
|
);
|
||||||
yield takeLatest(
|
yield takeLatest(
|
||||||
BACKGROUND,
|
BACKGROUND,
|
||||||
appHasComeBackToForeground
|
appHasComeBackToBackground
|
||||||
);
|
);
|
||||||
yield takeLatest(
|
yield takeLatest(
|
||||||
INACTIVE,
|
INACTIVE,
|
||||||
appHasComeBackToForeground
|
appHasComeBackToBackground
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue