forked from Ivasoft/mattermost-mobile
* RN-379 Added websocket state to device state * Fixed view store blacklist * RN-379 Get posts since last websocket disconnect when viewing channel * Used Date.now instead of new Date().getTime()
35 lines
969 B
JavaScript
35 lines
969 B
JavaScript
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
import {GeneralTypes, UserTypes} from 'mattermost-redux/action_types';
|
|
|
|
function getInitialState() {
|
|
return {
|
|
connected: false,
|
|
lastConnectAt: 0,
|
|
lastDisconnectAt: 0
|
|
};
|
|
}
|
|
|
|
export default function(state = getInitialState(), action) {
|
|
if (!state.connected && action.type === GeneralTypes.WEBSOCKET_SUCCESS) {
|
|
return {
|
|
...state,
|
|
connected: true,
|
|
lastConnectAt: new Date().getTime()
|
|
};
|
|
} else if (state.connected && (action.type === GeneralTypes.WEBSOCKET_FAILURE || action.type === GeneralTypes.WEBSOCKET_CLOSED)) {
|
|
return {
|
|
...state,
|
|
connected: false,
|
|
lastDisconnectAt: new Date().getTime()
|
|
};
|
|
}
|
|
|
|
if (action.type === UserTypes.LOGOUT_SUCCESS) {
|
|
return getInitialState();
|
|
}
|
|
|
|
return state;
|
|
}
|