summaryrefslogtreecommitdiffstats
path: root/webapp/actions/channel_actions.jsx
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-01-18 20:54:49 +0000
committerenahum <nahumhbl@gmail.com>2017-01-18 17:54:48 -0300
commite15ae2253a15c7951c31ce0a2f9eea188ba2b639 (patch)
tree5d832b2f33f3e0ba81142d09968473262c8695d4 /webapp/actions/channel_actions.jsx
parent2554ae4a253dfe0e66d79a2955fccdb7db041b4b (diff)
downloadchat-e15ae2253a15c7951c31ce0a2f9eea188ba2b639.tar.gz
chat-e15ae2253a15c7951c31ce0a2f9eea188ba2b639.tar.bz2
chat-e15ae2253a15c7951c31ce0a2f9eea188ba2b639.zip
PLT-5050 (WebApp): Change channel member roles. (#5076)
Admins can now Promote/Demote channel members in the Channel Manage Membersmodal.
Diffstat (limited to 'webapp/actions/channel_actions.jsx')
-rw-r--r--webapp/actions/channel_actions.jsx72
1 files changed, 72 insertions, 0 deletions
diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx
index 40e0cde30..3e41a2310 100644
--- a/webapp/actions/channel_actions.jsx
+++ b/webapp/actions/channel_actions.jsx
@@ -125,6 +125,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);
@@ -343,3 +385,33 @@ export function updateChannelHeader(channelId, header, success, error) {
}
);
}
+
+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);
+ }
+ }
+ );
+}