[MM-15477][MM-27540][MM-27541]: fix search inconsistencies using in:@ / in: (#4704)

* [MM-15477] reorder search suggest results

* allow searching dms and gms with 'in:@'

* fix sort order for private before public

* faster than regex

* remove server minimum version prop and checks
This commit is contained in:
Ashish Bhate 2020-09-01 22:38:17 +05:30 committed by GitHub
parent 4bcb595e5b
commit 0210cc4761
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 22 deletions

View file

@ -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 {

View file

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

View file

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

View file

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