diff --git a/app/components/autocomplete/channel_mention/channel_mention.js b/app/components/autocomplete/channel_mention/channel_mention.js index 25e21705c..639ecbb65 100644 --- a/app/components/autocomplete/channel_mention/channel_mention.js +++ b/app/components/autocomplete/channel_mention/channel_mention.js @@ -6,7 +6,6 @@ import PropTypes from 'prop-types'; import {Platform, SectionList} from 'react-native'; import {RequestStatus} from '@mm-redux/constants'; -import {isMinimumServerVersion} from '@mm-redux/utils/helpers'; import {debounce} from '@mm-redux/actions/helpers'; import {CHANNEL_MENTION_REGEX, CHANNEL_MENTION_SEARCH_REGEX} from 'app/constants/autocomplete'; @@ -37,7 +36,6 @@ export default class ChannelMention extends PureComponent { requestStatus: PropTypes.string.isRequired, theme: PropTypes.object.isRequired, value: PropTypes.string, - serverVersion: PropTypes.string, isLandscape: PropTypes.bool.isRequired, nestedScrollEnabled: PropTypes.bool, }; @@ -61,11 +59,7 @@ export default class ChannelMention extends PureComponent { } runSearch = debounce((currentTeamId, matchTerm) => { - if (isMinimumServerVersion(this.props.serverVersion, 5, 4)) { - this.props.actions.autocompleteChannelsForSearch(currentTeamId, matchTerm); - return; - } - this.props.actions.searchChannels(currentTeamId, matchTerm); + this.props.actions.autocompleteChannelsForSearch(currentTeamId, matchTerm); }, 200); componentWillReceiveProps(nextProps) { @@ -97,13 +91,12 @@ export default class ChannelMention extends PureComponent { myMembers !== this.props.myMembers)) { const sections = []; if (isSearch) { - if (publicChannels.length) { + if (directAndGroupMessages.length) { sections.push({ - id: t('suggestion.search.public'), - defaultMessage: 'Public Channels', - data: publicChannels.filter((cId) => myMembers[cId]), - key: 'publicChannels', - hideLoadingIndicator: true, + id: t('suggestion.search.direct'), + defaultMessage: 'Direct Messages', + data: directAndGroupMessages, + key: 'directAndGroupMessages', }); } @@ -117,12 +110,13 @@ export default class ChannelMention extends PureComponent { }); } - if (directAndGroupMessages.length && isMinimumServerVersion(this.props.serverVersion, 5, 4)) { + if (publicChannels.length) { sections.push({ - id: t('suggestion.search.direct'), - defaultMessage: 'Direct Messages', - data: directAndGroupMessages, - key: 'directAndGroupMessages', + id: t('suggestion.search.public'), + defaultMessage: 'Public Channels', + data: publicChannels.filter((cId) => myMembers[cId]), + key: 'publicChannels', + hideLoadingIndicator: true, }); } } else { diff --git a/app/components/autocomplete/channel_mention/index.js b/app/components/autocomplete/channel_mention/index.js index 5c5087020..614a84935 100644 --- a/app/components/autocomplete/channel_mention/index.js +++ b/app/components/autocomplete/channel_mention/index.js @@ -52,7 +52,6 @@ function mapStateToProps(state, ownProps) { matchTerm, requestStatus: state.requests.channels.getChannels.status, theme: getTheme(state), - serverVersion: state.entities.general.serverVersion, isLandscape: isLandscape(state), }; } diff --git a/app/selectors/autocomplete.js b/app/selectors/autocomplete.js index 900b2e4f0..c9d07e2be 100644 --- a/app/selectors/autocomplete.js +++ b/app/selectors/autocomplete.js @@ -258,14 +258,18 @@ export const filterDirectAndGroupMessages = createSelector( if (matchTerm === null) { return null; } + let mt = matchTerm; + if (matchTerm.startsWith('@')) { + mt = matchTerm.substr(1); + } let channels; - if (matchTerm) { + if (mt) { channels = myChannels.filter((c) => { - if (c.type === General.DM_CHANNEL && (originalChannels[c.id].display_name.toLowerCase().startsWith(matchTerm))) { + if (c.type === General.DM_CHANNEL && (originalChannels[c.id].display_name.toLowerCase().startsWith(mt))) { return true; } - if (c.type === General.GM_CHANNEL && (c.name.toLowerCase().startsWith(matchTerm) || c.display_name.toLowerCase().replace(/ /g, '').startsWith(matchTerm))) { + if (c.type === General.GM_CHANNEL && (c.name.toLowerCase().startsWith(mt) || c.display_name.toLowerCase().replace(/ /g, '').startsWith(mt))) { return true; } return false; diff --git a/app/selectors/autocomplete.test.js b/app/selectors/autocomplete.test.js index 532ed42e9..84222998c 100644 --- a/app/selectors/autocomplete.test.js +++ b/app/selectors/autocomplete.test.js @@ -7,8 +7,11 @@ import { getMatchTermForAtMention, filterMembersNotInChannel, filterMembersInChannel, + filterDirectAndGroupMessages, } from 'app/selectors/autocomplete'; +import {General} from '@mm-redux/constants'; + /* eslint-disable max-nested-callbacks */ describe('Selectors.Autocomplete', () => { @@ -134,4 +137,73 @@ describe('Selectors.Autocomplete', () => { profiles = filterMembersInChannel(state, 'example'); expect(profiles.length).toBe(2); }); + + it('Should return DMs', () => { + const dm1 = { + id: 'dm-1-id', + type: General.DM_CHANNEL, + name: 'another1', + display_name: 'another1', + }; + const dm2 = { + id: 'dm-2-id', + type: General.DM_CHANNEL, + name: 'another2', + display_name: 'another2', + }; + const gm1 = { + id: 'gm-1-id', + type: General.GM_CHANNEL, + name: 'anothergroup1', + display_name: 'anothergroup1', + }; + const teamId = 'current-team-id'; + const state = { + entities: { + general: { + config: {}, + }, + preferences: { + myPreferences: {}, + }, + channels: { + channels: { + [dm1.id]: dm1, + [dm2.id]: dm2, + [gm1.id]: gm1, + }, + myMembers: { + [dm1.id]: {}, + [dm2.id]: {}, + [gm1.id]: {}, + }, + channelsInTeam: { + [teamId]: new Set([dm1.id, dm2.id, gm1.id]), + }, + }, + teams: { + currentTeamId: teamId, + }, + users: { + currentUserId: 'current-user-id', + + profiles: { + 'current-user-id': {id: 'current-user-id', username: 'current', first_name: 'Current', last_name: 'User', email: 'current@user.com', nickname: 'nickname', delete_at: 0}, + }, + }, + }, + }; + + let profiles = filterDirectAndGroupMessages(state, '@another1'); + expect(profiles.length).toBe(1); + + profiles = filterDirectAndGroupMessages(state, 'another2'); + expect(profiles.length).toBe(1); + + profiles = filterDirectAndGroupMessages(state, '@anothergroup1'); + expect(profiles.length).toBe(1); + + profiles = filterDirectAndGroupMessages(state, '@another'); + expect(profiles.length).toBe(3); + }); });