From 8097764d8786247ea78d19b7a4f5e541c0b823d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Fri, 23 Nov 2018 18:25:46 +0100 Subject: [PATCH] MM-12959: Fix autocomplete archived channels visibility (#2367) * MM-12959: Fix autocomplete archived channels visibility * Remove unneeded getDeletedPublicChannels --- .../channel_mention/channel_mention.js | 5 ++- .../autocomplete/channel_mention/index.js | 2 -- app/selectors/autocomplete.js | 34 ++++++++----------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/app/components/autocomplete/channel_mention/channel_mention.js b/app/components/autocomplete/channel_mention/channel_mention.js index 36c628f6a..8d080ccc8 100644 --- a/app/components/autocomplete/channel_mention/channel_mention.js +++ b/app/components/autocomplete/channel_mention/channel_mention.js @@ -35,7 +35,6 @@ export default class ChannelMention extends PureComponent { privateChannels: PropTypes.array, publicChannels: PropTypes.array, directAndGroupMessages: PropTypes.array, - deletedPublicChannels: PropTypes.instanceOf(Set), requestStatus: PropTypes.string.isRequired, theme: PropTypes.object.isRequired, value: PropTypes.string, @@ -64,7 +63,7 @@ export default class ChannelMention extends PureComponent { }, 200); componentWillReceiveProps(nextProps) { - const {isSearch, matchTerm, myChannels, otherChannels, privateChannels, publicChannels, directAndGroupMessages, requestStatus, myMembers, deletedPublicChannels} = nextProps; + const {isSearch, matchTerm, myChannels, otherChannels, privateChannels, publicChannels, directAndGroupMessages, requestStatus, myMembers} = 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 @@ -89,7 +88,7 @@ export default class ChannelMention extends PureComponent { if (matchTerm === '' || (myChannels !== this.props.myChannels || otherChannels !== this.props.otherChannels || privateChannels !== this.props.privateChannels || publicChannels !== this.props.publicChannels || directAndGroupMessages !== this.props.directAndGroupMessages || - myMembers !== this.props.myMembers || deletedPublicChannels !== this.props.deletedPublicChannels)) { + myMembers !== this.props.myMembers)) { const sections = []; if (isSearch) { if (publicChannels.length) { diff --git a/app/components/autocomplete/channel_mention/index.js b/app/components/autocomplete/channel_mention/index.js index ab988decd..9c2898ae0 100644 --- a/app/components/autocomplete/channel_mention/index.js +++ b/app/components/autocomplete/channel_mention/index.js @@ -14,7 +14,6 @@ import { filterPublicChannels, filterPrivateChannels, filterDirectAndGroupMessages, - getDeletedPublicChannelsIds, getMatchTermForChannelMention, } from 'app/selectors/autocomplete'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; @@ -46,7 +45,6 @@ function mapStateToProps(state, ownProps) { myMembers: getMyChannelMemberships(state), otherChannels, publicChannels, - deletedPublicChannels: getDeletedPublicChannelsIds(state), privateChannels, directAndGroupMessages, currentTeamId: getCurrentTeamId(state), diff --git a/app/selectors/autocomplete.js b/app/selectors/autocomplete.js index e03c47689..54c1bd978 100644 --- a/app/selectors/autocomplete.js +++ b/app/selectors/autocomplete.js @@ -4,6 +4,7 @@ import {createSelector} from 'reselect'; import {General} from 'mattermost-redux/constants'; +import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getMyChannels, getOtherChannels} from 'mattermost-redux/selectors/entities/channels'; import { getCurrentUser, getCurrentUserId, getProfilesInCurrentChannel, @@ -184,7 +185,8 @@ export const filterPublicChannels = createSelector( getOtherChannels, getCurrentLocale, (state, matchTerm) => matchTerm, - (myChannels, otherChannels, locale, matchTerm) => { + getConfig, + (myChannels, otherChannels, locale, matchTerm, config) => { if (matchTerm === null) { return null; } @@ -203,6 +205,11 @@ export const filterPublicChannels = createSelector( }).concat(otherChannels); } + const viewArchivedChannels = config.ExperimentalViewArchivedChannels === 'true'; + if (!viewArchivedChannels) { + channels = channels.filter((c) => c.delete_at === 0); + } + return channels.sort(sortChannelsByDisplayName.bind(null, locale)).map((c) => c.id); } ); @@ -210,7 +217,8 @@ export const filterPublicChannels = createSelector( export const filterPrivateChannels = createSelector( getMyChannels, (state, matchTerm) => matchTerm, - (myChannels, matchTerm) => { + getConfig, + (myChannels, matchTerm, config) => { if (matchTerm === null) { return null; } @@ -227,6 +235,11 @@ export const filterPrivateChannels = createSelector( }); } + const viewArchivedChannels = config.ExperimentalViewArchivedChannels === 'true'; + if (!viewArchivedChannels) { + channels = channels.filter((c) => c.delete_at === 0); + } + return channels.map((c) => c.id); } ); @@ -278,20 +291,3 @@ 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; - }, [])); - } -);