summaryrefslogtreecommitdiffstats
path: root/webapp/actions
diff options
context:
space:
mode:
authorDavid Meza <dmeza@users.noreply.github.com>2017-08-03 07:59:42 -0500
committerJoram Wilander <jwawilander@gmail.com>2017-08-03 08:59:42 -0400
commitb54d1342990253d3fe4a00c64df27cdd1bb0719b (patch)
treedadf9452248080b1a976d37430409696091fe52b /webapp/actions
parent19804c4e40340cc4c0093197f71216719ffe4050 (diff)
downloadchat-b54d1342990253d3fe4a00c64df27cdd1bb0719b.tar.gz
chat-b54d1342990253d3fe4a00c64df27cdd1bb0719b.tar.bz2
chat-b54d1342990253d3fe4a00c64df27cdd1bb0719b.zip
PLT-6484 Add /leave command to leave a channel (#6402)
* PLT-6484 Add /leave command to leave a channel * Text changes requeted on review. * PLT-6484 Display the right error message when trying to /leave town-square * PLT-6484 Be able to execute /leave command in direct and group message channels with the same effect as clicking x * PLT-6484 Refactor to create new leave_private_channel_modal.jsx * PLT-6484 Remove previous leave private channel logic to use new leave_private_channel_modal.jsx * Remove dot in command description. Change localized error when leaving Town square. * disable /leave command in reply threads on the right-hand sidebar, since it is not obvious which channel you should leave
Diffstat (limited to 'webapp/actions')
-rw-r--r--webapp/actions/channel_actions.jsx33
-rw-r--r--webapp/actions/global_actions.jsx11
2 files changed, 43 insertions, 1 deletions
diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx
index 39dc37591..78df1ff17 100644
--- a/webapp/actions/channel_actions.jsx
+++ b/webapp/actions/channel_actions.jsx
@@ -72,6 +72,39 @@ export function executeCommand(message, args, success, error) {
msg = '/shortcuts';
}
break;
+ case '/leave': {
+ // /leave command not supported in reply threads.
+ if (args.channel_id && (args.root_id || args.parent_id)) {
+ GlobalActions.sendEphemeralPost('/leave is not supported in reply threads. Use it in the center channel instead.', args.channel_id, args.parent_id);
+ return;
+ }
+ const channel = ChannelStore.getCurrent();
+ if (channel.type === Constants.PRIVATE_CHANNEL) {
+ GlobalActions.showLeavePrivateChannelModal(channel);
+ return;
+ } else if (
+ channel.type === Constants.DM_CHANNEL ||
+ channel.type === Constants.GM_CHANNEL
+ ) {
+ let name;
+ let category;
+ if (channel.type === Constants.DM_CHANNEL) {
+ name = Utils.getUserIdFromChannelName(channel);
+ category = Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW;
+ } else {
+ name = channel.id;
+ category = Constants.Preferences.CATEGORY_GROUP_CHANNEL_SHOW;
+ }
+ const currentUserId = UserStore.getCurrentId();
+ savePreferences(currentUserId, [{category, name, user_id: currentUserId, value: 'false'}])(dispatch, getState);
+ if (ChannelUtils.isFavoriteChannel(channel)) {
+ unmarkFavorite(channel.id);
+ }
+ browserHistory.push(`${TeamStore.getCurrentTeamRelativeUrl()}/channels/town-square`);
+ return;
+ }
+ break;
+ }
case '/settings':
GlobalActions.showAccountSettingsModal();
return;
diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx
index f464483cf..a163db126 100644
--- a/webapp/actions/global_actions.jsx
+++ b/webapp/actions/global_actions.jsx
@@ -281,6 +281,13 @@ export function showLeaveTeamModal() {
});
}
+export function showLeavePrivateChannelModal(channel) {
+ AppDispatcher.handleViewAction({
+ type: ActionTypes.TOGGLE_LEAVE_PRIVATE_CHANNEL_MODAL,
+ value: channel
+ });
+}
+
export function emitSuggestionPretextChanged(suggestionId, pretext) {
AppDispatcher.handleViewAction({
type: ActionTypes.SUGGESTION_PRETEXT_CHANGED,
@@ -351,7 +358,7 @@ export function emitPreferencesDeletedEvent(preferences) {
});
}
-export function sendEphemeralPost(message, channelId) {
+export function sendEphemeralPost(message, channelId, parentId) {
const timestamp = Utils.getTimestamp();
const post = {
id: Utils.generateId(),
@@ -361,6 +368,8 @@ export function sendEphemeralPost(message, channelId) {
type: Constants.PostTypes.EPHEMERAL,
create_at: timestamp,
update_at: timestamp,
+ root_id: parentId,
+ parent_id: parentId,
props: {}
};