From ea99cedb62a308415d9558badaf638abda73dbc8 Mon Sep 17 00:00:00 2001 From: David Lu Date: Mon, 6 Jun 2016 10:54:23 -0700 Subject: PLT-3185 Added support for DMs in Channel Switcher (#3260) * Added support for DMs * Checked username beginning characters --- webapp/components/channel_switch_modal.jsx | 20 +++++++++++++++++--- .../suggestion/switch_channel_provider.jsx | 17 ++++++++++++++++- 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'webapp/components') diff --git a/webapp/components/channel_switch_modal.jsx b/webapp/components/channel_switch_modal.jsx index 5cf26c482..91e545fd7 100644 --- a/webapp/components/channel_switch_modal.jsx +++ b/webapp/components/channel_switch_modal.jsx @@ -4,12 +4,17 @@ import SuggestionList from './suggestion/suggestion_list.jsx'; import SuggestionBox from './suggestion/suggestion_box.jsx'; import SwitchChannelProvider from './suggestion/switch_channel_provider.jsx'; + import {FormattedMessage} from 'react-intl'; import {Modal} from 'react-bootstrap'; -import * as Utils from 'utils/utils.jsx'; + import ChannelStore from 'stores/channel_store.jsx'; +import UserStore from 'stores/user_store.jsx'; + import Constants from 'utils/constants.jsx'; +import * as Utils from 'utils/utils.jsx'; import * as ChannelActions from 'actions/channel_actions.jsx'; + import React from 'react'; export default class SwitchChannelModal extends React.Component { @@ -66,8 +71,17 @@ export default class SwitchChannelModal extends React.Component { } handleSubmit() { - const channel = ChannelStore.getByName(this.state.text.trim()); - if (channel !== null && channel.name === this.state.text.trim() && channel.type !== Constants.DM_CHANNEL) { + const name = this.state.text.trim(); + let channel = null; + + if (name.indexOf(Utils.localizeMessage('channel_switch_modal.dm', '(Direct Message)')) > 0) { + const dmUsername = name.substr(0, name.indexOf(Utils.localizeMessage('channel_switch_modal.dm', '(Direct Message)')) - 1); + channel = ChannelStore.getByName(Utils.getDirectChannelNameByUsername(dmUsername, UserStore.getCurrentUser().username).trim()); + } else { + channel = ChannelStore.getByName(this.state.text.trim()); + } + + if (channel !== null) { ChannelActions.goToChannel(channel); this.onHide(); } else if (this.state.text !== '') { diff --git a/webapp/components/suggestion/switch_channel_provider.jsx b/webapp/components/suggestion/switch_channel_provider.jsx index b52cd7fe9..c12918c51 100644 --- a/webapp/components/suggestion/switch_channel_provider.jsx +++ b/webapp/components/suggestion/switch_channel_provider.jsx @@ -6,6 +6,8 @@ import React from 'react'; import ChannelStore from 'stores/channel_store.jsx'; import SuggestionStore from 'stores/suggestion_store.jsx'; import Suggestion from './suggestion.jsx'; +import Constants from 'utils/constants.jsx'; +import * as Utils from 'utils/utils.jsx'; class SwitchChannelSuggestion extends Suggestion { render() { @@ -16,7 +18,12 @@ class SwitchChannelSuggestion extends Suggestion { className += ' suggestion--selected'; } - const displayName = item.display_name + ' (' + item.name + ')'; + let displayName = ''; + if (item.type === Constants.DM_CHANNEL) { + displayName = item.display_name + ' ' + Utils.localizeMessage('channel_switch_modal.dm', '(Direct Message)'); + } else { + displayName = item.display_name + ' (' + item.name + ')'; + } return (