MM-11725: Filter archived channels by membership on search autocomplete (#2066)

* MM-11725: Filter archived channels by membership on search autocomplete

* Fixing PR suggestions
This commit is contained in:
Jesús Espino 2018-09-07 11:51:36 +02:00 committed by Elias Nahum
parent c6ea5e6024
commit db898694a5
3 changed files with 27 additions and 3 deletions

View file

@ -24,11 +24,13 @@ export default class ChannelMention extends PureComponent {
listHeight: PropTypes.number,
matchTerm: PropTypes.string,
myChannels: PropTypes.array,
myMembers: PropTypes.object,
otherChannels: PropTypes.array,
onChangeText: PropTypes.func.isRequired,
onResultCountChange: PropTypes.func.isRequired,
privateChannels: PropTypes.array,
publicChannels: PropTypes.array,
deletedPublicChannels: PropTypes.instanceOf(Set),
requestStatus: PropTypes.string.isRequired,
theme: PropTypes.object.isRequired,
value: PropTypes.string,
@ -48,7 +50,7 @@ export default class ChannelMention extends PureComponent {
}
componentWillReceiveProps(nextProps) {
const {isSearch, matchTerm, myChannels, otherChannels, privateChannels, publicChannels, requestStatus} = nextProps;
const {isSearch, matchTerm, myChannels, otherChannels, privateChannels, publicChannels, requestStatus, myMembers, deletedPublicChannels} = nextProps;
if ((matchTerm !== this.props.matchTerm && matchTerm === null) || this.state.mentionComplete) {
// if the term changes but is null or the mention has been completed we render this component as null
@ -74,7 +76,8 @@ export default class ChannelMention extends PureComponent {
if (requestStatus !== RequestStatus.STARTED &&
(myChannels !== this.props.myChannels || otherChannels !== this.props.otherChannels ||
privateChannels !== this.props.privateChannels || publicChannels !== this.props.publicChannels)) {
privateChannels !== this.props.privateChannels || publicChannels !== this.props.publicChannels ||
myMembers !== this.props.myMembers || deletedPublicChannels !== this.props.deletedPublicChannels)) {
// if the request is complete and the term is not null we show the autocomplete
const sections = [];
if (isSearch) {
@ -82,7 +85,7 @@ export default class ChannelMention extends PureComponent {
sections.push({
id: 'suggestion.search.public',
defaultMessage: 'Public Channels',
data: publicChannels,
data: publicChannels.filter((cId) => !deletedPublicChannels.has(cId) || myMembers[cId]),
key: 'publicChannels',
});
}

View file

@ -5,6 +5,7 @@ import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {searchChannels} from 'mattermost-redux/actions/channels';
import {getMyChannelMemberships} from 'mattermost-redux/selectors/entities/channels';
import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams';
import {
@ -12,6 +13,7 @@ import {
filterOtherChannels,
filterPublicChannels,
filterPrivateChannels,
getDeletedPublicChannelsIds,
getMatchTermForChannelMention,
} from 'app/selectors/autocomplete';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
@ -38,8 +40,10 @@ function mapStateToProps(state, ownProps) {
return {
myChannels,
myMembers: getMyChannelMemberships(state),
otherChannels,
publicChannels,
deletedPublicChannels: getDeletedPublicChannelsIds(state),
privateChannels,
currentTeamId: getCurrentTeamId(state),
matchTerm,

View file

@ -242,3 +242,20 @@ export const makeGetMatchTermForDateMention = () => {
return lastMatchTerm;
};
};
export const getDeletedPublicChannelsIds = createSelector(
getMyChannels,
getOtherChannels,
(myChannels, otherChannels) => {
const channels = myChannels.filter((c) => {
return (c.type === General.OPEN_CHANNEL);
}).concat(otherChannels);
return new Set(channels.reduce((acc, c) => {
if (c.delete_at !== 0) {
acc.push(c.id);
}
return acc;
}, []));
}
);