From bbfd6e820fc545a03bdbcf207265372f85531ec8 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Thu, 16 May 2019 20:02:19 -0400 Subject: [PATCH] Fix select default channel (#2800) * Fix select default channel * use utility with channels in team object * feedback review * update mattermost-redux --- app/actions/views/channel.js | 11 +++++++---- package-lock.json | 4 ++-- package.json | 2 +- share_extension/android/actions/index.js | 6 ++++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/actions/views/channel.js b/app/actions/views/channel.js index 509f41f1e6..4522785881 100644 --- a/app/actions/views/channel.js +++ b/app/actions/views/channel.js @@ -30,7 +30,7 @@ import { getCurrentChannelId, getMyChannelMember, getRedirectChannelNameForTeam, - getChannelByName as getChannelByNameSelector, + getChannelsNameMapInTeam, } from 'mattermost-redux/selectors/entities/channels'; import {getCurrentTeamId, getTeamByName} from 'mattermost-redux/selectors/entities/teams'; @@ -42,6 +42,7 @@ import { getUserIdFromChannelName, isDirectChannel, isGroupChannel, + getChannelByName as getChannelByNameSelector, } from 'mattermost-redux/utils/channel_utils'; import EventEmitter from 'mattermost-redux/utils/event_emitter'; import {getLastCreateAt} from 'mattermost-redux/utils/post_utils'; @@ -340,15 +341,17 @@ export function selectDefaultChannel(teamId) { return (dispatch, getState) => { const state = getState(); - const channel = getChannelByNameSelector(state, getRedirectChannelNameForTeam(state, teamId)); + const channelsInTeam = getChannelsNameMapInTeam(state, teamId); + const channel = getChannelByNameSelector(channelsInTeam, getRedirectChannelNameForTeam(state, teamId)); + let channelId; if (channel) { channelId = channel.id; } else { // Handle case when the default channel cannot be found // so we need to get the first available channel of the team - const channelsInTeam = Object.values(state.entities.channels).filter((c) => c.team_id === teamId); - const firstChannel = channelsInTeam.length ? channelsInTeam[0].id : {id: ''}; + const channels = Object.values(channelsInTeam); + const firstChannel = channels.length ? channels[0].id : {id: ''}; channelId = firstChannel.id; } diff --git a/package-lock.json b/package-lock.json index 384c50276e..6811963f7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13205,8 +13205,8 @@ "integrity": "sha1-XdaUPJOFSCZwFtTjTwV1gwgMUUw=" }, "mattermost-redux": { - "version": "github:mattermost/mattermost-redux#429ac99932207fa21441d05482e36a0597c80515", - "from": "github:mattermost/mattermost-redux#429ac99932207fa21441d05482e36a0597c80515", + "version": "github:mattermost/mattermost-redux#99245b6feccdb61ff221394f923471250b9e3719", + "from": "github:mattermost/mattermost-redux#99245b6feccdb61ff221394f923471250b9e3719", "requires": { "deep-equal": "1.0.1", "eslint-plugin-header": "3.0.0", diff --git a/package.json b/package.json index 412b9c46e4..a580c57f65 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "intl": "1.2.5", "jail-monkey": "2.2.0", "jsc-android": "241213.1.0", - "mattermost-redux": "github:mattermost/mattermost-redux#429ac99932207fa21441d05482e36a0597c80515", + "mattermost-redux": "github:mattermost/mattermost-redux#99245b6feccdb61ff221394f923471250b9e3719", "mime-db": "1.40.0", "moment-timezone": "0.5.25", "prop-types": "15.7.2", diff --git a/share_extension/android/actions/index.js b/share_extension/android/actions/index.js index 6030752f8d..808f7aad5a 100644 --- a/share_extension/android/actions/index.js +++ b/share_extension/android/actions/index.js @@ -2,7 +2,8 @@ // See LICENSE.txt for license information. import {fetchMyChannelsAndMembers} from 'mattermost-redux/actions/channels'; -import {getRedirectChannelNameForTeam, getChannelByName} from 'mattermost-redux/selectors/entities/channels'; +import {getRedirectChannelNameForTeam, getChannelsNameMapInTeam} from 'mattermost-redux/selectors/entities/channels'; +import {getChannelByName} from 'mattermost-redux/utils/channel_utils'; import {loadProfilesAndTeamMembersForDMSidebar} from 'app/actions/views/channel'; import {ViewTypes} from 'app/constants'; @@ -13,7 +14,8 @@ export function getTeamChannels(teamId) { dispatch(loadProfilesAndTeamMembersForDMSidebar(teamId)); const state = getState(); - const redirectChannel = getChannelByName(state, getRedirectChannelNameForTeam(state, teamId)); + const channelsInTeam = getChannelsNameMapInTeam(state, teamId); + const redirectChannel = getChannelByName(channelsInTeam, getRedirectChannelNameForTeam(state, teamId)); return redirectChannel.id; };