From e9e1dc054170395348a0b07b028b08cba23b0fbe Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Wed, 2 Oct 2019 20:34:41 +0200 Subject: [PATCH] Automated cherry pick of #3343 (#3363) * MM-18999 Fix search in: modifier to show the appropriate badge when needed for DM/GM * feedback review * fix eslint * fix eslint disable rule --- .../channel_mention/channel_mention.js | 2 -- .../channel_mention_item.js | 31 +++++++++++++------ .../channel_mention_item/index.js | 19 ++++++------ .../main/channels_list/channel_item/index.js | 18 +++++------ 4 files changed, 39 insertions(+), 31 deletions(-) diff --git a/app/components/autocomplete/channel_mention/channel_mention.js b/app/components/autocomplete/channel_mention/channel_mention.js index 627679bb1..928b73ff1 100644 --- a/app/components/autocomplete/channel_mention/channel_mention.js +++ b/app/components/autocomplete/channel_mention/channel_mention.js @@ -10,7 +10,6 @@ import {isMinimumServerVersion} from 'mattermost-redux/utils/helpers'; import {debounce} from 'mattermost-redux/actions/helpers'; import {CHANNEL_MENTION_REGEX, CHANNEL_MENTION_SEARCH_REGEX} from 'app/constants/autocomplete'; -import AutocompleteDivider from 'app/components/autocomplete/autocomplete_divider'; import AutocompleteSectionHeader from 'app/components/autocomplete/autocomplete_section_header'; import ChannelMentionItem from 'app/components/autocomplete/channel_mention_item'; import {makeStyleSheetFromTheme} from 'app/utils/theme'; @@ -231,7 +230,6 @@ export default class ChannelMention extends PureComponent { sections={sections} renderItem={this.renderItem} renderSectionHeader={this.renderSectionHeader} - ItemSeparatorComponent={AutocompleteDivider} initialNumToRender={10} nestedScrollEnabled={nestedScrollEnabled} /> diff --git a/app/components/autocomplete/channel_mention_item/channel_mention_item.js b/app/components/autocomplete/channel_mention_item/channel_mention_item.js index 226af6fe9..599249a43 100644 --- a/app/components/autocomplete/channel_mention_item/channel_mention_item.js +++ b/app/components/autocomplete/channel_mention_item/channel_mention_item.js @@ -8,6 +8,7 @@ import { } from 'react-native'; import {General} from 'mattermost-redux/constants'; +import AutocompleteDivider from 'app/components/autocomplete/autocomplete_divider'; import {BotTag, GuestTag} from 'app/components/tag'; import {paddingHorizontal as padding} from 'app/components/safe_area_view/iphone_x_spacing'; import TouchableWithFeedback from 'app/components/touchable_with_feedback'; @@ -49,11 +50,13 @@ export default class ChannelMentionItem extends PureComponent { const style = getStyleFromTheme(theme); + let component; if (type === General.DM_CHANNEL || type === General.GM_CHANNEL) { if (!displayName) { return null; } - return ( + + component = ( ); + } else { + component = ( + + {displayName} + {` (~${name})`} + + ); } + return ( - - {displayName} - {` (~${name})`} - + + {component} + + ); } } diff --git a/app/components/autocomplete/channel_mention_item/index.js b/app/components/autocomplete/channel_mention_item/index.js index 3bf635684..c70208684 100644 --- a/app/components/autocomplete/channel_mention_item/index.js +++ b/app/components/autocomplete/channel_mention_item/index.js @@ -4,28 +4,28 @@ import {connect} from 'react-redux'; import {General} from 'mattermost-redux/constants'; - import {getChannel} from 'mattermost-redux/selectors/entities/channels'; - import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; +import {getUser} from 'mattermost-redux/selectors/entities/users'; import {getChannelNameForSearchAutocomplete} from 'app/selectors/channel'; +import {isLandscape} from 'app/selectors/device'; +import {isGuest as isGuestUser} from 'app/utils/users'; import ChannelMentionItem from './channel_mention_item'; -import {getUser} from 'mattermost-redux/selectors/entities/users'; - -import {isLandscape} from 'app/selectors/device'; - function mapStateToProps(state, ownProps) { const channel = getChannel(state, ownProps.channelId); - const displayName = getChannelNameForSearchAutocomplete(state, ownProps.channelId); + let displayName = getChannelNameForSearchAutocomplete(state, ownProps.channelId); let isBot = false; + let isGuest = false; if (channel.type === General.DM_CHANNEL) { const teammate = getUser(state, channel.teammate_id); - if (teammate && teammate.is_bot) { - isBot = true; + if (teammate) { + displayName = teammate.username; + isBot = teammate.is_bot || false; + isGuest = isGuestUser(teammate) || false; } } @@ -34,6 +34,7 @@ function mapStateToProps(state, ownProps) { name: channel.name, type: channel.type, isBot, + isGuest, theme: getTheme(state), isLandscape: isLandscape(state), }; diff --git a/app/components/sidebars/main/channels_list/channel_item/index.js b/app/components/sidebars/main/channels_list/channel_item/index.js index f79b7dedf..60c4141c2 100644 --- a/app/components/sidebars/main/channels_list/channel_item/index.js +++ b/app/components/sidebars/main/channels_list/channel_item/index.js @@ -35,18 +35,16 @@ function makeMapStateToProps() { let isArchived = channel.delete_at > 0; if (channel.type === General.DM_CHANNEL) { - if (ownProps.isSearchResult) { - isBot = Boolean(channel.isBot); - } else { - const teammateId = getUserIdFromChannelName(currentUserId, channel.name); - const teammate = getUser(state, teammateId); + const teammateId = getUserIdFromChannelName(currentUserId, channel.name); + const teammate = getUser(state, teammateId); + + isBot = Boolean(ownProps.isSearchResult ? channel.isBot : teammate?.is_bot); //eslint-disable-line camelcase + + if (teammate) { const teammateNameDisplay = getTeammateNameDisplaySetting(state); displayName = displayUsername(teammate, teammateNameDisplay, false); - if (teammate) { - isArchived = teammate.delete_at > 0; - isBot = teammate.is_bot || false; - } - isGuest = isGuestUser(teammate); + isArchived = teammate.delete_at > 0; + isGuest = isGuestUser(teammate) || false; } }