Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
[MM 7970] Support maintaining online status while the Desktop App is …
Browse files Browse the repository at this point in the history
…in the background ... and other things. (#2992)

* listen for os-level user status updates

* typo
  • Loading branch information
deanwhillier committed Jun 21, 2019
1 parent f0be50c commit dfff668
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion actions/global_actions.jsx
Expand Up @@ -318,4 +318,4 @@ export async function redirectUserToDefaultTeam() {
} else {
browserHistory.push('/select_team');
}
}
}
8 changes: 8 additions & 0 deletions client/websocket_client.jsx
Expand Up @@ -184,6 +184,14 @@ export default class WebSocketClient {
this.sendMessage('user_typing', data, callback);
}

userUpdateActiveStatus(userIsActive, manual, callback) {
const data = {
user_is_active: userIsActive,
manual,
};
this.sendMessage('user_update_active_status', data, callback);
}

getStatuses(callback) {
this.sendMessage('get_statuses', null, callback);
}
Expand Down
19 changes: 18 additions & 1 deletion components/logged_in/logged_in.jsx
Expand Up @@ -13,6 +13,8 @@ import * as UserAgent from 'utils/user_agent.jsx';
import LoadingScreen from 'components/loading_screen.jsx';
import {getBrowserTimezone} from 'utils/timezone.jsx';
import store from 'stores/redux_store.jsx';
import {webappConnector} from 'utils/webapp_connector';
import WebSocketClient from 'client/web_websocket_client.jsx';

const dispatch = store.dispatch;
const getState = store.getState;
Expand Down Expand Up @@ -69,6 +71,11 @@ export default class LoggedIn extends React.PureComponent {
window.addEventListener('focus', this.onFocusListener);
window.addEventListener('blur', this.onBlurListener);

// Listen for user activity updates from external sources via the webapp connector
if (webappConnector.active) {
webappConnector.on('user-activity-update', this.handleUserActivityUpdates);
}

// Because current CSS requires the root tag to have specific stuff

// Device tracking setup
Expand Down Expand Up @@ -132,9 +139,10 @@ export default class LoggedIn extends React.PureComponent {

$(window).off('keydown.preventBackspace');

// Listen for focussed tab/window state
window.removeEventListener('focus', this.onFocusListener);
window.removeEventListener('blur', this.onBlurListener);

webappConnector.removeListener('user-activity-update', this.handleUserActivityUpdates);
}

render() {
Expand Down Expand Up @@ -164,4 +172,13 @@ export default class LoggedIn extends React.PureComponent {
onBlurListener() {
GlobalActions.emitBrowserFocus(false);
}

handleUserActivityUpdates = ({userIsActive, manual}) => {
if (!this.props.currentUser) {
return;
}

// update the server with the users current away status
WebSocketClient.userUpdateActiveStatus(userIsActive, manual);
}
}
19 changes: 19 additions & 0 deletions utils/webapp_connector.js
@@ -0,0 +1,19 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

/**
* Create a placeholder webappConnector if one doesn't exist. Likely means we're not running in the desktop client.
*/
if (!window.webappConnector) {
window.webappConnector = {
active: false,
on: () => { }, //eslint-disable-line no-empty-function
removeListener: () => { }, //eslint-disable-line no-empty-function
emit: () => { }, //eslint-disable-line no-empty-function
};
}

/**
* Returns a reference to the webappConnector if available, or a placeholder object to silently ignore any interaction
*/
export const webappConnector = window.webappConnector;

0 comments on commit dfff668

Please sign in to comment.