mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Add functionality for refetching latest data after computer wakes up (#5120)
This commit is contained in:
committed by
Harrison Healey
parent
36b62333b1
commit
0d8bb03b57
@@ -67,9 +67,15 @@ export function close() {
|
||||
WebSocketClient.close();
|
||||
}
|
||||
|
||||
export function reconnect() {
|
||||
function reconnectWebSocket() {
|
||||
close();
|
||||
initialize();
|
||||
}
|
||||
|
||||
export function reconnect(includeWebSocket = true) {
|
||||
if (includeWebSocket) {
|
||||
reconnectWebSocket();
|
||||
}
|
||||
|
||||
if (Client.teamId) {
|
||||
loadChannelsForCurrentUser();
|
||||
|
||||
@@ -8,6 +8,7 @@ import {browserHistory} from 'react-router/es6';
|
||||
import TeamStore from 'stores/team_store.jsx';
|
||||
import * as GlobalActions from 'actions/global_actions.jsx';
|
||||
import {loadStatusesForChannelAndSidebar} from 'actions/status_actions.jsx';
|
||||
import {reconnect} from 'actions/websocket_actions.jsx';
|
||||
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
|
||||
import Constants from 'utils/constants.jsx';
|
||||
const ActionTypes = Constants.ActionTypes;
|
||||
@@ -60,12 +61,28 @@ function doChannelChange(state, replace, callback) {
|
||||
callback();
|
||||
}
|
||||
|
||||
let wakeUpInterval;
|
||||
let lastTime = (new Date()).getTime();
|
||||
const WAKEUP_CHECK_INTERVAL = 30000; // 30 seconds
|
||||
const WAKEUP_THRESHOLD = 60000; // 60 seconds
|
||||
|
||||
function preNeedsTeam(nextState, replace, callback) {
|
||||
if (RouteUtils.checkIfMFARequired(nextState)) {
|
||||
browserHistory.push('/mfa/setup');
|
||||
return;
|
||||
}
|
||||
|
||||
clearInterval(wakeUpInterval);
|
||||
|
||||
wakeUpInterval = setInterval(() => {
|
||||
const currentTime = (new Date()).getTime();
|
||||
if (currentTime > (lastTime + WAKEUP_THRESHOLD)) { // ignore small delays
|
||||
console.log('computer woke up - fetching latest'); //eslint-disable-line no-console
|
||||
reconnect(false);
|
||||
}
|
||||
lastTime = currentTime;
|
||||
}, WAKEUP_CHECK_INTERVAL);
|
||||
|
||||
// First check to make sure you're in the current team
|
||||
// for the current url.
|
||||
const teamName = nextState.params.team;
|
||||
|
||||
Reference in New Issue
Block a user