mattermost-mobile/app/mm-redux/reducers/websocket.ts
Elias Nahum d3a6e166ad
MM-15758 Update dependencies including Fastlane (#4272)
* Update dependencies including Fastlane and disable Flipper on iOS

* Remove EventEmitter for previous doc-viewer

* Fix android crash when setting more channels buttons

* Downgrade fuse.js

* Upgrade deps to latest

* Update Podfile.lock

* Downgrade RNN to 6.4.0

* QA Review #2

* Upgrade fuse.js to 6.0.0
2020-05-18 11:24:47 -07:00

31 lines
931 B
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {GeneralTypes} from '@mm-redux/action_types';
import {GenericAction} from '@mm-redux/types/actions';
function getInitialState() {
return {
connected: false,
lastConnectAt: 0,
lastDisconnectAt: 0,
};
}
export default function reducer(state = getInitialState(), action: GenericAction) {
if (!state.connected && action.type === GeneralTypes.WEBSOCKET_SUCCESS) {
return {
...state,
connected: true,
lastConnectAt: action.timestamp,
};
} else if (state.connected && (action.type === GeneralTypes.WEBSOCKET_FAILURE || action.type === GeneralTypes.WEBSOCKET_CLOSED)) {
return {
...state,
connected: false,
lastDisconnectAt: action.timestamp,
};
}
return state;
}