From e6547c69700e90925b159349a143ca9b64b95bb3 Mon Sep 17 00:00:00 2001 From: enahum Date: Mon, 27 Feb 2017 16:10:39 -0300 Subject: [PATCH] PLT-5502 Update statuses (#302) --- app/components/root/root.js | 6 +++++- app/components/root/root_container.js | 3 +++ service/actions/users.js | 25 ++++++++++++++++++++++++- service/constants/constants.js | 1 + 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/components/root/root.js b/app/components/root/root.js index 6f89e3483..b311b28a6 100644 --- a/app/components/root/root.js +++ b/app/components/root/root.js @@ -14,7 +14,9 @@ export default class Root extends React.Component { locale: React.PropTypes.string.isRequired, actions: React.PropTypes.shape({ loadConfigAndLicense: React.PropTypes.func.isRequired, - setAppState: React.PropTypes.func + startPeriodicStatusUpdates: React.PropTypes.func.isRequired, + stopPeriodicStatusUpdates: React.PropTypes.func.isRequired, + setAppState: React.PropTypes.func.isRequired }).isRequired }; @@ -29,11 +31,13 @@ export default class Root extends React.Component { componentDidMount() { AppState.addEventListener('change', this.handleAppStateChange); EventEmitter.on(Constants.CONFIG_CHANGED, this.handleConfigChanged); + this.props.actions.startPeriodicStatusUpdates(); } componentWillUnmount() { AppState.removeEventListener('change', this.handleAppStateChange); EventEmitter.off(Constants.CONFIG_CHANGED, this.handleConfigChanged); + this.props.actions.stopPeriodicStatusUpdates(); } handleAppStateChange(appState) { diff --git a/app/components/root/root_container.js b/app/components/root/root_container.js index 3e17153af..e066ea087 100644 --- a/app/components/root/root_container.js +++ b/app/components/root/root_container.js @@ -8,6 +8,7 @@ import Config from 'assets/config.json'; import {loadConfigAndLicense} from 'app/actions/views/root'; import {setAppState} from 'service/actions/general'; +import {startPeriodicStatusUpdates, stopPeriodicStatusUpdates} from 'service/actions/users'; import Root from './root'; @@ -30,6 +31,8 @@ function mapDispatchToProps(dispatch) { return { actions: bindActionCreators({ loadConfigAndLicense, + startPeriodicStatusUpdates, + stopPeriodicStatusUpdates, setAppState }, dispatch) }; diff --git a/service/actions/users.js b/service/actions/users.js index 3ee5af450..c2667ba85 100644 --- a/service/actions/users.js +++ b/service/actions/users.js @@ -369,6 +369,27 @@ export function searchProfiles(term, options) { ); } +let statusIntervalId = ''; +export function startPeriodicStatusUpdates() { + return async (dispatch, getState) => { + clearInterval(statusIntervalId); + + statusIntervalId = setInterval( + () => { + const {statuses} = getState().entities.users; + getStatusesByIds(Object.keys(statuses))(dispatch, getState); + }, + Constants.STATUS_INTERVAL + ); + }; +} + +export function stopPeriodicStatusUpdates() { + return async () => { + clearInterval(statusIntervalId); + }; +} + export default { checkMfa, login, @@ -382,5 +403,7 @@ export default { getSessions, revokeSession, getAudits, - searchProfiles + searchProfiles, + startPeriodicStatusUpdates, + stopPeriodicStatusUpdates }; diff --git a/service/constants/constants.js b/service/constants/constants.js index af1815cff..70b191cf1 100644 --- a/service/constants/constants.js +++ b/service/constants/constants.js @@ -8,6 +8,7 @@ const Constants = { PROFILE_CHUNK_SIZE: 100, CHANNELS_CHUNK_SIZE: 50, SEARCH_TIMEOUT_MILLISECONDS: 100, + STATUS_INTERVAL: 60000, MENTION: 'mention',