diff options
Diffstat (limited to 'webapp/actions/channel_actions.jsx')
-rw-r--r-- | webapp/actions/channel_actions.jsx | 72 |
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); + } + } + ); +} |