Commit 8abd02ad authored by Saturnino Abril's avatar Saturnino Abril

use available redux of selectChannel in selecting/setting channel ID

parent fcdbc8e1
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {createDirectChannel, getChannelAndMyMember, getChannelStats, getMyChannelMember, joinChannel, markChannelAsRead, viewChannel} from 'mattermost-redux/actions/channels';
import {
createDirectChannel,
getChannelAndMyMember,
getChannelStats,
getMyChannelMember,
joinChannel,
markChannelAsRead,
selectChannel,
viewChannel
} from 'mattermost-redux/actions/channels';
import {getPostThread} from 'mattermost-redux/actions/posts';
import {removeUserFromTeam} from 'mattermost-redux/actions/teams';
import {Client4} from 'mattermost-redux/client';
......@@ -492,21 +501,23 @@ export async function redirectUserToDefaultTeam() {
}
}
if (teams[teamId]) {
const team = teams[teamId];
if (team) {
const channelId = BrowserStore.getGlobalItem(teamId);
const channel = ChannelStore.getChannelById(channelId);
if (channel) {
redirect(teams[teamId].name, channel.name);
let channelName = Constants.DEFAULT_CHANNEL;
if (channel && channel.team_id === team.id) {
selectChannel(channel.id)(dispatch, getState);
channelName = channel.name;
} else if (channelId) {
const {data} = await getChannelAndMyMember(channelId)(dispatch, getState);
if (data) {
redirect(teams[teamId].name, data.channel.name);
} else {
redirect(teams[teamId].name, Constants.DEFAULT_CHANNEL);
selectChannel(channelId)(dispatch, getState);
channelName = data.channel.name;
}
} else {
redirect(teams[teamId].name, Constants.DEFAULT_CHANNEL);
}
redirect(team.name, channelName);
} else {
browserHistory.push('/select_team');
}
......
......@@ -110,7 +110,7 @@ export default class NeedsTeam extends React.Component {
updateCurrentTeam(props) {
// First check to make sure you're in the current team
// for the current url.
const {team: teamName, identifier} = props.match.params;
const teamName = props.match.params.team;
const team = TeamStore.getByName(teamName);
if (!team) {
......@@ -127,21 +127,6 @@ export default class NeedsTeam extends React.Component {
TeamStore.saveMyTeam(team);
BrowserStore.setGlobalItem('team', team.id);
TeamStore.emitChange();
let channel;
if (identifier) {
const channelName = identifier.toLowerCase();
channel = ChannelStore.getByName(channelName);
}
if (!channel) {
const defaultChannel = ChannelStore.getByName(Constants.DEFAULT_CHANNEL);
if (defaultChannel && defaultChannel.id) {
ChannelStore.setCurrentId(defaultChannel.id);
ChannelStore.emitChange();
}
}
GlobalActions.emitCloseRightHandSide();
this.props.actions.fetchMyChannelsAndMembers(team.id).then(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment