mattermost-redux
Version:
Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client
49 lines (48 loc) • 1.57 kB
JavaScript
;
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = reducer;
const action_types_1 = require("mattermost-redux/action_types");
function getInitialState() {
return {
connected: false,
lastConnectAt: 0,
lastDisconnectAt: 0,
connectionId: '',
serverHostname: '',
};
}
function reducer(state = getInitialState(), action) {
if (!state.connected && action.type === action_types_1.GeneralTypes.WEBSOCKET_SUCCESS) {
return {
...state,
connected: true,
lastConnectAt: action.timestamp,
};
}
else if (state.connected && (action.type === action_types_1.GeneralTypes.WEBSOCKET_FAILURE || action.type === action_types_1.GeneralTypes.WEBSOCKET_CLOSED)) {
return {
...state,
connected: false,
lastDisconnectAt: action.timestamp,
serverHostname: '',
};
}
if (action.type === action_types_1.UserTypes.LOGOUT_SUCCESS) {
return getInitialState();
}
if (action.type === action_types_1.GeneralTypes.SET_CONNECTION_ID) {
return {
...state,
connectionId: action.payload.connectionId,
};
}
if (action.type === action_types_1.GeneralTypes.SET_SERVER_HOSTNAME) {
return {
...state,
serverHostname: action.payload.serverHostname,
};
}
return state;
}