MM-10300 Fix crash when leaving channel (#1606)
This commit is contained in:
parent
5385a1e5fa
commit
7db7a311f1
3 changed files with 40 additions and 4 deletions
|
|
@ -400,11 +400,23 @@ export function refreshChannelWithRetry(channelId) {
|
|||
|
||||
export function leaveChannel(channel, reset = false) {
|
||||
return async (dispatch, getState) => {
|
||||
const {currentTeamId} = getState().entities.teams;
|
||||
await serviceLeaveChannel(channel.id)(dispatch, getState);
|
||||
if (channel.isCurrent || reset) {
|
||||
await selectInitialChannel(currentTeamId)(dispatch, getState);
|
||||
const state = getState();
|
||||
const {currentChannelId} = state.entities.channels;
|
||||
const {currentTeamId} = state.entities.teams;
|
||||
|
||||
dispatch({
|
||||
type: ViewTypes.REMOVE_LAST_CHANNEL_FOR_TEAM,
|
||||
data: {
|
||||
teamId: currentTeamId,
|
||||
channelId: channel.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (channel.id === currentChannelId || reset) {
|
||||
await dispatch(selectInitialChannel(currentTeamId));
|
||||
}
|
||||
|
||||
await serviceLeaveChannel(channel.id)(dispatch, getState);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ const ViewTypes = keyMirror({
|
|||
SET_CHANNEL_DISPLAY_NAME: null,
|
||||
|
||||
SET_LAST_CHANNEL_FOR_TEAM: null,
|
||||
REMOVE_LAST_CHANNEL_FOR_TEAM: null,
|
||||
|
||||
GITLAB: null,
|
||||
SAML: null,
|
||||
|
|
|
|||
|
|
@ -44,6 +44,29 @@ function lastChannelForTeam(state = {}, action) {
|
|||
[action.teamId]: channelIds,
|
||||
};
|
||||
}
|
||||
case ViewTypes.REMOVE_LAST_CHANNEL_FOR_TEAM: {
|
||||
const {data} = action;
|
||||
const team = state[data.teamId];
|
||||
|
||||
if (!data.channelId) {
|
||||
return state;
|
||||
}
|
||||
|
||||
if (team) {
|
||||
const channelIds = [...team];
|
||||
const index = channelIds.indexOf(data.channelId);
|
||||
if (index !== -1) {
|
||||
channelIds.splice(index, 1);
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
[data.teamId]: channelIds,
|
||||
};
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue