Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
[MM-17253] Change to using ‘postMessage’ for desktop presence detecti…
Browse files Browse the repository at this point in the history
…on (mattermost#3548)

* change to ‘postMessage’ for desktop integration

* remove unused reference

* remove old connector
  • Loading branch information
deanwhillier authored and skheria committed Oct 3, 2019
1 parent a35fff5 commit 6fa92d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
25 changes: 15 additions & 10 deletions components/logged_in/logged_in.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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;
Expand Down Expand Up @@ -71,10 +70,8 @@ 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);
}
// Listen for messages from the desktop app
window.addEventListener('message', this.onDesktopMessageListener);

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

Expand Down Expand Up @@ -141,8 +138,7 @@ export default class LoggedIn extends React.PureComponent {

window.removeEventListener('focus', this.onFocusListener);
window.removeEventListener('blur', this.onBlurListener);

webappConnector.removeListener('user-activity-update', this.handleUserActivityUpdates);
window.removeEventListener('message', this.onDesktopMessageListener);
}

render() {
Expand Down Expand Up @@ -173,12 +169,21 @@ export default class LoggedIn extends React.PureComponent {
GlobalActions.emitBrowserFocus(false);
}

handleUserActivityUpdates = ({userIsActive, manual}) => {
onDesktopMessageListener = ({origin, data: {type, message: {userIsActive, manual} = {}} = {}} = {}) => {
if (!this.props.currentUser) {
return;
}
if (origin !== window.location.origin) {
return;
}

// update the server with the users current away status
WebSocketClient.userUpdateActiveStatus(userIsActive, manual);
switch (type) {
case 'user-activity-update':
// update the server with the users current away status
if (userIsActive === true || userIsActive === false) {
WebSocketClient.userUpdateActiveStatus(userIsActive, manual);
}
break;
}
}
}
19 changes: 0 additions & 19 deletions utils/webapp_connector.js

This file was deleted.

0 comments on commit 6fa92d1

Please sign in to comment.