UNPKG

mattermost-redux

Version:

Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client

36 lines (30 loc) 1.01 kB
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import {GeneralTypes, UserTypes} from 'action_types'; import {GenericAction} from '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, }; } if (action.type === UserTypes.LOGOUT_SUCCESS) { return getInitialState(); } return state; }