Fix select default channel (#2800)

* Fix select default channel

* use utility with channels in team object

* feedback review

* update mattermost-redux
This commit is contained in:
Elias Nahum
2019-05-16 20:02:19 -04:00
committed by GitHub
parent 013579c69f
commit bbfd6e820f
4 changed files with 14 additions and 9 deletions

View File

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

4
package-lock.json generated
View File

@@ -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",

View File

@@ -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",

View File

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