summaryrefslogtreecommitdiffstats
path: root/webapp/actions/channel_actions.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/actions/channel_actions.jsx')
-rw-r--r--webapp/actions/channel_actions.jsx172
1 files changed, 171 insertions, 1 deletions
diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx
index 204e6f9f1..4b4e3e10c 100644
--- a/webapp/actions/channel_actions.jsx
+++ b/webapp/actions/channel_actions.jsx
@@ -6,6 +6,7 @@ import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import ChannelStore from 'stores/channel_store.jsx';
+import * as ChannelUtils from 'utils/channel_utils.jsx';
import PreferenceStore from 'stores/preference_store.jsx';
import {loadProfilesAndTeamMembersForDMSidebar} from 'actions/user_actions.jsx';
@@ -48,7 +49,14 @@ export function executeCommand(message, args, success, error) {
msg = '/shortcuts';
}
}
- Client.executeCommand(msg, args, success, error);
+ Client.executeCommand(msg, args, success,
+ (err) => {
+ AsyncClient.dispatchError(err, 'executeCommand');
+
+ if (error) {
+ error(err);
+ }
+ });
}
export function setChannelAsRead(channelIdParam) {
@@ -101,6 +109,9 @@ export function removeUserFromChannel(channelId, userId, success, error) {
}
UserStore.emitInChannelChange();
+ ChannelStore.removeMemberInChannel(channelId, userId);
+ ChannelStore.emitChange();
+
if (success) {
success(data);
}
@@ -115,6 +126,48 @@ export function removeUserFromChannel(channelId, userId, success, error) {
);
}
+export function makeUserChannelAdmin(channelId, userId, success, error) {
+ Client.updateChannelMemberRoles(
+ channelId,
+ userId,
+ 'channel_user channel_admin',
+ () => {
+ AsyncClient.getChannelMember(channelId, userId);
+ getChannelMembersForUserIds(channelId, [userId]);
+
+ if (success) {
+ success();
+ }
+ },
+ (err) => {
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}
+
+export function makeUserChannelMember(channelId, userId, success, error) {
+ Client.updateChannelMemberRoles(
+ channelId,
+ userId,
+ 'channel_user',
+ () => {
+ AsyncClient.getChannelMember(channelId, userId);
+ getChannelMembersForUserIds(channelId, [userId]);
+
+ if (success) {
+ success();
+ }
+ },
+ (err) => {
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}
+
export function openDirectChannelToUser(user, success, error) {
const channelName = Utils.getDirectChannelName(UserStore.getCurrentId(), user.id);
const channel = ChannelStore.getByName(channelName);
@@ -311,3 +364,120 @@ export function createChannel(channel, success, error) {
}
);
}
+
+export function updateChannelPurpose(channelId, purposeValue, success, error) {
+ Client.updateChannelPurpose(
+ channelId,
+ purposeValue,
+ () => {
+ AsyncClient.getChannel(channelId);
+
+ if (success) {
+ success();
+ }
+ },
+ (err) => {
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}
+
+export function updateChannelHeader(channelId, header, success, error) {
+ Client.updateChannelHeader(
+ channelId,
+ header,
+ (channelData) => {
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.RECEIVED_CHANNEL,
+ channel: channelData
+ });
+
+ if (success) {
+ success(channelData);
+ }
+ },
+ (err) => {
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}
+
+export function getChannelMembersForUserIds(channelId, userIds, success, error) {
+ Client.getChannelMembersByIds(
+ channelId,
+ userIds,
+ (data) => {
+ const memberMap = {};
+ for (let i = 0; i < data.length; i++) {
+ memberMap[data[i].user_id] = data[i];
+ }
+
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.RECEIVED_MEMBERS_IN_CHANNEL,
+ channel_id: channelId,
+ channel_members: memberMap
+ });
+
+ if (success) {
+ success(data);
+ }
+ },
+ (err) => {
+ AsyncClient.dispatchError(err, 'getChannelMembersByIds');
+
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}
+
+export function leaveChannel(channelId, success, error) {
+ Client.leaveChannel(channelId,
+ () => {
+ loadChannelsForCurrentUser();
+
+ if (ChannelUtils.isFavoriteChannelId(channelId)) {
+ unmarkFavorite(channelId);
+ }
+
+ const townsquare = ChannelStore.getByName('town-square');
+ browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + townsquare.name);
+
+ if (success) {
+ success();
+ }
+ },
+ (err) => {
+ AsyncClient.dispatchError(err, 'handleLeave');
+
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}
+
+export function deleteChannel(channelId, success, error) {
+ Client.deleteChannel(
+ channelId,
+ () => {
+ loadChannelsForCurrentUser();
+
+ if (success) {
+ success();
+ }
+ },
+ (err) => {
+ AsyncClient.dispatchError(err, 'handleDelete');
+
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}