PLT-4233 When internet reconnects, reconnect websocket and grab latest posts, etc. (#4500)

* When internet reconnects, reconnect websocket and grab latest posts, etc.

* Rename internet connection variable
Этот коммит содержится в:
Joram Wilander
2016-11-29 10:37:59 -05:00
коммит произвёл enahum
родитель 58215e573f
Коммит 557aa68636
4 изменённых файлов: 30 добавлений и 6 удалений

Просмотреть файл

@@ -67,12 +67,13 @@ export function close() {
WebSocketClient.close(); WebSocketClient.close();
} }
export function getStatuses() { export function reconnect() {
StatusActions.loadStatusesForChannelAndSidebar(); close();
initialize();
handleReconnect();
} }
function handleFirstConnect() { function handleFirstConnect() {
getStatuses();
ErrorStore.clearLastError(); ErrorStore.clearLastError();
ErrorStore.emitChange(); ErrorStore.emitChange();
} }
@@ -83,7 +84,7 @@ function handleReconnect() {
loadPosts(ChannelStore.getCurrentId()); loadPosts(ChannelStore.getCurrentId());
} }
getStatuses(); StatusActions.loadStatusesForChannelAndSidebar();
ErrorStore.clearLastError(); ErrorStore.clearLastError();
ErrorStore.emitChange(); ErrorStore.emitChange();
} }

Просмотреть файл

@@ -156,6 +156,10 @@ export default class Client {
// NO-OP for inherited classes to override // NO-OP for inherited classes to override
} }
handleSuccess(res) { // eslint-disable-line no-unused-vars
// NO-OP for inherited classes to override
}
handleResponse(methodName, successCallback, errorCallback, err, res) { handleResponse(methodName, successCallback, errorCallback, err, res) {
if (res && res.header) { if (res && res.header) {
this.serverVersion = res.header[HEADER_X_VERSION_ID]; this.serverVersion = res.header[HEADER_X_VERSION_ID];
@@ -212,6 +216,7 @@ export default class Client {
console.error('Missing response body for ' + methodName); // eslint-disable-line no-console console.error('Missing response body for ' + methodName); // eslint-disable-line no-console
successCallback('', res); successCallback('', res);
} }
this.handleSuccess(res);
} }
} }

Просмотреть файл

@@ -2,9 +2,12 @@
// See License.txt for license information. // See License.txt for license information.
import Client from './client.jsx'; import Client from './client.jsx';
import TeamStore from '../stores/team_store.jsx';
import BrowserStore from '../stores/browser_store.jsx'; import TeamStore from 'stores/team_store.jsx';
import BrowserStore from 'stores/browser_store.jsx';
import * as GlobalActions from 'actions/global_actions.jsx'; import * as GlobalActions from 'actions/global_actions.jsx';
import {reconnect} from 'actions/websocket_actions.jsx';
import request from 'superagent'; import request from 'superagent';
@@ -14,6 +17,7 @@ class WebClientClass extends Client {
constructor() { constructor() {
super(); super();
this.enableLogErrorsToConsole(true); this.enableLogErrorsToConsole(true);
this.hasInternetConnection = true;
TeamStore.addChangeListener(this.onTeamStoreChanged.bind(this)); TeamStore.addChangeListener(this.onTeamStoreChanged.bind(this));
} }
@@ -37,6 +41,17 @@ class WebClientClass extends Client {
if (err.status === HTTP_UNAUTHORIZED && res.req.url !== '/api/v3/users/login') { if (err.status === HTTP_UNAUTHORIZED && res.req.url !== '/api/v3/users/login') {
GlobalActions.emitUserLoggedOutEvent('/login'); GlobalActions.emitUserLoggedOutEvent('/login');
} }
if (err.status == null) {
this.hasInternetConnection = false;
}
}
handleSuccess = (res) => { // eslint-disable-line no-unused-vars
if (res && !this.hasInternetConnection) {
reconnect();
this.hasInternetConnection = true;
}
} }
// not sure why but super.login doesn't work if using an () => arrow functions. // not sure why but super.login doesn't work if using an () => arrow functions.

Просмотреть файл

@@ -7,6 +7,7 @@ import {browserHistory} from 'react-router/es6';
import TeamStore from 'stores/team_store.jsx'; import TeamStore from 'stores/team_store.jsx';
import * as GlobalActions from 'actions/global_actions.jsx'; import * as GlobalActions from 'actions/global_actions.jsx';
import {loadStatusesForChannelAndSidebar} from 'actions/status_actions.jsx';
import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import Constants from 'utils/constants.jsx'; import Constants from 'utils/constants.jsx';
const ActionTypes = Constants.ActionTypes; const ActionTypes = Constants.ActionTypes;
@@ -85,6 +86,8 @@ function preNeedsTeam(nextState, replace, callback) {
channels: data channels: data
}); });
loadStatusesForChannelAndSidebar();
d1.resolve(); d1.resolve();
}, },
(err) => { (err) => {