From e1a0134021e82438a237a2c01297936f91187021 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 4 Dec 2017 14:32:07 -0200 Subject: [PATCH] - User presence away when app goes to background - User presence online when app comes back to foreground --- app/lib/rocketchat.js | 6 ++++++ app/sagas/state.js | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js index 74c439b83..885900b6d 100644 --- a/app/lib/rocketchat.js +++ b/app/lib/rocketchat.js @@ -520,6 +520,12 @@ const RocketChat = { emitTyping(room, t = true) { const { login } = reduxStore.getState(); return call('stream-notify-room', `${ room }/typing`, login.user.username, t); + }, + setUserPresenceAway() { + return call('UserPresence:away'); + }, + setUserPresenceOnline() { + return call('UserPresence:online'); } }; diff --git a/app/sagas/state.js b/app/sagas/state.js index 0f58ae7f9..a0659f8c3 100644 --- a/app/sagas/state.js +++ b/app/sagas/state.js @@ -1,8 +1,15 @@ import { takeLatest } from 'redux-saga/effects'; import { FOREGROUND, BACKGROUND, INACTIVE } from 'redux-enhancer-react-native-appstate'; +import RocketChat from '../lib/rocketchat'; const appHasComeBackToForeground = function* appHasComeBackToForeground() { yield console.log('appHasComeBackToForeground'); + return yield RocketChat.setUserPresenceOnline(); +}; + +const appHasComeBackToBackground = function* appHasComeBackToBackground() { + yield console.log('appHasComeBackToBackground'); + return yield RocketChat.setUserPresenceAway(); }; const root = function* root() { @@ -12,11 +19,11 @@ const root = function* root() { ); yield takeLatest( BACKGROUND, - appHasComeBackToForeground + appHasComeBackToBackground ); yield takeLatest( INACTIVE, - appHasComeBackToForeground + appHasComeBackToBackground ); };