summaryrefslogtreecommitdiffstats
path: root/webapp/client/client.jsx
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-04-04 20:17:15 +0100
committerChristopher Speller <crspeller@gmail.com>2017-04-04 15:17:15 -0400
commit1fa3f2351c98e4d1b9c198e357d90ac0d436dcaa (patch)
tree23ff5a64041ed6aa1dc6b7a1db85b85972b2ec66 /webapp/client/client.jsx
parent77a76487a8e15084c8b5e8e350eb8dc7a87455ea (diff)
downloadchat-1fa3f2351c98e4d1b9c198e357d90ac0d436dcaa.tar.gz
chat-1fa3f2351c98e4d1b9c198e357d90ac0d436dcaa.tar.bz2
chat-1fa3f2351c98e4d1b9c198e357d90ac0d436dcaa.zip
PLT-6023: Add Users to Team in WebApp. (#5956)
* PLT-6198: Use added to channel system message on default channels. Use a different sytem message when a user was added to a default channel by someone else than when they joined themselves. * PLT-6023: Add Users to Team in WebApp. * Fix string text. * Handle added_to_team websocket message. * Fix unread flag on new channel.
Diffstat (limited to 'webapp/client/client.jsx')
-rw-r--r--webapp/client/client.jsx69
1 files changed, 69 insertions, 0 deletions
diff --git a/webapp/client/client.jsx b/webapp/client/client.jsx
index 1f70300e8..c1a9d2f85 100644
--- a/webapp/client/client.jsx
+++ b/webapp/client/client.jsx
@@ -489,6 +489,15 @@ export default class Client {
// Team Routes Section
+ getTeam(teamId, success, error) {
+ request.
+ get(`${this.getTeamsRoute()}/${teamId}/me`).
+ set(this.defaultHeaders).
+ type('application/json').
+ accept('application/json').
+ end(this.handleResponse.bind(this, 'getTeam', success, error));
+ }
+
findTeamByName(teamName, success, error) {
request.
post(`${this.getTeamsRoute()}/find_team_by_name`).
@@ -681,6 +690,30 @@ export default class Client {
this.trackEvent('api', 'api_teams_invite_members');
}
+ addUsersToTeam(teamId, userIds, success, error) {
+ let nonEmptyTeamId = teamId;
+ if (nonEmptyTeamId === '') {
+ nonEmptyTeamId = this.getTeamId();
+ }
+
+ const teamMembers = userIds.map((userId) => {
+ return {
+ team_id: nonEmptyTeamId,
+ user_id: userId
+ };
+ });
+
+ request.
+ post(`${this.url}/api/v4/teams/${nonEmptyTeamId}/members/batch`).
+ set(this.defaultHeaders).
+ type('application/json').
+ accept('application/json').
+ send(teamMembers).
+ end(this.handleResponse.bind(this, 'addUsersToTeam', success, error));
+
+ this.trackEvent('api', 'api_teams_batch_add_members', {team_id: nonEmptyTeamId, count: teamMembers.length});
+ }
+
removeUserFromTeam(teamId, userId, success, error) {
let nonEmptyTeamId = teamId;
if (nonEmptyTeamId === '') {
@@ -1124,6 +1157,29 @@ export default class Client {
this.trackEvent('api', 'api_profiles_get_in_team', {team_id: teamId});
}
+ getProfilesNotInTeam(teamId, offset, limit, success, error) {
+ // Super hacky, but this option only exists in api v4
+ function wrappedSuccess(data, res) {
+ // Convert the profile list provided by api v4 to a map to match similar v3 calls
+ const profiles = {};
+
+ for (const profile of data) {
+ profiles[profile.id] = profile;
+ }
+
+ success(profiles, res);
+ }
+
+ request.
+ get(`${this.url}/api/v4/users?not_in_team=${this.getTeamId()}&page=${offset}&per_page=${limit}`).
+ set(this.defaultHeaders).
+ type('application/json').
+ accept('application/json').
+ end(this.handleResponse.bind(this, 'getProfilesNotInTeam', wrappedSuccess, error));
+
+ this.trackEvent('api', 'api_profiles_get_not_in_team', {team_id: teamId});
+ }
+
getProfilesInChannel(channelId, offset, limit, success, error) {
request.
get(`${this.getChannelNeededRoute(channelId)}/users/${offset}/${limit}`).
@@ -1191,6 +1247,19 @@ export default class Client {
end(this.handleResponse.bind(this, 'searchUsers', success, error));
}
+ searchUsersNotInTeam(term, teamId, options, success, error) {
+ // Note that this is calling an APIv4 Endpoint since no APIv3 equivalent exists.
+ request.
+ post(`${this.url}/api/v4/users/search`).
+ set(this.defaultHeaders).
+ type('application/json').
+ accept('application/json').
+ send({term, not_in_team_id: teamId, ...options}).
+ end(this.handleResponse.bind(this, 'searchUsersNotInTeam', success, error));
+
+ this.trackEvent('api', 'api_search_users_not_in_team', {team_id: teamId});
+ }
+
autocompleteUsersInChannel(term, channelId, success, error) {
request.
get(`${this.getChannelNeededRoute(channelId)}/users/autocomplete?term=${encodeURIComponent(term)}`).