Merge pull request #2625 from mattermost/plt-2502

PLT-2502 Fxing some channel changing issues
Этот коммит содержится в:
Joram Wilander
2016-04-04 12:24:12 -04:00
родитель 2bb9332467 5f3111e880
Коммит 2bdab516b2
11 изменённых файлов: 90 добавлений и 45 удалений

Просмотреть файл

@@ -335,4 +335,3 @@ export function emitRemoteUserTypingEvent(channelId, userId, postParentId) {
postParentId postParentId
}); });
} }

Просмотреть файл

@@ -26,10 +26,10 @@ import * as Utils from 'utils/utils.jsx';
import * as TextFormatting from 'utils/text_formatting.jsx'; import * as TextFormatting from 'utils/text_formatting.jsx';
import * as AsyncClient from 'utils/async_client.jsx'; import * as AsyncClient from 'utils/async_client.jsx';
import * as Client from 'utils/client.jsx'; import * as Client from 'utils/client.jsx';
import * as GlobalActions from 'action_creators/global_actions.jsx';
import Constants from 'utils/constants.jsx'; import Constants from 'utils/constants.jsx';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import {browserHistory} from 'react-router';
const ActionTypes = Constants.ActionTypes; const ActionTypes = Constants.ActionTypes;
@@ -106,7 +106,7 @@ export default class ChannelHeader extends React.Component {
}); });
const townsquare = ChannelStore.getByName('town-square'); const townsquare = ChannelStore.getByName('town-square');
GlobalActions.emitChannelClickEvent(townsquare); browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + townsquare.name);
}, },
(err) => { (err) => {
AsyncClient.dispatchError(err, 'handleLeave'); AsyncClient.dispatchError(err, 'handleLeave');

Просмотреть файл

@@ -9,9 +9,9 @@ import * as AsyncClient from 'utils/async_client.jsx';
import ChannelStore from 'stores/channel_store.jsx'; import ChannelStore from 'stores/channel_store.jsx';
import LoadingScreen from './loading_screen.jsx'; import LoadingScreen from './loading_screen.jsx';
import NewChannelFlow from './new_channel_flow.jsx'; import NewChannelFlow from './new_channel_flow.jsx';
import * as GlobalActions from 'action_creators/global_actions.jsx';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import {browserHistory} from 'react-router';
import loadingGif from 'images/load.gif'; import loadingGif from 'images/load.gif';
@@ -65,7 +65,7 @@ export default class MoreChannels extends React.Component {
client.joinChannel(channel.id, client.joinChannel(channel.id,
() => { () => {
$(ReactDOM.findDOMNode(this.refs.modal)).modal('hide'); $(ReactDOM.findDOMNode(this.refs.modal)).modal('hide');
GlobalActions.emitChannelClickEvent(channel); browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name);
this.setState({joiningChannel: -1}); this.setState({joiningChannel: -1});
}, },
(err) => { (err) => {

Просмотреть файл

@@ -5,9 +5,9 @@ import {Modal} from 'react-bootstrap';
import FilteredUserList from './filtered_user_list.jsx'; import FilteredUserList from './filtered_user_list.jsx';
import UserStore from 'stores/user_store.jsx'; import UserStore from 'stores/user_store.jsx';
import * as Utils from 'utils/utils.jsx'; import * as Utils from 'utils/utils.jsx';
import * as GlobalActions from 'action_creators/global_actions.jsx';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import {browserHistory} from 'react-router';
import SpinnerButton from 'components/spinner_button.jsx'; import SpinnerButton from 'components/spinner_button.jsx';
import React from 'react'; import React from 'react';
@@ -69,7 +69,7 @@ export default class MoreDirectChannels extends React.Component {
Utils.openDirectChannelToUser( Utils.openDirectChannelToUser(
teammate, teammate,
(channel) => { (channel) => {
GlobalActions.emitChannelClickEvent(channel); browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name);
this.setState({loadingDMChannel: -1}); this.setState({loadingDMChannel: -1});
this.handleHide(); this.handleHide();
}, },

Просмотреть файл

@@ -4,25 +4,21 @@
import * as Utils from 'utils/utils.jsx'; import * as Utils from 'utils/utils.jsx';
import * as Client from 'utils/client.jsx'; import * as Client from 'utils/client.jsx';
import UserStore from 'stores/user_store.jsx'; import UserStore from 'stores/user_store.jsx';
import * as GlobalActions from 'action_creators/global_actions.jsx';
import NewChannelModal from './new_channel_modal.jsx'; import NewChannelModal from './new_channel_modal.jsx';
import ChangeURLModal from './change_url_modal.jsx'; import ChangeURLModal from './change_url_modal.jsx';
import {intlShape, injectIntl, defineMessages} from 'react-intl'; import {intlShape, injectIntl, defineMessages} from 'react-intl';
import {browserHistory} from 'react-router';
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import Constants from 'utils/constants.jsx';
const ActionTypes = Constants.ActionTypes;
const SHOW_NEW_CHANNEL = 1; const SHOW_NEW_CHANNEL = 1;
const SHOW_EDIT_URL = 2; const SHOW_EDIT_URL = 2;
const SHOW_EDIT_URL_THEN_COMPLETE = 3; const SHOW_EDIT_URL_THEN_COMPLETE = 3;
const messages = defineMessages({ const messages = defineMessages({
invalidName: {
id: 'channel_flow.invalidName',
defaultMessage: 'Invalid Channel Name'
},
alreadyExist: {
id: 'channel_flow.alreadyExist',
defaultMessage: 'A channel with that URL already exists'
},
channel: { channel: {
id: 'channel_flow.channel', id: 'channel_flow.channel',
defaultMessage: 'Channel' defaultMessage: 'Channel'
@@ -87,37 +83,51 @@ class NewChannelFlow extends React.Component {
} }
} }
doSubmit() { doSubmit() {
var channel = {}; if (!this.state.channelDisplayName) {
this.setState({serverError: Utils.localizeMessage('channel_flow.invalidName', 'Invalid Channel Name')});
const {formatMessage} = this.props.intl;
channel.display_name = this.state.channelDisplayName;
if (!channel.display_name) {
this.setState({serverError: formatMessage(messages.invalidName)});
return; return;
} }
channel.name = this.state.channelName; if (this.state.channelName < 2) {
if (channel.name.length < 2) {
this.setState({flowState: SHOW_EDIT_URL_THEN_COMPLETE}); this.setState({flowState: SHOW_EDIT_URL_THEN_COMPLETE});
return; return;
} }
const cu = UserStore.getCurrentUser(); const cu = UserStore.getCurrentUser();
channel.team_id = cu.team_id; const channel = {
channel.purpose = this.state.channelPurpose; team_id: cu.team_id,
channel.type = this.state.channelType; name: this.state.channelName,
display_name: this.state.channelDisplayName,
Client.createChannel(channel, purpose: this.state.channelPurpose,
type: this.state.channelType
};
Client.createChannel(
channel,
(data) => { (data) => {
this.props.onModalDismissed(); Client.getChannel(
GlobalActions.emitChannelClickEvent(data); data.id,
(data2, textStatus, xhr) => {
if (xhr.status === 304 || !data2) {
return;
}
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL,
channel: data2.channel,
member: data2.member
});
this.props.onModalDismissed();
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + data2.channel.name);
}
);
}, },
(err) => { (err) => {
if (err.id === 'model.channel.is_valid.2_or_more.app_error') { if (err.id === 'model.channel.is_valid.2_or_more.app_error') {
this.setState({flowState: SHOW_EDIT_URL_THEN_COMPLETE}); this.setState({flowState: SHOW_EDIT_URL_THEN_COMPLETE});
} }
if (err.id === 'store.sql_channel.update.exists.app_error') { if (err.id === 'store.sql_channel.update.exists.app_error') {
this.setState({serverError: formatMessage(messages.alreadyExist)}); this.setState({serverError: Utils.localizeMessage('channel_flow.alreadyExist', 'A channel with that URL already exists')});
return; return;
} }
this.setState({serverError: err.message}); this.setState({serverError: err.message});

Просмотреть файл

@@ -6,10 +6,10 @@ import $ from 'jquery';
import UserStore from 'stores/user_store.jsx'; import UserStore from 'stores/user_store.jsx';
import {Popover, Overlay} from 'react-bootstrap'; import {Popover, Overlay} from 'react-bootstrap';
import * as Utils from 'utils/utils.jsx'; import * as Utils from 'utils/utils.jsx';
import * as GlobalActions from 'action_creators/global_actions.jsx';
import Constants from 'utils/constants.jsx'; import Constants from 'utils/constants.jsx';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import {browserHistory} from 'react-router';
import React from 'react'; import React from 'react';
@@ -35,7 +35,7 @@ export default class PopoverListMembers extends React.Component {
Utils.openDirectChannelToUser( Utils.openDirectChannelToUser(
teammate, teammate,
(channel, channelAlreadyExisted) => { (channel, channelAlreadyExisted) => {
GlobalActions.emitChannelClickEvent(channel); browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name);
if (channelAlreadyExisted) { if (channelAlreadyExisted) {
this.closePopover(); this.closePopover();
} }

Просмотреть файл

@@ -6,9 +6,10 @@ import ReactDOM from 'react-dom';
import ChannelStore from 'stores/channel_store.jsx'; import ChannelStore from 'stores/channel_store.jsx';
import UserStore from 'stores/user_store.jsx'; import UserStore from 'stores/user_store.jsx';
import BrowserStore from 'stores/browser_store.jsx'; import BrowserStore from 'stores/browser_store.jsx';
import * as GlobalActions from 'action_creators/global_actions.jsx';
import * as Utils from 'utils/utils.jsx';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import {browserHistory} from 'react-router';
import React from 'react'; import React from 'react';
@@ -33,7 +34,11 @@ export default class RemovedFromChannelModal extends React.Component {
} }
var townSquare = ChannelStore.getByName('town-square'); var townSquare = ChannelStore.getByName('town-square');
setTimeout(() => GlobalActions.emitChannelClickEvent(townSquare), 1); setTimeout(
() => {
browserHistory.push(Utils.getTeamURLNoOriginFromAddressBar() + '/channels/' + townSquare.name);
},
1);
this.setState(newState); this.setState(newState);
} }

Просмотреть файл

@@ -4,7 +4,7 @@
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import * as Utils from 'utils/utils.jsx'; import * as Utils from 'utils/utils.jsx';
import * as Client from 'utils/client.jsx'; import * as Client from 'utils/client.jsx';
import * as GlobalActions from 'action_creators/global_actions.jsx'; import * as AsyncClient from 'utils/async_client.jsx';
import Constants from 'utils/constants.jsx'; import Constants from 'utils/constants.jsx';
import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'react-intl'; import {intlShape, injectIntl, defineMessages, FormattedMessage} from 'react-intl';
@@ -165,7 +165,7 @@ export default class RenameChannelModal extends React.Component {
Client.updateChannel( Client.updateChannel(
channel, channel,
() => { () => {
GlobalActions.emitChannelClickEvent(channel); AsyncClient.getChannel(channel.id);
this.handleHide(); this.handleHide();
}, },

Просмотреть файл

@@ -180,6 +180,12 @@ function doChannelChange(state) {
channel = JSON.parse(state.location.query.fakechannel); channel = JSON.parse(state.location.query.fakechannel);
} else { } else {
channel = ChannelStore.getByName(state.params.channel); channel = ChannelStore.getByName(state.params.channel);
if (!channel) {
channel = ChannelStore.getMoreByName(state.params.channel);
}
if (!channel) {
console.error('Unable to get channel to change to.'); //eslint-disable-line no-console
}
} }
GlobalActions.emitChannelClickEvent(channel); GlobalActions.emitChannelClickEvent(channel);
} }

Просмотреть файл

@@ -95,7 +95,12 @@ class ChannelStoreClass extends EventEmitter {
this.removeListener(LEAVE_EVENT, callback); this.removeListener(LEAVE_EVENT, callback);
} }
findFirstBy(field, value) { findFirstBy(field, value) {
var channels = this.getChannels(); return this.doFindFirst(field, value, this.getChannels());
}
findFirstMoreBy(field, value) {
return this.doFindFirst(field, value, this.getMoreChannels());
}
doFindFirst(field, value, channels) {
for (var i = 0; i < channels.length; i++) { for (var i = 0; i < channels.length; i++) {
if (channels[i][field] === value) { if (channels[i][field] === value) {
return channels[i]; return channels[i];
@@ -113,6 +118,9 @@ class ChannelStoreClass extends EventEmitter {
getByName(name) { getByName(name) {
return this.findFirstBy('name', name); return this.findFirstBy('name', name);
} }
getMoreByName(name) {
return this.findFirstMoreBy('name', name);
}
getAll() { getAll() {
return this.getChannels(); return this.getChannels();
} }

Просмотреть файл

@@ -3,7 +3,6 @@
import $ from 'jquery'; import $ from 'jquery';
import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import * as GlobalActions from 'action_creators/global_actions.jsx';
import ChannelStore from 'stores/channel_store.jsx'; import ChannelStore from 'stores/channel_store.jsx';
import UserStore from 'stores/user_store.jsx'; import UserStore from 'stores/user_store.jsx';
import LocalizationStore from 'stores/localization_store.jsx'; import LocalizationStore from 'stores/localization_store.jsx';
@@ -168,7 +167,7 @@ export function notifyMe(title, body, channel) {
notification.onclick = () => { notification.onclick = () => {
window.focus(); window.focus();
if (channel) { if (channel) {
GlobalActions.emitChannelClickEvent(channel); browserHistory.push(getTeamURLNoOriginFromAddressBar() + '/channels/' + channel.name);
} else { } else {
browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/town-square'); browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/town-square');
} }
@@ -1216,6 +1215,10 @@ export function getTeamURLFromAddressBar() {
return window.location.origin + '/' + window.location.pathname.split('/')[1]; return window.location.origin + '/' + window.location.pathname.split('/')[1];
} }
export function getTeamURLNoOriginFromAddressBar() {
return '/' + window.location.pathname.split('/')[1];
}
export function getShortenedTeamURL() { export function getShortenedTeamURL() {
const teamURL = getTeamURLFromAddressBar(); const teamURL = getTeamURLFromAddressBar();
if (teamURL.length > 35) { if (teamURL.length > 35) {
@@ -1261,10 +1264,24 @@ export function openDirectChannelToUser(user, successCb, errorCb) {
channel, channel,
user.id, user.id,
(data) => { (data) => {
AsyncClient.getChannel(data.id); Client.getChannel(
if ($.isFunction(successCb)) { data.id,
successCb(data, false); (data2, textStatus, xhr) => {
} if (xhr.status === 304 || !data2) {
return;
}
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL,
channel: data2.channel,
member: data2.member
});
if ($.isFunction(successCb)) {
successCb(data2.channel, false);
}
}
);
}, },
() => { () => {
browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/' + channelName); browserHistory.push(TeamStore.getCurrentTeamUrl() + '/channels/' + channelName);