From 1c758e22877ee6602b6834a7d3cf4d6057824a47 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Wed, 8 Aug 2018 00:18:09 +0800 Subject: [PATCH] [MM-10918] Filter system_remove_channel messages of a current user based on hiding/showing join/leave messages (#1955) * filter system_remove_channel messages of a current user based on hiding/showing join/leave messages * update mattermost-redux * makes the remove_from_channel/team shows after leave_channel/team * update per comments * revert change on mattermost-redux commit to prevent conflict with existing PR --- .../combined_system_message.js | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/app/components/combined_system_message/combined_system_message.js b/app/components/combined_system_message/combined_system_message.js index 52ee86612..f3841615e 100644 --- a/app/components/combined_system_message/combined_system_message.js +++ b/app/components/combined_system_message/combined_system_message.js @@ -304,14 +304,24 @@ export default class CombinedSystemMessage extends React.PureComponent { ); } + renderMessage(postType, userIds, actorId, style) { + return ( + + {this.renderFormattedMessage(postType, userIds, actorId, {baseText: style.baseText, linkText: style.linkText})} + + ); + } + render() { const { + currentUserId, messageData, theme, } = this.props; const style = getStyleSheet(theme); const content = []; + const removedUserIds = []; for (const message of messageData) { const { postType, @@ -319,23 +329,29 @@ export default class CombinedSystemMessage extends React.PureComponent { } = message; let userIds = message.userIds; - if (!this.props.showJoinLeave && actorId !== this.props.currentUserId) { - const affectsCurrentUser = userIds.indexOf(this.props.currentUserId) !== -1; + if (!this.props.showJoinLeave && actorId !== currentUserId) { + const affectsCurrentUser = userIds.indexOf(currentUserId) !== -1; if (affectsCurrentUser) { // Only show the message that the current user was added, etc - userIds = [this.props.currentUserId]; + userIds = [currentUserId]; } else { // Not something the current user did or was affected by continue; } } - content.push( - - {this.renderFormattedMessage(postType, userIds, actorId, {baseText: style.baseText, linkText: style.linkText})} - - ); + if (postType === REMOVE_FROM_CHANNEL) { + removedUserIds.push(...userIds); + continue; + } + + content.push(this.renderMessage(postType, userIds, actorId, style)); + } + + if (removedUserIds.length > 0) { + const uniqueRemovedUserIds = removedUserIds.filter((id, index, arr) => arr.indexOf(id) === index); + content.push(this.renderMessage(REMOVE_FROM_CHANNEL, uniqueRemovedUserIds, currentUserId, style)); } return (