Skip to content

Commit

Permalink
MM-20345: Adding changes for cleanup not longer visible users to the …
Browse files Browse the repository at this point in the history
…websockets event handlers (mattermost#4690)

* MM-20345: Adding changes for cleanup not longer visible users to the websockets event handlers

* Now handling the remove from team event

* Fixing tests

* Fixing current user id check

* Fixing the problem in a more general way

* Bumping the mattermost-redux version

Co-authored-by: mattermod <[email protected]>
  • Loading branch information
jespino and mattermod authored Mar 18, 2020
1 parent 6e17304 commit da9604d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
53 changes: 48 additions & 5 deletions actions/websocket_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ import {
getStatusesByIds,
getUser as loadUser,
} from 'mattermost-redux/actions/users';
import {removeNotVisibleUsers} from 'mattermost-redux/actions/websocket';
import {Client4} from 'mattermost-redux/client';
import {getCurrentUser, getCurrentUserId, getStatusForUserId, getUser, getIsManualStatusForUserId} from 'mattermost-redux/selectors/entities/users';
import {getMyTeams, getCurrentRelativeTeamUrl, getCurrentTeamId, getCurrentTeamUrl} from 'mattermost-redux/selectors/entities/teams';
import {getMyTeams, getCurrentRelativeTeamUrl, getCurrentTeamId, getCurrentTeamUrl, getTeam} from 'mattermost-redux/selectors/entities/teams';
import {getConfig} from 'mattermost-redux/selectors/entities/general';
import {getChannelsInTeam, getChannel, getCurrentChannel, getCurrentChannelId, getRedirectChannelNameForTeam, getMembersInCurrentChannel} from 'mattermost-redux/selectors/entities/channels';
import {getChannelsInTeam, getChannel, getCurrentChannel, getCurrentChannelId, getRedirectChannelNameForTeam, getMembersInCurrentChannel, getChannelMembersInChannels} from 'mattermost-redux/selectors/entities/channels';
import {getPost, getMostRecentPostIdInChannel} from 'mattermost-redux/selectors/entities/posts';
import {haveISystemPermission, haveITeamPermission} from 'mattermost-redux/selectors/entities/roles';

Expand Down Expand Up @@ -603,8 +604,9 @@ export function handleLeaveTeamEvent(msg) {
}

dispatch(batchActions(actions));
const currentUser = getCurrentUser(state);

if (getCurrentUserId(state) === msg.data.user_id) {
if (currentUser.id === msg.data.user_id) {
dispatch({type: TeamTypes.LEAVE_TEAM, data: {id: msg.data.team_id}});

// if they are on the team being removed redirect them to default team
Expand All @@ -613,6 +615,25 @@ export function handleLeaveTeamEvent(msg) {
redirectUserToDefaultTeam();
}
}
if (isGuest(currentUser)) {
dispatch(removeNotVisibleUsers());
}
} else {
const team = getTeam(state, msg.data.team_id);
const members = getChannelMembersInChannels(state);
const isMember = Object.values(members).some((member) => member[msg.data.user_id]);
if (team && isGuest(currentUser) && !isMember) {
dispatch(batchActions([
{
type: UserTypes.PROFILE_NO_LONGER_VISIBLE,
data: {user_id: msg.data.user_id},
},
{
type: TeamTypes.REMOVE_MEMBER_FROM_TEAM,
data: {team_id: team.id, user_id: msg.data.user_id},
},
]));
}
}
}

Expand Down Expand Up @@ -712,9 +733,9 @@ function handleUserAddedEvent(msg) {
export function handleUserRemovedEvent(msg) {
const state = getState();
const currentChannel = getCurrentChannel(state) || {};
const currentUserId = getCurrentUserId(state);
const currentUser = getCurrentUser(state);

if (msg.broadcast.user_id === currentUserId) {
if (msg.broadcast.user_id === currentUser.id) {
dispatch(loadChannelsForCurrentUser());

const rhsChannelId = getSelectedChannelId(state);
Expand Down Expand Up @@ -747,6 +768,9 @@ export function handleUserRemovedEvent(msg) {
type: ChannelTypes.LEAVE_CHANNEL,
data: {id: msg.data.channel_id, user_id: msg.broadcast.user_id},
});
if (isGuest(currentUser)) {
dispatch(removeNotVisibleUsers());
}
} else if (msg.broadcast.channel_id === currentChannel.id) {
dispatch(getChannelStats(currentChannel.id));
dispatch({
Expand All @@ -755,6 +779,25 @@ export function handleUserRemovedEvent(msg) {
});
}

if (msg.broadcast.user_id !== currentUser.id) {
const channel = getChannel(state, msg.broadcast.channel_id);
const members = getChannelMembersInChannels(state);
const isMember = Object.values(members).some((member) => member[msg.data.user_id]);
if (channel && isGuest(currentUser) && !isMember) {
const actions = [
{
type: UserTypes.PROFILE_NO_LONGER_VISIBLE,
data: {user_id: msg.data.user_id},
},
{
type: TeamTypes.REMOVE_MEMBER_FROM_TEAM,
data: {team_id: channel.team_id, user_id: msg.data.user_id},
},
];
dispatch(batchActions(actions));
}
}

const channelId = msg.broadcast.channel_id || msg.data.channel_id;
const userId = msg.broadcast.user_id || msg.data.user_id;
const channel = getChannel(state, channelId);
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"localforage-observable": "2.0.0",
"mark.js": "8.11.1",
"marked": "github:mattermost/marked#5a06d1af25ca48927b9efe0d9c42c01c84e7839b",
"mattermost-redux": "github:mattermost/mattermost-redux#fbe252dd069b1e5ecfdf48f497ae8c39c472a6a2",
"mattermost-redux": "github:mattermost/mattermost-redux#5a0163bf77f29b2a17618b2f8529fd7171084205",
"moment-timezone": "0.5.27",
"pdfjs-dist": "2.0.489",
"popmotion": "8.7.0",
Expand Down

0 comments on commit da9604d

Please sign in to comment.