mattermost-mobile/app/components/autocomplete/channel_mention/index.js
Jesús Espino 9bd89930b7
MM-11567: Autocomplete search in: for DMs and GMs (#2133)
* MM-11567: Autocomplete search in: for DMs and GMs

* More robust behavior on older versions and a fix on autocompletion

* Moving get display_name for search to a selector
2018-09-27 18:38:07 +02:00

69 lines
2.3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {searchChannels, autocompleteChannelsForSearch} from 'mattermost-redux/actions/channels';
import {getMyChannelMemberships} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {
filterMyChannels,
filterOtherChannels,
filterPublicChannels,
filterPrivateChannels,
filterDirectAndGroupMessages,
getDeletedPublicChannelsIds,
getMatchTermForChannelMention,
} from 'app/selectors/autocomplete';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
import ChannelMention from './channel_mention';
function mapStateToProps(state, ownProps) {
const {cursorPosition, isSearch} = ownProps;
const value = ownProps.value.substring(0, cursorPosition);
const matchTerm = getMatchTermForChannelMention(value, isSearch);
let myChannels;
let otherChannels;
let publicChannels;
let privateChannels;
let directAndGroupMessages;
if (isSearch) {
publicChannels = filterPublicChannels(state, matchTerm);
privateChannels = filterPrivateChannels(state, matchTerm);
directAndGroupMessages = filterDirectAndGroupMessages(state, matchTerm);
} else {
myChannels = filterMyChannels(state, matchTerm);
otherChannels = filterOtherChannels(state, matchTerm);
}
return {
myChannels,
myMembers: getMyChannelMemberships(state),
otherChannels,
publicChannels,
deletedPublicChannels: getDeletedPublicChannelsIds(state),
privateChannels,
directAndGroupMessages,
currentTeamId: getCurrentTeamId(state),
matchTerm,
requestStatus: state.requests.channels.getChannels.status,
theme: getTheme(state),
serverVersion: state.entities.general.serverVersion,
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
searchChannels,
autocompleteChannelsForSearch,
}, dispatch),
};
}
export default connect(mapStateToProps, mapDispatchToProps)(ChannelMention);