Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #137 from mattermost/leave
Browse files Browse the repository at this point in the history
Fix WS leave channel event
  • Loading branch information
jwilander authored and hmhealey committed Aug 28, 2020
1 parent 613e34a commit 4420ffd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/mattermost-redux/src/actions/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
updateChannelHeader,
updateChannelPurpose,
markChannelAsUnread,
markChannelAsRead
markChannelAsRead,
selectChannel
} from './channels';
import {
getPosts,
Expand Down Expand Up @@ -346,17 +347,28 @@ function handleUserAddedEvent(msg, dispatch, getState) {

function handleUserRemovedEvent(msg, dispatch, getState) {
const state = getState();
const {currentChannelId} = state.entities.channels;
const {channels, currentChannelId} = state.entities.channels;
const {currentTeamId} = state.entities.teams;
const {currentUserId} = state.entities.users;

if (msg.broadcast.user_id === currentUserId && currentTeamId) {
fetchMyChannelsAndMembers(currentTeamId)(dispatch, getState);
const channel = channels[currentChannelId] || {};
dispatch({
type: ChannelTypes.LEAVE_CHANNEL,
data: msg.data.channel_id
data: {
id: msg.data.channel_id,
user_id: currentUserId,
team_id: channel.team_id,
type: channel.type
}
}, getState);
} else if (msg.broadcast.channel_id === currentChannelId) {

if (msg.data.channel_id === currentChannelId) {
const defaultChannel = Object.values(channels).find((c) => c.team_id === currentTeamId && c.name === General.DEFAULT_CHANNEL);
selectChannel(defaultChannel.id)(dispatch, getState);
}
} else if (msg.data.channel_id === currentChannelId) {
getChannelStats(currentTeamId, currentChannelId)(dispatch, getState);
}
}
Expand Down

0 comments on commit 4420ffd

Please sign in to comment.