From d08f1ca3fb71407d273398615a0a7c90548f772e Mon Sep 17 00:00:00 2001 From: Alex DeCamillo Date: Mon, 18 Sep 2023 23:48:59 -0700 Subject: [PATCH] MM-54356: In-correct User count when adding members that already exists to the channel (#24540) * Only add user who isn't in the channel * Update webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts Co-authored-by: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> --------- Co-authored-by: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Co-authored-by: Mattermost Build --- .../mattermost-redux/src/actions/channels.ts | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts index d2d3cdf1d1..5f788e5c67 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts @@ -1049,20 +1049,23 @@ export function addChannelMember(channelId: string, userId: string, postRootId = Client4.trackEvent('action', 'action_channels_add_member', {channel_id: channelId}); - dispatch(batchActions([ - { - type: UserTypes.RECEIVED_PROFILE_IN_CHANNEL, - data: {id: channelId, user_id: userId}, - }, - { - type: ChannelTypes.RECEIVED_CHANNEL_MEMBER, - data: member, - }, - { - type: ChannelTypes.ADD_CHANNEL_MEMBER_SUCCESS, - id: channelId, - }, - ], 'ADD_CHANNEL_MEMBER.BATCH')); + const membersInChannel = getState().entities.channels.membersInChannel[channelId]; + if (!(membersInChannel && userId in membersInChannel)) { + dispatch(batchActions([ + { + type: UserTypes.RECEIVED_PROFILE_IN_CHANNEL, + data: {id: channelId, user_id: userId}, + }, + { + type: ChannelTypes.RECEIVED_CHANNEL_MEMBER, + data: member, + }, + { + type: ChannelTypes.ADD_CHANNEL_MEMBER_SUCCESS, + id: channelId, + }, + ], 'ADD_CHANNEL_MEMBER.BATCH')); + } return {data: member}; };