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
This commit is contained in:
Mattermost Build 2019-10-02 20:34:41 +02:00 committed by Elias Nahum
parent c55dcaf598
commit e9e1dc0541
4 changed files with 39 additions and 31 deletions

View file

@ -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}
/>

View file

@ -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 = (
<TouchableWithFeedback
key={channelId}
onPress={this.completeMention}
@ -71,17 +74,25 @@ export default class ChannelMentionItem extends PureComponent {
/>
</TouchableWithFeedback>
);
} else {
component = (
<TouchableWithFeedback
key={channelId}
onPress={this.completeMention}
style={[style.row, padding(isLandscape)]}
type={'opacity'}
>
<Text style={style.rowDisplayName}>{displayName}</Text>
<Text style={style.rowName}>{` (~${name})`}</Text>
</TouchableWithFeedback>
);
}
return (
<TouchableWithFeedback
key={channelId}
onPress={this.completeMention}
style={[style.row, padding(isLandscape)]}
type={'opacity'}
>
<Text style={style.rowDisplayName}>{displayName}</Text>
<Text style={style.rowName}>{` (~${name})`}</Text>
</TouchableWithFeedback>
<React.Fragment>
{component}
<AutocompleteDivider/>
</React.Fragment>
);
}
}

View file

@ -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),
};

View file

@ -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;
}
}