From 23ccfc845ca2350075f6027e16c6206fc7b71716 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Mon, 26 Jun 2017 08:16:57 -0400 Subject: Move remaining actions over to use redux and v4 endpoints (#6720) --- webapp/actions/admin_actions.jsx | 51 +- webapp/actions/channel_actions.jsx | 121 +- webapp/actions/diagnostics_actions.jsx | 22 +- webapp/actions/emoji_actions.jsx | 53 +- webapp/actions/file_actions.jsx | 13 + webapp/actions/global_actions.jsx | 101 +- webapp/actions/integration_actions.jsx | 68 +- webapp/actions/post_actions.jsx | 86 +- webapp/actions/team_actions.jsx | 49 +- webapp/actions/user_actions.jsx | 43 +- webapp/actions/webrtc_actions.jsx | 10 +- webapp/actions/websocket_actions.jsx | 66 +- webapp/client/browser_web_client.jsx | 154 -- webapp/client/client.jsx | 2368 -------------------- webapp/client/web_client.jsx | 10 - .../admin_console/system_users/system_users.jsx | 2 +- .../system_users/system_users_list.jsx | 11 +- webapp/components/analytics/system_analytics.jsx | 10 +- .../analytics/team_analytics/team_analytics.jsx | 9 +- .../announcement_bar/announcement_bar.jsx | 4 +- webapp/components/channel_view.jsx | 6 +- webapp/components/emoji/components/add_emoji.jsx | 7 +- webapp/components/emoji/components/emoji_list.jsx | 15 +- webapp/components/get_public_link_modal.jsx | 4 +- webapp/components/login/login_controller.jsx | 13 +- webapp/components/password_reset_send_link.jsx | 4 +- webapp/components/post_view/post_list.jsx | 2 +- webapp/components/root.jsx | 4 +- webapp/components/sidebar.jsx | 14 +- webapp/components/signup/signup_controller.jsx | 13 +- .../components/suggestion/at_mention_provider.jsx | 4 +- webapp/components/suggestion/command_provider.jsx | 6 +- .../components/suggestion/search_user_provider.jsx | 4 +- .../suggestion/switch_channel_provider.jsx | 3 +- .../components/tutorial/tutorial_intro_screens.jsx | 6 +- webapp/components/tutorial/tutorial_tip.jsx | 6 +- webapp/components/user_profile.jsx | 4 +- .../user_settings/email_notification_setting.jsx | 5 +- .../user_settings/user_settings_advanced.jsx | 14 +- .../user_settings/user_settings_display.jsx | 7 +- .../user_settings_general.jsx | 4 +- .../webrtc/components/webrtc_notification.jsx | 4 +- webapp/components/webrtc/webrtc_controller.jsx | 8 +- webapp/components/youtube_video/youtube_video.jsx | 4 +- webapp/routes/route_team.jsx | 45 +- webapp/stores/analytics_store.jsx | 71 +- webapp/stores/emoji_store.jsx | 70 +- webapp/stores/user_store.jsx | 6 +- webapp/tests/client/client_admin.test.jsx | 291 --- webapp/tests/client/client_channel.test.jsx | 457 ---- webapp/tests/client/client_command.test.jsx | 142 -- webapp/tests/client/client_emoji.test.jsx | 102 - webapp/tests/client/client_file.test.jsx | 248 -- webapp/tests/client/client_general.test.jsx | 44 - webapp/tests/client/client_hooks.test.jsx | 173 -- webapp/tests/client/client_oauth.test.jsx | 50 - webapp/tests/client/client_post.test.jsx | 233 -- webapp/tests/client/client_preferences.test.jsx | 62 - webapp/tests/client/client_reaction.test.jsx | 79 - webapp/tests/client/client_team.test.jsx | 309 --- webapp/tests/client/client_user.test.jsx | 700 ------ webapp/tests/client/client_websocket.test.jsx | 46 - webapp/utils/async_client.jsx | 889 -------- webapp/utils/channel_intro_messages.jsx | 7 +- webapp/utils/post_utils.jsx | 4 +- webapp/utils/utils.jsx | 9 +- webapp/yarn.lock | 2 +- 67 files changed, 528 insertions(+), 6923 deletions(-) delete mode 100644 webapp/client/browser_web_client.jsx delete mode 100644 webapp/client/client.jsx delete mode 100644 webapp/client/web_client.jsx delete mode 100644 webapp/tests/client/client_admin.test.jsx delete mode 100644 webapp/tests/client/client_channel.test.jsx delete mode 100644 webapp/tests/client/client_command.test.jsx delete mode 100644 webapp/tests/client/client_emoji.test.jsx delete mode 100644 webapp/tests/client/client_file.test.jsx delete mode 100644 webapp/tests/client/client_general.test.jsx delete mode 100644 webapp/tests/client/client_hooks.test.jsx delete mode 100644 webapp/tests/client/client_oauth.test.jsx delete mode 100644 webapp/tests/client/client_post.test.jsx delete mode 100644 webapp/tests/client/client_preferences.test.jsx delete mode 100644 webapp/tests/client/client_reaction.test.jsx delete mode 100644 webapp/tests/client/client_team.test.jsx delete mode 100644 webapp/tests/client/client_user.test.jsx delete mode 100644 webapp/tests/client/client_websocket.test.jsx delete mode 100644 webapp/utils/async_client.jsx (limited to 'webapp') diff --git a/webapp/actions/admin_actions.jsx b/webapp/actions/admin_actions.jsx index b9580c746..fdaeb8732 100644 --- a/webapp/actions/admin_actions.jsx +++ b/webapp/actions/admin_actions.jsx @@ -3,8 +3,6 @@ import {clientLogout} from 'actions/global_actions.jsx'; -import Client from 'client/web_client.jsx'; - import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; @@ -267,31 +265,26 @@ export function uploadBrandImage(brandImage, success, error) { } export function uploadLicenseFile(file, success, error) { - Client.uploadLicenseFile( - file, - () => { - if (success) { - success(); - } - }, - (err) => { - if (error) { - error(err); + AdminActions.uploadLicense(file)(dispatch, getState).then( + (data) => { + if (data && success) { + success(data); + } else if (data == null && error) { + const serverError = getState().requests.admin.uploadLicense.error; + error({id: serverError.server_error_id, ...serverError}); } } ); } export function removeLicenseFile(success, error) { - Client.removeLicenseFile( - () => { - if (success) { - success(); - } - }, - (err) => { - if (error) { - error(err); + AdminActions.removeLicense()(dispatch, getState).then( + (data) => { + if (data && success) { + success(data); + } else if (data == null && error) { + const serverError = getState().requests.admin.removeLicense.error; + error({id: serverError.server_error_id, ...serverError}); } } ); @@ -374,3 +367,19 @@ export function removeIdpSamlCertificate(success, error) { } ); } + +export function getStandardAnalytics(teamId) { + AdminActions.getStandardAnalytics(teamId)(dispatch, getState); +} + +export function getAdvancedAnalytics(teamId) { + AdminActions.getAdvancedAnalytics(teamId)(dispatch, getState); +} + +export function getPostsPerDayAnalytics(teamId) { + AdminActions.getPostsPerDayAnalytics(teamId)(dispatch, getState); +} + +export function getUsersPerDayAnalytics(teamId) { + AdminActions.getUsersPerDayAnalytics(teamId)(dispatch, getState); +} diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx index 3a01c4089..beee61c49 100644 --- a/webapp/actions/channel_actions.jsx +++ b/webapp/actions/channel_actions.jsx @@ -1,8 +1,6 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -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'; @@ -14,36 +12,19 @@ import * as GlobalActions from 'actions/global_actions.jsx'; import {loadProfilesForSidebar, loadNewDMIfNeeded, loadNewGMIfNeeded} from 'actions/user_actions.jsx'; import {trackEvent} from 'actions/diagnostics_actions.jsx'; -import Client from 'client/web_client.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; import * as UserAgent from 'utils/user_agent.jsx'; import * as Utils from 'utils/utils.jsx'; -import {Constants, Preferences, ActionTypes} from 'utils/constants.jsx'; +import {Constants, Preferences} from 'utils/constants.jsx'; import {browserHistory} from 'react-router/es6'; -// Redux actions import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; -import { - viewChannel, - addChannelMember, - removeChannelMember, - updateChannelMemberRoles, - createDirectChannel, - fetchMyChannelsAndMembers, - joinChannel as joinChannelRedux, - leaveChannel as leaveChannelRedux, - updateChannel as updateChannelRedux, - searchChannels, - updateChannelNotifyProps as updateChannelNotifyPropsRedux, - createChannel as createChannelRedux, - patchChannel, - getChannelMembersByIds, - deleteChannel as deleteChannelRedux -} from 'mattermost-redux/actions/channels'; +import * as ChannelActions from 'mattermost-redux/actions/channels'; +import {savePreferences, deletePreferences} from 'mattermost-redux/actions/preferences'; +import {Client4} from 'mattermost-redux/client'; import {getMyChannelMemberships} from 'mattermost-redux/selectors/entities/channels'; @@ -92,10 +73,8 @@ export function executeCommand(message, args, success, error) { return; } - Client.executeCommand(msg, args, success, + Client4.executeCommand(msg, args).then(success).catch( (err) => { - AsyncClient.dispatchError(err, 'executeCommand'); - if (error) { error(err); } @@ -105,7 +84,7 @@ export function executeCommand(message, args, success, error) { export function setChannelAsRead(channelIdParam) { const channelId = channelIdParam || ChannelStore.getCurrentId(); - viewChannel(channelId)(dispatch, getState); + ChannelActions.viewChannel(channelId)(dispatch, getState); ChannelStore.resetCounts([channelId]); ChannelStore.emitChange(); if (channelId === ChannelStore.getCurrentId()) { @@ -114,7 +93,7 @@ export function setChannelAsRead(channelIdParam) { } export function addUserToChannel(channelId, userId, success, error) { - addChannelMember(channelId, userId)(dispatch, getState).then( + ChannelActions.addChannelMember(channelId, userId)(dispatch, getState).then( (data) => { if (data && success) { success(data); @@ -127,7 +106,7 @@ export function addUserToChannel(channelId, userId, success, error) { } export function removeUserFromChannel(channelId, userId, success, error) { - removeChannelMember(channelId, userId)(dispatch, getState).then( + ChannelActions.removeChannelMember(channelId, userId)(dispatch, getState).then( (data) => { if (data && success) { success(data); @@ -140,7 +119,7 @@ export function removeUserFromChannel(channelId, userId, success, error) { } export function makeUserChannelAdmin(channelId, userId, success, error) { - updateChannelMemberRoles(channelId, userId, 'channel_user channel_admin')(dispatch, getState).then( + ChannelActions.updateChannelMemberRoles(channelId, userId, 'channel_user channel_admin')(dispatch, getState).then( (data) => { if (data && success) { success(data); @@ -153,7 +132,7 @@ export function makeUserChannelAdmin(channelId, userId, success, error) { } export function makeUserChannelMember(channelId, userId, success, error) { - updateChannelMemberRoles(channelId, userId, 'channel_user')(dispatch, getState).then( + ChannelActions.updateChannelMemberRoles(channelId, userId, 'channel_user')(dispatch, getState).then( (data) => { if (data && success) { success(data); @@ -174,11 +153,8 @@ export function openDirectChannelToUser(userId, success, error) { PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'true'); loadProfilesForSidebar(); - AsyncClient.savePreference( - Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, - userId, - 'true' - ); + const currentUserId = UserStore.getCurrentId(); + savePreferences(currentUserId, [{user_id: currentUserId, category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, name: userId, value: 'true'}])(dispatch, getState); if (success) { success(channel, true); @@ -187,7 +163,7 @@ export function openDirectChannelToUser(userId, success, error) { return; } - createDirectChannel(UserStore.getCurrentId(), userId)(dispatch, getState).then( + ChannelActions.createDirectChannel(UserStore.getCurrentId(), userId)(dispatch, getState).then( (data) => { loadProfilesForSidebar(); if (data && success) { @@ -202,37 +178,15 @@ export function openDirectChannelToUser(userId, success, error) { } export function openGroupChannelToUsers(userIds, success, error) { - Client.createGroupChannel( - userIds, + ChannelActions.createGroupChannel(userIds)(dispatch, getState).then( (data) => { - Client.getChannelMember( - data.id, - UserStore.getCurrentId(), - (data2) => { - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_CHANNEL, - channel: data, - member: data2 - }); - - PreferenceStore.setPreference(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, data.id, 'true'); - loadProfilesForSidebar(); - - AsyncClient.savePreference( - Preferences.CATEGORY_GROUP_CHANNEL_SHOW, - data.id, - 'true' - ); - - if (success) { - success(data); - } - } - ); - }, - () => { - if (error) { - error(); + loadProfilesForSidebar(); + if (data && success) { + success(data, false); + } else if (data == null && error) { + browserHistory.push(TeamStore.getCurrentTeamUrl()); + const serverError = getState().requests.channels.createChannel.error; + error({id: serverError.server_error_id, ...serverError}); } } ); @@ -240,22 +194,25 @@ export function openGroupChannelToUsers(userIds, success, error) { export function markFavorite(channelId) { trackEvent('api', 'api_channels_favorited'); - AsyncClient.savePreference(Preferences.CATEGORY_FAVORITE_CHANNEL, channelId, 'true'); + const currentUserId = UserStore.getCurrentId(); + savePreferences(currentUserId, [{user_id: currentUserId, category: Preferences.CATEGORY_FAVORITE_CHANNEL, name: channelId, value: 'true'}])(dispatch, getState); } export function unmarkFavorite(channelId) { trackEvent('api', 'api_channels_unfavorited'); + const currentUserId = UserStore.getCurrentId(); + const pref = { - user_id: UserStore.getCurrentId(), + user_id: currentUserId, category: Preferences.CATEGORY_FAVORITE_CHANNEL, name: channelId }; - AsyncClient.deletePreferences([pref]); + deletePreferences(currentUserId, [pref])(dispatch, getState); } export function loadChannelsForCurrentUser() { - fetchMyChannelsAndMembers(TeamStore.getCurrentId())(dispatch, getState).then( + ChannelActions.fetchMyChannelsAndMembers(TeamStore.getCurrentId())(dispatch, getState).then( () => { loadDMsAndGMsForUnreads(); } @@ -281,7 +238,7 @@ export function loadDMsAndGMsForUnreads() { } export function joinChannel(channel, success, error) { - joinChannelRedux(UserStore.getCurrentId(), null, channel.id)(dispatch, getState).then( + ChannelActions.joinChannel(UserStore.getCurrentId(), null, channel.id)(dispatch, getState).then( (data) => { if (data && success) { success(data); @@ -294,7 +251,7 @@ export function joinChannel(channel, success, error) { } export function updateChannel(channel, success, error) { - updateChannelRedux(channel)(dispatch, getState).then( + ChannelActions.updateChannel(channel)(dispatch, getState).then( (data) => { if (data && success) { success(data); @@ -307,7 +264,7 @@ export function updateChannel(channel, success, error) { } export function searchMoreChannels(term, success, error) { - searchChannels(TeamStore.getCurrentId(), term)(dispatch, getState).then( + ChannelActions.searchChannels(TeamStore.getCurrentId(), term)(dispatch, getState).then( (data) => { if (data && success) { const myMembers = getMyChannelMemberships(getState()); @@ -322,7 +279,7 @@ export function searchMoreChannels(term, success, error) { } export function autocompleteChannels(term, success, error) { - searchChannels(TeamStore.getCurrentId(), term)(dispatch, getState).then( + ChannelActions.searchChannels(TeamStore.getCurrentId(), term)(dispatch, getState).then( (data) => { if (data && success) { success(data); @@ -335,7 +292,7 @@ export function autocompleteChannels(term, success, error) { } export function updateChannelNotifyProps(data, options, success, error) { - updateChannelNotifyPropsRedux(data.user_id, data.channel_id, Object.assign({}, data, options))(dispatch, getState).then( + ChannelActions.updateChannelNotifyProps(data.user_id, data.channel_id, Object.assign({}, data, options))(dispatch, getState).then( (result) => { if (result && success) { success(result); @@ -348,7 +305,7 @@ export function updateChannelNotifyProps(data, options, success, error) { } export function createChannel(channel, success, error) { - createChannelRedux(channel)(dispatch, getState).then( + ChannelActions.createChannel(channel)(dispatch, getState).then( (data) => { if (data && success) { success(data); @@ -361,7 +318,7 @@ export function createChannel(channel, success, error) { } export function updateChannelPurpose(channelId, purpose, success, error) { - patchChannel(channelId, {purpose})(dispatch, getState).then( + ChannelActions.patchChannel(channelId, {purpose})(dispatch, getState).then( (data) => { if (data && success) { success(data); @@ -374,7 +331,7 @@ export function updateChannelPurpose(channelId, purpose, success, error) { } export function updateChannelHeader(channelId, header, success, error) { - patchChannel(channelId, {header})(dispatch, getState).then( + ChannelActions.patchChannel(channelId, {header})(dispatch, getState).then( (data) => { if (data && success) { success(data); @@ -387,7 +344,7 @@ export function updateChannelHeader(channelId, header, success, error) { } export function getChannelMembersForUserIds(channelId, userIds, success, error) { - getChannelMembersByIds(channelId, userIds)(dispatch, getState).then( + ChannelActions.getChannelMembersByIds(channelId, userIds)(dispatch, getState).then( (data) => { if (data && success) { success(data); @@ -400,7 +357,7 @@ export function getChannelMembersForUserIds(channelId, userIds, success, error) } export function leaveChannel(channelId, success) { - leaveChannelRedux(channelId)(dispatch, getState).then( + ChannelActions.leaveChannel(channelId)(dispatch, getState).then( () => { if (ChannelUtils.isFavoriteChannelId(channelId)) { unmarkFavorite(channelId); @@ -417,7 +374,7 @@ export function leaveChannel(channelId, success) { } export function deleteChannel(channelId, success, error) { - deleteChannelRedux(channelId)(dispatch, getState).then( + ChannelActions.deleteChannel(channelId)(dispatch, getState).then( (data) => { if (data && success) { success(data); diff --git a/webapp/actions/diagnostics_actions.jsx b/webapp/actions/diagnostics_actions.jsx index 4ffdfa552..72cf387b4 100644 --- a/webapp/actions/diagnostics_actions.jsx +++ b/webapp/actions/diagnostics_actions.jsx @@ -1,8 +1,24 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import Client from 'client/web_client.jsx'; +import UserStore from 'stores/user_store.jsx'; -export function trackEvent(category, event, properties) { - Client.trackEvent(category, event, properties); +export function trackEvent(category, event, props) { + if (global.window && global.window.analytics) { + const properties = Object.assign({category, type: event, user_actual_id: UserStore.getCurrentId()}, props); + const options = { + context: { + ip: '0.0.0.0' + }, + page: { + path: '', + referrer: '', + search: '', + title: '', + url: '' + }, + anonymousId: '00000000000000000000000000' + }; + global.window.analytics.track('event', properties, options); + } } diff --git a/webapp/actions/emoji_actions.jsx b/webapp/actions/emoji_actions.jsx index e5c9751c0..a6323449e 100644 --- a/webapp/actions/emoji_actions.jsx +++ b/webapp/actions/emoji_actions.jsx @@ -3,20 +3,21 @@ import UserStore from 'stores/user_store.jsx'; +import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; +import {ActionTypes} from 'utils/constants.jsx'; + import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; import {getProfilesByIds} from 'mattermost-redux/actions/users'; -import {getAllCustomEmojis} from 'mattermost-redux/actions/emojis'; +import * as EmojiActions from 'mattermost-redux/actions/emojis'; -export function loadEmoji(getProfiles = true) { - getAllCustomEmojis(10000)(dispatch, getState).then( - (data) => { - if (getProfiles) { - loadProfilesForEmoji(data); - } - } - ); +export async function loadEmoji(getProfiles = true) { + const data = await EmojiActions.getAllCustomEmojis(10000)(dispatch, getState); + + if (data && getProfiles) { + loadProfilesForEmoji(data); + } } function loadProfilesForEmoji(emojiList) { @@ -35,3 +36,37 @@ function loadProfilesForEmoji(emojiList) { getProfilesByIds(list)(dispatch, getState); } + +export function addEmoji(emoji, image, success, error) { + EmojiActions.createCustomEmoji(emoji, image)(dispatch, getState).then( + (data) => { + if (data && success) { + success(data); + } else if (data == null && error) { + const serverError = getState().requests.emojis.createCustomEmoji.error; + error({id: serverError.server_error_id, ...serverError}); + } + } + ); +} + +export function deleteEmoji(emojiId, success, error) { + EmojiActions.deleteCustomEmoji(emojiId)(dispatch, getState).then( + (data) => { + if (data) { + // Needed to remove recently used emoji + AppDispatcher.handleServerAction({ + type: ActionTypes.REMOVED_CUSTOM_EMOJI, + id: emojiId + }); + + if (success) { + success(data); + } + } else if (data == null && error) { + const serverError = getState().requests.emojis.deleteCustomEmoji.error; + error({id: serverError.server_error_id, ...serverError}); + } + } + ); +} diff --git a/webapp/actions/file_actions.jsx b/webapp/actions/file_actions.jsx index 628144676..c34af94c4 100644 --- a/webapp/actions/file_actions.jsx +++ b/webapp/actions/file_actions.jsx @@ -5,6 +5,7 @@ import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; import {uploadFile as uploadFileRedux} from 'mattermost-redux/actions/files'; +import {Client4} from 'mattermost-redux/client'; export function uploadFile(file, name, channelId, clientId, success, error) { const fileFormData = new FormData(); @@ -23,3 +24,15 @@ export function uploadFile(file, name, channelId, clientId, success, error) { } ); } + +export async function getPublicLink(fileId, success) { + Client4.getFilePublicLink(fileId).then( + (data) => { + if (data && success) { + success(data.link); + } + } + ).catch( + () => {} //eslint-disable-line no-empty-function + ); +} diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx index d3fa80d31..ea08d6671 100644 --- a/webapp/actions/global_actions.jsx +++ b/webapp/actions/global_actions.jsx @@ -21,8 +21,6 @@ import Constants from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; import EventTypes from 'utils/event_types.jsx'; -import Client from 'client/web_client.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; import WebSocketClient from 'client/web_websocket_client.jsx'; import {sortTeamsByDisplayName} from 'utils/team_utils.jsx'; import * as Utils from 'utils/utils.jsx'; @@ -35,20 +33,24 @@ import {browserHistory} from 'react-router/es6'; import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; + +import {Client4} from 'mattermost-redux/client'; + import {removeUserFromTeam} from 'mattermost-redux/actions/teams'; -import {viewChannel, getChannelStats, getMyChannelMember, getChannelAndMyMember} from 'mattermost-redux/actions/channels'; +import {viewChannel, getChannelStats, getMyChannelMember, getChannelAndMyMember, createDirectChannel} from 'mattermost-redux/actions/channels'; import {getPostThread} from 'mattermost-redux/actions/posts'; export function emitChannelClickEvent(channel) { function userVisitedFakeChannel(chan, success, fail) { + const currentUserId = UserStore.getCurrentId(); const otherUserId = Utils.getUserIdFromChannelName(chan); - Client.createDirectChannel( - otherUserId, + createDirectChannel(currentUserId, otherUserId)(dispatch, getState).then( (data) => { - success(data); - }, - () => { - fail(); + if (data) { + success(data); + } else { + fail(); + } } ); } @@ -119,32 +121,29 @@ export function doFocusPost(channelId, postId, data) { export function emitPostFocusEvent(postId, onSuccess) { loadChannelsForCurrentUser(); - Client.getPermalinkTmp( - postId, + getPostThread(postId)(dispatch, getState).then( (data) => { - if (!data) { - return; - } - const channelId = data.posts[data.order[0]].channel_id; - doFocusPost(channelId, postId, data); + if (data) { + const channelId = data.posts[data.order[0]].channel_id; + doFocusPost(channelId, postId, data); - if (onSuccess) { - onSuccess(); - } - }, - () => { - let link = `${TeamStore.getCurrentTeamRelativeUrl()}/channels/`; - const channel = ChannelStore.getCurrent(); - if (channel) { - link += channel.name; + if (onSuccess) { + onSuccess(); + } } else { - link += 'town-square'; - } + let link = `${TeamStore.getCurrentTeamRelativeUrl()}/channels/`; + const channel = ChannelStore.getCurrent(); + if (channel) { + link += channel.name; + } else { + link += 'town-square'; + } - const message = encodeURIComponent(Utils.localizeMessage('permalink.error.access', 'Permalink belongs to a deleted message or to a channel to which you do not have access.')); - const title = encodeURIComponent(Utils.localizeMessage('permalink.error.title', 'Message Not Found')); + const message = encodeURIComponent(Utils.localizeMessage('permalink.error.access', 'Permalink belongs to a deleted message or to a channel to which you do not have access.')); + const title = encodeURIComponent(Utils.localizeMessage('permalink.error.title', 'Message Not Found')); - browserHistory.push('/error?message=' + message + '&title=' + title + '&link=' + encodeURIComponent(link)); + browserHistory.push('/error?message=' + message + '&title=' + title + '&link=' + encodeURIComponent(link)); + } } ); } @@ -353,8 +352,7 @@ export function newLocalizationSelected(locale) { } else { const localeInfo = I18n.getLanguageInfo(locale); - Client.getTranslations( - localeInfo.url, + Client4.getTranslations(localeInfo.url).then( (data, res) => { let translations = data; if (!data && res.text) { @@ -365,10 +363,9 @@ export function newLocalizationSelected(locale) { locale, translations }); - }, - (err) => { - AsyncClient.dispatchError(err, 'getTranslations'); } + ).catch( + () => {} //eslint-disable-line no-empty-function ); } } @@ -414,14 +411,15 @@ export function emitRemoteUserTypingEvent(channelId, userId, postParentId) { } export function emitUserLoggedOutEvent(redirectTo = '/', shouldSignalLogout = true) { - Client.logout( + Client4.logout().then( () => { if (shouldSignalLogout) { BrowserStore.signalLogout(); } clientLogout(redirectTo); - }, + } + ).catch( () => { browserHistory.push(redirectTo); } @@ -523,7 +521,6 @@ export function redirectUserToDefaultTeam() { if (channel) { redirect(teams[teamId].name, channel); } else if (channelId) { - Client.setTeamId(teamId); getChannelAndMyMember(channelId)(dispatch, getState).then( (data) => { if (data) { @@ -541,34 +538,6 @@ export function redirectUserToDefaultTeam() { } } -requestOpenGraphMetadata.openGraphMetadataOnGoingRequests = {}; // Format: {: true} -export function requestOpenGraphMetadata(url) { - if (global.mm_config.EnableLinkPreviews !== 'true') { - return; - } - - const onself = requestOpenGraphMetadata; - - if (!onself.openGraphMetadataOnGoingRequests[url]) { - onself.openGraphMetadataOnGoingRequests[url] = true; - - Client.getOpenGraphMetadata(url, - (data) => { - AppDispatcher.handleServerAction({ - type: ActionTypes.RECIVED_OPEN_GRAPH_METADATA, - url, - data - }); - delete onself.openGraphMetadataOnGoingRequests[url]; - }, - (err) => { - AsyncClient.dispatchError(err, 'getOpenGraphMetadata'); - delete onself.openGraphMetadataOnGoingRequests[url]; - } - ); - } -} - export function postListScrollChange() { AppDispatcher.handleViewAction({ type: EventTypes.POST_LIST_SCROLL_CHANGE diff --git a/webapp/actions/integration_actions.jsx b/webapp/actions/integration_actions.jsx index 39dbbb2a8..6afaa5789 100644 --- a/webapp/actions/integration_actions.jsx +++ b/webapp/actions/integration_actions.jsx @@ -4,13 +4,21 @@ import UserStore from 'stores/user_store.jsx'; import TeamStore from 'stores/team_store.jsx'; -// Redux actions +import * as UserAgent from 'utils/user_agent.jsx'; +import {ActionTypes} from 'utils/constants.jsx'; +import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; + import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; + +import {Client4} from 'mattermost-redux/client'; + import {getProfilesByIds} from 'mattermost-redux/actions/users'; import * as IntegrationActions from 'mattermost-redux/actions/integrations'; +import request from 'superagent'; + export function loadIncomingHooks(complete) { IntegrationActions.getIncomingHooks('', 0, 10000)(dispatch, getState).then( (data) => { @@ -201,3 +209,61 @@ export function deleteCommand(id) { export function regenCommandToken(id) { IntegrationActions.regenCommandToken(id)(dispatch, getState); } + +export function getSuggestedCommands(command, suggestionId, component) { + Client4.getCommandsList(TeamStore.getCurrentId()).then( + (data) => { + var matches = []; + data.forEach((cmd) => { + if (cmd.trigger !== 'shortcuts' || !UserAgent.isMobile()) { + if (('/' + cmd.trigger).indexOf(command) === 0) { + const s = '/' + cmd.trigger; + let hint = ''; + if (cmd.auto_complete_hint && cmd.auto_complete_hint.length !== 0) { + hint = cmd.auto_complete_hint; + } + matches.push({ + suggestion: s, + hint, + description: cmd.auto_complete_desc + }); + } + } + }); + + matches = matches.sort((a, b) => a.suggestion.localeCompare(b.suggestion)); + + // pull out the suggested commands from the returned data + const terms = matches.map((suggestion) => suggestion.suggestion); + + if (terms.length > 0) { + AppDispatcher.handleServerAction({ + type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS, + id: suggestionId, + matchedPretext: command, + terms, + items: matches, + component + }); + } + } + ).catch( + () => {} //eslint-disable-line no-empty-function + ); +} + +export function getYoutubeVideoInfo(googleKey, videoId, success, error) { + request.get('https://www.googleapis.com/youtube/v3/videos'). + query({part: 'snippet', id: videoId, key: googleKey}). + end((err, res) => { + if (err) { + return error(err); + } + + if (!res.body) { + console.error('Missing response body for getYoutubeVideoInfo'); // eslint-disable-line no-console + } + + return success(res.body); + }); +} diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx index be7234c13..b9d6934d8 100644 --- a/webapp/actions/post_actions.jsx +++ b/webapp/actions/post_actions.jsx @@ -6,34 +6,25 @@ import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import UserStore from 'stores/user_store.jsx'; import PostStore from 'stores/post_store.jsx'; +import TeamStore from 'stores/team_store.jsx'; import {loadNewDMIfNeeded, loadNewGMIfNeeded} from 'actions/user_actions.jsx'; -import {trackEvent} from 'actions/diagnostics_actions.jsx'; import {sendDesktopNotification} from 'actions/notification_actions.jsx'; -import Client from 'client/web_client.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; - import Constants from 'utils/constants.jsx'; const ActionTypes = Constants.ActionTypes; -const Preferences = Constants.Preferences; // Redux actions import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; + import {getProfilesByIds} from 'mattermost-redux/actions/users'; -import { - createPost as createPostRedux, - getPostThread, - editPost, - deletePost as deletePostRedux, - getPosts, - getPostsBefore, - addReaction as addReactionRedux, - removeReaction as removeReactionRedux -} from 'mattermost-redux/actions/posts'; +import * as PostActions from 'mattermost-redux/actions/posts'; import {getMyChannelMember} from 'mattermost-redux/actions/channels'; + +import {Client4} from 'mattermost-redux/client'; + import {PostTypes} from 'mattermost-redux/action_types'; import * as Selectors from 'mattermost-redux/selectors/entities/posts'; import {batchActions} from 'redux-batched-actions'; @@ -47,11 +38,6 @@ export function handleNewPost(post, msg) { if (ChannelStore.getMyMember(post.channel_id)) { completePostReceive(post, websocketMessageProps); } else { - // This API call requires any real team id in API v3, so set one if we don't already have one - if (!Client.teamId && msg && msg.data) { - Client.setTeamId(msg.data.team_id); - } - getMyChannelMember(post.channel_id)(dispatch, getState).then(() => completePostReceive(post, websocketMessageProps)); } @@ -66,7 +52,7 @@ export function handleNewPost(post, msg) { function completePostReceive(post, websocketMessageProps) { if (post.root_id && Selectors.getPost(getState(), post.root_id) == null) { - getPostThread(post.root_id)(dispatch, getState).then( + PostActions.getPostThread(post.root_id)(dispatch, getState).then( (data) => { // Need manual dispatch to remove pending post dispatch({ @@ -116,31 +102,16 @@ function completePostReceive(post, websocketMessageProps) { sendDesktopNotification(post, websocketMessageProps); } -export function pinPost(channelId, postId) { - AsyncClient.pinPost(channelId, postId); -} - -export function unpinPost(channelId, postId) { - AsyncClient.unpinPost(channelId, postId); -} - export function flagPost(postId) { - trackEvent('api', 'api_posts_flagged'); - AsyncClient.savePreference(Preferences.CATEGORY_FLAGGED_POST, postId, 'true'); + PostActions.flagPost(postId)(dispatch, getState); } -export function unflagPost(postId, success) { - trackEvent('api', 'api_posts_unflagged'); - const pref = { - user_id: UserStore.getCurrentId(), - category: Preferences.CATEGORY_FLAGGED_POST, - name: postId - }; - AsyncClient.deletePreferences([pref], success); +export function unflagPost(postId) { + PostActions.unflagPost(postId)(dispatch, getState); } export function getFlaggedPosts() { - Client.getFlaggedPosts(0, Constants.POST_CHUNK_SIZE, + Client4.getFlaggedPosts(UserStore.getCurrentId(), '', TeamStore.getCurrentId()).then( (data) => { AppDispatcher.handleServerAction({ type: ActionTypes.RECEIVED_SEARCH_TERM, @@ -157,15 +128,14 @@ export function getFlaggedPosts() { }); loadProfilesForPosts(data.posts); - }, - (err) => { - AsyncClient.dispatchError(err, 'getFlaggedPosts'); } + ).catch( + () => {} //eslint-disable-line no-empty-function ); } export function getPinnedPosts(channelId = ChannelStore.getCurrentId()) { - Client.getPinnedPosts(channelId, + Client4.getPinnedPosts(channelId).then( (data) => { AppDispatcher.handleServerAction({ type: ActionTypes.RECEIVED_SEARCH_TERM, @@ -182,10 +152,9 @@ export function getPinnedPosts(channelId = ChannelStore.getCurrentId()) { }); loadProfilesForPosts(data.posts); - }, - (err) => { - AsyncClient.dispatchError(err, 'getPinnedPosts'); } + ).catch( + () => {} //eslint-disable-line no-empty-function ); } @@ -211,15 +180,15 @@ export function loadProfilesForPosts(posts) { } export function addReaction(channelId, postId, emojiName) { - addReactionRedux(postId, emojiName)(dispatch, getState); + PostActions.addReaction(postId, emojiName)(dispatch, getState); } export function removeReaction(channelId, postId, emojiName) { - removeReactionRedux(postId, emojiName)(dispatch, getState); + PostActions.removeReaction(postId, emojiName)(dispatch, getState); } export function createPost(post, files, success) { - createPostRedux(post, files)(dispatch, getState).then(() => { + PostActions.createPost(post, files)(dispatch, getState).then(() => { if (post.root_id) { PostStore.storeCommentDraft(post.root_id, null); } else { @@ -233,7 +202,7 @@ export function createPost(post, files, success) { } export function updatePost(post, success) { - editPost(post)(dispatch, getState).then( + PostActions.editPost(post)(dispatch, getState).then( (data) => { if (data && success) { success(); @@ -257,7 +226,7 @@ export function deletePost(channelId, post, success) { hardDelete = true; } - deletePostRedux(post, hardDelete)(dispatch, getState).then( + PostActions.deletePost(post, hardDelete)(dispatch, getState).then( () => { if (post.id === getState().views.rhs.selectedPostId) { dispatch({ @@ -279,9 +248,7 @@ export function deletePost(channelId, post, success) { } export function performSearch(terms, isMentionSearch, success, error) { - Client.search( - terms, - isMentionSearch, + Client4.searchPosts(TeamStore.getCurrentId(), terms, isMentionSearch).then( (data) => { AppDispatcher.handleServerAction({ type: ActionTypes.RECEIVED_SEARCH, @@ -294,10 +261,9 @@ export function performSearch(terms, isMentionSearch, success, error) { if (success) { success(data); } - }, + } + ).catch( (err) => { - AsyncClient.dispatchError(err, 'search'); - if (error) { error(err); } @@ -337,9 +303,9 @@ export function increasePostVisibility(channelId, focusedPostId) { let posts; if (focusedPostId) { - posts = await getPostsBefore(channelId, focusedPostId, page, POST_INCREASE_AMOUNT)(dispatch, getState); + posts = await PostActions.getPostsBefore(channelId, focusedPostId, page, POST_INCREASE_AMOUNT)(dispatch, getState); } else { - posts = await getPosts(channelId, page, POST_INCREASE_AMOUNT)(doDispatch, doGetState); + posts = await PostActions.getPosts(channelId, page, POST_INCREASE_AMOUNT)(doDispatch, doGetState); } doDispatch({ diff --git a/webapp/actions/team_actions.jsx b/webapp/actions/team_actions.jsx index 6407e1b12..a0d208301 100644 --- a/webapp/actions/team_actions.jsx +++ b/webapp/actions/team_actions.jsx @@ -4,8 +4,6 @@ import TeamStore from 'stores/team_store.jsx'; import ChannelStore from 'stores/channel_store.jsx'; -import Client from 'client/web_client.jsx'; - import {browserHistory} from 'react-router/es6'; // Redux actions @@ -13,26 +11,17 @@ import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; +import {Client4} from 'mattermost-redux/client'; + import {getUser} from 'mattermost-redux/actions/users'; import {viewChannel} from 'mattermost-redux/actions/channels'; -import { - createTeam as createTeamRedux, - updateTeam as updateTeamRedux, - removeUserFromTeam as removeUserFromTeamRedux, - getTeamStats, - checkIfTeamExists as checkIfTeamExistsRedux, - updateTeamMemberRoles as updateTeamMemberRolesRedux, - addUsersToTeam as addUsersToTeamRedux, - sendEmailInvitesToTeam, - getTeamsForUser as getTeamsForUserRedux, - getTeamMembersForUser as getTeamMembersForUserRedux -} from 'mattermost-redux/actions/teams'; +import * as TeamActions from 'mattermost-redux/actions/teams'; import {TeamTypes} from 'mattermost-redux/action_types'; import {batchActions} from 'redux-batched-actions'; export function checkIfTeamExists(teamName, onSuccess, onError) { - checkIfTeamExistsRedux(teamName)(dispatch, getState).then( + TeamActions.checkIfTeamExists(teamName)(dispatch, getState).then( (exists) => { if (exists != null && onSuccess) { onSuccess(exists); @@ -45,7 +34,7 @@ export function checkIfTeamExists(teamName, onSuccess, onError) { } export function createTeam(team, onSuccess, onError) { - createTeamRedux(team)(dispatch, getState).then( + TeamActions.createTeam(team)(dispatch, getState).then( (rteam) => { if (rteam && onSuccess) { browserHistory.push('/' + rteam.name + '/channels/town-square'); @@ -59,7 +48,7 @@ export function createTeam(team, onSuccess, onError) { } export function updateTeam(team, onSuccess, onError) { - updateTeamRedux(team)(dispatch, getState).then( + TeamActions.updateTeam(team)(dispatch, getState).then( (rteam) => { if (rteam && onSuccess) { browserHistory.push('/' + rteam.name + '/channels/town-square'); @@ -73,10 +62,10 @@ export function updateTeam(team, onSuccess, onError) { } export function removeUserFromTeam(teamId, userId, success, error) { - removeUserFromTeamRedux(teamId, userId)(dispatch, getState).then( + TeamActions.removeUserFromTeam(teamId, userId)(dispatch, getState).then( (data) => { getUser(userId)(dispatch, getState); - getTeamStats(teamId)(dispatch, getState); + TeamActions.getTeamStats(teamId)(dispatch, getState); if (data && success) { success(); @@ -89,7 +78,7 @@ export function removeUserFromTeam(teamId, userId, success, error) { } export function updateTeamMemberRoles(teamId, userId, newRoles, success, error) { - updateTeamMemberRolesRedux(teamId, userId, newRoles)(dispatch, getState).then( + TeamActions.updateTeamMemberRoles(teamId, userId, newRoles)(dispatch, getState).then( (data) => { if (data && success) { success(); @@ -102,10 +91,7 @@ export function updateTeamMemberRoles(teamId, userId, newRoles, success, error) } export function addUserToTeamFromInvite(data, hash, inviteId, success, error) { - Client.addUserToTeamFromInvite( - data, - hash, - inviteId, + Client4.addToTeamFromInvite(hash, data, inviteId).then( (team) => { const member = { team_id: team.id, @@ -131,6 +117,7 @@ export function addUserToTeamFromInvite(data, hash, inviteId, success, error) { success(team); } }, + ).catch( (err) => { if (error) { error(err); @@ -140,7 +127,7 @@ export function addUserToTeamFromInvite(data, hash, inviteId, success, error) { } export function addUsersToTeam(teamId, userIds, success, error) { - addUsersToTeamRedux(teamId, userIds)(dispatch, getState).then( + TeamActions.addUsersToTeam(teamId, userIds)(dispatch, getState).then( (teamMembers) => { if (teamMembers && success) { success(teamMembers); @@ -153,13 +140,13 @@ export function addUsersToTeam(teamId, userIds, success, error) { } export function getInviteInfo(inviteId, success, error) { - Client.getInviteInfo( - inviteId, + Client4.getTeamInviteInfo(inviteId).then( (inviteData) => { if (success) { success(inviteData); } - }, + } + ).catch( (err) => { if (error) { error(err); @@ -176,7 +163,7 @@ export function inviteMembers(data, success, error) { data.invites.forEach((i) => { emails.push(i.email); }); - sendEmailInvitesToTeam(TeamStore.getCurrentId(), emails)(dispatch, getState).then( + TeamActions.sendEmailInvitesToTeam(TeamStore.getCurrentId(), emails)(dispatch, getState).then( (result) => { if (result && success) { success(); @@ -194,7 +181,7 @@ export function switchTeams(url) { } export function getTeamsForUser(userId, success, error) { - getTeamsForUserRedux(userId)(dispatch, getState).then( + TeamActions.getTeamsForUser(userId)(dispatch, getState).then( (result) => { if (result && success) { success(result); @@ -207,7 +194,7 @@ export function getTeamsForUser(userId, success, error) { } export function getTeamMembersForUser(userId, success, error) { - getTeamMembersForUserRedux(userId)(dispatch, getState).then( + TeamActions.getTeamMembersForUser(userId)(dispatch, getState).then( (result) => { if (result && success) { success(result); diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx index 8814d5286..b28bc71c0 100644 --- a/webapp/actions/user_actions.jsx +++ b/webapp/actions/user_actions.jsx @@ -15,7 +15,6 @@ import {getDirectChannelName, getUserIdFromChannelName} from 'utils/utils.jsx'; import {Constants, ActionTypes, Preferences} from 'utils/constants.jsx'; import {browserHistory} from 'react-router/es6'; -// Redux actions import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; @@ -29,7 +28,7 @@ import {Client4} from 'mattermost-redux/client'; import {getClientConfig, getLicenseConfig} from 'mattermost-redux/actions/general'; import {getTeamMembersByIds, getMyTeamMembers, getMyTeamUnreads} from 'mattermost-redux/actions/teams'; import {getChannelAndMyMember} from 'mattermost-redux/actions/channels'; -import {savePreferences, deletePreferences} from 'mattermost-redux/actions/preferences'; +import {savePreferences as savePreferencesRedux, deletePreferences} from 'mattermost-redux/actions/preferences'; import {Preferences as PreferencesRedux} from 'mattermost-redux/constants'; @@ -242,7 +241,7 @@ export function loadNewDMIfNeeded(channelId) { if (pref === false) { PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'true'); const currentUserId = UserStore.getCurrentId(); - savePreferences(currentUserId, [{user_id: currentUserId, category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, name: userId, value: 'true'}])(dispatch, getState); + savePreferencesRedux(currentUserId, [{user_id: currentUserId, category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, name: userId, value: 'true'}])(dispatch, getState); loadProfilesForDM(); } } @@ -267,7 +266,7 @@ export function loadNewGMIfNeeded(channelId) { if (pref === false) { PreferenceStore.setPreference(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, channelId, 'true'); const currentUserId = UserStore.getCurrentId(); - savePreferences(currentUserId, [{user_id: currentUserId, category: Preferences.CATEGORY_GROUP_CHANNEL_SHOW, name: channelId, value: 'true'}])(dispatch, getState); + savePreferencesRedux(currentUserId, [{user_id: currentUserId, category: Preferences.CATEGORY_GROUP_CHANNEL_SHOW, name: channelId, value: 'true'}])(dispatch, getState); loadProfilesForGM(); } } @@ -328,7 +327,7 @@ export function loadProfilesForGM() { if (newPreferences.length > 0) { const currentUserId = UserStore.getCurrentId(); - savePreferences(currentUserId, newPreferences)(dispatch, getState); + savePreferencesRedux(currentUserId, newPreferences)(dispatch, getState); } } @@ -369,7 +368,7 @@ export function loadProfilesForDM() { if (newPreferences.length > 0) { const currentUserId = UserStore.getCurrentId(); - savePreferences(currentUserId, newPreferences)(dispatch, getState); + savePreferencesRedux(currentUserId, newPreferences)(dispatch, getState); } if (profilesToLoad.length > 0) { @@ -794,6 +793,25 @@ export function loadMyTeamMembers() { ); } +export function savePreferences(prefs, success, error) { + const currentUserId = UserStore.getCurrentId(); + savePreferencesRedux(currentUserId, prefs)(dispatch, getState).then( + (data) => { + if (data && success) { + success(data); + } else if (data == null && error) { + const serverError = getState().requests.preferences.savePreferences.error; + error({id: serverError.server_error_id, ...serverError}); + } + } + ); +} + +export async function savePreference(category, name, value) { + const currentUserId = UserStore.getCurrentId(); + return savePreferencesRedux(currentUserId, [{user_id: currentUserId, category, name, value}])(dispatch, getState); +} + export function autoResetStatus() { return async (doDispatch, doGetState) => { const {currentUserId} = getState().entities.users; @@ -813,3 +831,16 @@ export function autoResetStatus() { return userStatus; }; } + +export function sendPasswordResetEmail(email, success, error) { + UserActions.sendPasswordResetEmail(email)(dispatch, getState).then( + (data) => { + if (data && success) { + success(data); + } else if (data == null && error) { + const serverError = getState().requests.users.passwordReset.error; + error({id: serverError.server_error_id, ...serverError}); + } + } + ); +} diff --git a/webapp/actions/webrtc_actions.jsx b/webapp/actions/webrtc_actions.jsx index 65820f35c..244de289b 100644 --- a/webapp/actions/webrtc_actions.jsx +++ b/webapp/actions/webrtc_actions.jsx @@ -4,7 +4,7 @@ import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import {WebrtcActionTypes} from 'utils/constants.jsx'; -import Client from 'client/web_client.jsx'; +import {Client4} from 'mattermost-redux/client'; export function initWebrtc(userId, isCalling) { AppDispatcher.handleServerAction({ @@ -22,15 +22,17 @@ export function handle(message) { } export function webrtcToken(success, error) { - Client.webrtcToken( + Client4.webrtcToken().then( (data) => { if (success) { success(data); } - }, + } + ).catch( () => { if (error) { error(); } - }); + } + ); } diff --git a/webapp/actions/websocket_actions.jsx b/webapp/actions/websocket_actions.jsx index bf9b05cb7..1cdd06599 100644 --- a/webapp/actions/websocket_actions.jsx +++ b/webapp/actions/websocket_actions.jsx @@ -11,13 +11,9 @@ import BrowserStore from 'stores/browser_store.jsx'; import ErrorStore from 'stores/error_store.jsx'; import NotificationStore from 'stores/notification_store.jsx'; //eslint-disable-line no-unused-vars -import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; -import Client from 'client/web_client.jsx'; import WebSocketClient from 'client/web_websocket_client.jsx'; import * as WebrtcActions from './webrtc_actions.jsx'; import * as Utils from 'utils/utils.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; -import {getSiteURL} from 'utils/url.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import {handleNewPost, loadProfilesForPosts} from 'actions/post_actions.jsx'; @@ -25,19 +21,22 @@ import {loadProfilesForSidebar} from 'actions/user_actions.jsx'; import {loadChannelsForCurrentUser} from 'actions/channel_actions.jsx'; import * as StatusActions from 'actions/status_actions.jsx'; -import {ActionTypes, Constants, Preferences, SocketEvents, UserStatuses} from 'utils/constants.jsx'; +import {Constants, Preferences, SocketEvents, UserStatuses} from 'utils/constants.jsx'; import {browserHistory} from 'react-router/es6'; -// Redux actions import store from 'stores/redux_store.jsx'; const dispatch = store.dispatch; const getState = store.getState; + import {batchActions} from 'redux-batched-actions'; +import {Client4} from 'mattermost-redux/client'; + +import * as TeamActions from 'mattermost-redux/actions/teams'; import {viewChannel, getChannelAndMyMember, getChannelStats} from 'mattermost-redux/actions/channels'; import {getPosts} from 'mattermost-redux/actions/posts'; import {setServerVersion} from 'mattermost-redux/actions/general'; -import {ChannelTypes, TeamTypes, UserTypes, PostTypes} from 'mattermost-redux/action_types'; +import {ChannelTypes, TeamTypes, UserTypes, PostTypes, EmojiTypes} from 'mattermost-redux/action_types'; const MAX_WEBSOCKET_FAILS = 7; @@ -47,7 +46,7 @@ export function initialize() { return; } - let connUrl = getSiteURL(); + let connUrl = Client4.getWebSocketUrl(); // replace the protocol with a websocket one if (connUrl.startsWith('https:')) { @@ -57,7 +56,7 @@ export function initialize() { } // append a port number if one isn't already specified - if (!(/:\d+$/).test(connUrl)) { + if (!(/:\d+/).test(connUrl)) { if (connUrl.startsWith('wss:')) { connUrl += ':' + global.window.mm_config.WebsocketSecurePort; } else { @@ -65,18 +64,10 @@ export function initialize() { } } - // append the websocket api path - connUrl += Client.getUsersRoute() + '/websocket'; - WebSocketClient.setEventCallback(handleEvent); WebSocketClient.setFirstConnectCallback(handleFirstConnect); WebSocketClient.setReconnectCallback(() => reconnect(false)); - WebSocketClient.setMissedEventCallback(() => { - if (global.window.mm_config.EnableDeveloper === 'true') { - Client.logClientError('missed websocket event seq=' + WebSocketClient.eventSequence); - } - reconnect(false); - }); + WebSocketClient.setMissedEventCallback(() => reconnect(false)); WebSocketClient.setCloseCallback(handleClose); WebSocketClient.initialize(connUrl); } @@ -95,11 +86,9 @@ export function reconnect(includeWebSocket = true) { reconnectWebSocket(); } - if (Client.teamId) { - loadChannelsForCurrentUser(); - getPosts(ChannelStore.getCurrentId())(dispatch, getState); - StatusActions.loadStatusesForChannelAndSidebar(); - } + loadChannelsForCurrentUser(); + getPosts(ChannelStore.getCurrentId())(dispatch, getState); + StatusActions.loadStatusesForChannelAndSidebar(); ErrorStore.clearLastError(); ErrorStore.emitChange(); @@ -269,25 +258,10 @@ function handlePostDeleteEvent(msg) { dispatch({type: PostTypes.POST_DELETED, data: post}); } -function handleTeamAddedEvent(msg) { - Client.getTeam(msg.data.team_id, (team) => { - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_TEAM, - team - }); - - Client.getMyTeamMembers((data) => { - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_MY_TEAM_MEMBERS, - team_members: data - }); - AsyncClient.getMyTeamsUnread(); - }, (err) => { - AsyncClient.dispatchError(err, 'getMyTeamMembers'); - }); - }, (err) => { - AsyncClient.dispatchError(err, 'getTeam'); - }); +async function handleTeamAddedEvent(msg) { + await TeamActions.getTeam(msg.data.team_id)(dispatch, getState); + await TeamActions.getMyTeamMembers()(dispatch, getState); + await TeamActions.getMyTeamUnreads()(dispatch, getState); } function handleLeaveTeamEvent(msg) { @@ -296,7 +270,6 @@ function handleLeaveTeamEvent(msg) { // if they are on the team being removed redirect them to default team if (TeamStore.getCurrentId() === msg.data.team_id) { - Client.setTeamId(''); BrowserStore.removeGlobalItem('team'); BrowserStore.removeGlobalItem(msg.data.team_id); @@ -424,7 +397,6 @@ function handleStatusChangedEvent(msg) { } function handleHelloEvent(msg) { - Client.serverVersion = msg.data.server_version; setServerVersion(msg.data.server_version)(dispatch, getState); } @@ -445,9 +417,9 @@ function handleReactionAddedEvent(msg) { function handleAddEmoji(msg) { const data = JSON.parse(msg.data.emoji); - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_CUSTOM_EMOJI, - emoji: data + dispatch({ + type: EmojiTypes.RECEIVED_CUSTOM_EMOJI, + data }); } diff --git a/webapp/client/browser_web_client.jsx b/webapp/client/browser_web_client.jsx deleted file mode 100644 index 4a7b95f63..000000000 --- a/webapp/client/browser_web_client.jsx +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import Client from './client.jsx'; - -import TeamStore from 'stores/team_store.jsx'; -import UserStore from 'stores/user_store.jsx'; -import BrowserStore from 'stores/browser_store.jsx'; - -import * as GlobalActions from 'actions/global_actions.jsx'; -import {reconnect} from 'actions/websocket_actions.jsx'; - -import request from 'superagent'; - -const HTTP_UNAUTHORIZED = 401; - -const mfaPaths = [ - '/mfa/setup', - '/mfa/confirm' -]; - -class WebClientClass extends Client { - constructor() { - super(); - this.enableLogErrorsToConsole(true); - this.hasInternetConnection = true; - TeamStore.addChangeListener(this.onTeamStoreChanged.bind(this)); - } - - onTeamStoreChanged() { - this.setTeamId(TeamStore.getCurrentId()); - } - trackEvent(category, event, props) { - if (global.window && global.window.analytics) { - const properties = Object.assign({category, type: event, user_actual_id: UserStore.getCurrentId()}, props); - const options = { - context: { - ip: '0.0.0.0' - }, - page: { - path: '', - referrer: '', - search: '', - title: '', - url: '' - }, - anonymousId: '00000000000000000000000000' - }; - global.window.analytics.track('event', properties, options); - } - } - - handleError(err, res) { - if (res && res.body && res.body.id === 'api.context.mfa_required.app_error') { - if (mfaPaths.indexOf(window.location.pathname) === -1) { - window.location.reload(); - } - return; - } - - if (err.status === HTTP_UNAUTHORIZED && res.req.url !== this.getUsersRoute() + '/login' && !res.req.url.startsWith(this.getUsersRoute() + '/claim')) { - GlobalActions.emitUserLoggedOutEvent('/login'); - } - - if (err.status == null) { - this.hasInternetConnection = false; - } - } - - handleSuccess = (res) => { // eslint-disable-line no-unused-vars - if (res && !this.hasInternetConnection) { - reconnect(); - this.hasInternetConnection = true; - } - } - - // not sure why but super.login doesn't work if using an () => arrow functions. - // I think this might be a webpack issue. - webLogin(loginId, password, token, success, error) { - this.login( - loginId, - password, - token, - (data) => { - this.trackEvent('api', 'api_users_login_success'); - BrowserStore.signalLogin(); - - if (success) { - success(data); - } - }, - (err) => { - this.trackEvent('api', 'api_users_login_fail'); - if (error) { - error(err); - } - } - ); - } - - webLoginByLdap(loginId, password, token, success, error) { - this.loginByLdap( - loginId, - password, - token, - (data) => { - this.trackEvent('api', 'api_users_login_success'); - this.trackEvent('api', 'api_users_login_ldap_success'); - BrowserStore.signalLogin(); - - if (success) { - success(data); - } - }, - (err) => { - this.trackEvent('api', 'api_users_login_fail'); - this.trackEvent('api', 'api_users_login_ldap_fail'); - if (error) { - error(err); - } - } - ); - } - - getYoutubeVideoInfo(googleKey, videoId, success, error) { - request.get('https://www.googleapis.com/youtube/v3/videos'). - query({part: 'snippet', id: videoId, key: googleKey}). - end((err, res) => { - if (err) { - return error(err); - } - - if (!res.body) { - console.error('Missing response body for getYoutubeVideoInfo'); // eslint-disable-line no-console - } - - return success(res.body); - }); - } - - uploadFileV4(file, filename, channelId, clientId, success, error) { - return request. - post(`${this.url}/api/v4/files`). - set(this.defaultHeaders). - attach('files', file, filename). - field('channel_id', channelId). - field('client_ids', clientId). - accept('application/json'). - end(this.handleResponse.bind(this, 'uploadFile', success, error)); - } -} - -var WebClient = new WebClientClass(); -export default WebClient; diff --git a/webapp/client/client.jsx b/webapp/client/client.jsx deleted file mode 100644 index 2b149e240..000000000 --- a/webapp/client/client.jsx +++ /dev/null @@ -1,2368 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import request from 'superagent'; - -const HEADER_X_VERSION_ID = 'x-version-id'; -const HEADER_X_CLUSTER_ID = 'x-cluster-id'; -const HEADER_TOKEN = 'token'; -const HEADER_BEARER = 'BEARER'; -const HEADER_AUTH = 'Authorization'; - -export default class Client { - constructor() { - this.teamId = ''; - this.serverVersion = ''; - this.clusterId = ''; - this.logToConsole = false; - this.useToken = false; - this.token = ''; - this.url = ''; - this.urlVersion = '/api/v3'; - this.defaultHeaders = { - 'X-Requested-With': 'XMLHttpRequest' - }; - - this.translations = { - connectionError: 'There appears to be a problem with your internet connection.', - unknownError: 'We received an unexpected status code from the server.' - }; - } - - setUrl(url) { - this.url = url; - } - - setAcceptLanguage(locale) { - this.defaultHeaders['Accept-Language'] = locale; - } - - setTeamId(id) { - this.teamId = id; - } - - getTeamId() { - if (!this.teamId) { - console.error('You are trying to use a route that requires a team_id, but you have not called setTeamId() in client.jsx'); // eslint-disable-line no-console - } - - return this.teamId; - } - - getServerVersion() { - return this.serverVersion; - } - - getBaseRoute() { - return `${this.url}${this.urlVersion}`; - } - - getAdminRoute() { - return `${this.url}${this.urlVersion}/admin`; - } - - getGeneralRoute() { - return `${this.url}${this.urlVersion}/general`; - } - - getLicenseRoute() { - return `${this.url}${this.urlVersion}/license`; - } - - getTeamsRoute() { - return `${this.url}${this.urlVersion}/teams`; - } - - getTeamNeededRoute(teamId = this.getTeamId()) { - return `${this.url}${this.urlVersion}/teams/${teamId}`; - } - - getChannelsRoute() { - return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/channels`; - } - - getChannelNameRoute(channelName) { - return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/channels/name/${channelName}`; - } - - getChannelNeededRoute(channelId) { - return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/channels/${channelId}`; - } - - getCommandsRoute() { - return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/commands`; - } - - getEmojiRoute() { - return `${this.url}${this.urlVersion}/emoji`; - } - - getHooksRoute() { - return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/hooks`; - } - - getPostsRoute(channelId) { - return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/channels/${channelId}/posts`; - } - - getUsersRoute() { - return `${this.url}${this.urlVersion}/users`; - } - - getTeamFilesRoute() { - return `${this.url}${this.urlVersion}/teams/${this.getTeamId()}/files`; - } - - getFileRoute(fileId) { - return `${this.url}${this.urlVersion}/files/${fileId}`; - } - - getOAuthRoute() { - return `${this.url}${this.urlVersion}/oauth`; - } - - getUserNeededRoute(userId) { - return `${this.url}${this.urlVersion}/users/${userId}`; - } - - getWebrtcRoute() { - return `${this.url}${this.urlVersion}/webrtc`; - } - - setTranslations(messages) { - this.translations = messages; - } - - enableLogErrorsToConsole(enabled) { - this.logToConsole = enabled; - } - - useHeaderToken() { - this.useToken = true; - if (this.token !== '') { - this.defaultHeaders[HEADER_AUTH] = `${HEADER_BEARER} ${this.token}`; - } - } - - trackEvent(category, event, properties) { // eslint-disable-line no-unused-vars - // NO-OP for inherited classes to override - } - - handleError(err, res) { // eslint-disable-line no-unused-vars - // NO-OP for inherited classes to override - } - - handleSuccess(res) { // eslint-disable-line no-unused-vars - // NO-OP for inherited classes to override - } - - handleResponse(methodName, successCallback, errorCallback, err, res) { - if (res && res.header) { - if (res.header[HEADER_X_VERSION_ID]) { - this.serverVersion = res.header[HEADER_X_VERSION_ID]; - } - - if (res.header[HEADER_X_CLUSTER_ID]) { - this.clusterId = res.header[HEADER_X_CLUSTER_ID]; - } - } - - if (err) { - // test to make sure it looks like a server JSON error response - var e = null; - if (res && res.body && res.body.id) { - e = res.body; - } - - var msg = ''; - - if (e) { - msg = 'method=' + methodName + ' msg=' + e.message + ' detail=' + e.detailed_error + ' rid=' + e.request_id; - } else { - msg = 'method=' + methodName + ' status=' + err.status + ' statusCode=' + err.statusCode + ' err=' + err; - - if (err.status === 0 || !err.status) { - e = {message: this.translations.connectionError}; - } else { - e = {message: this.translations.unknownError + ' (' + err.status + ')'}; - } - } - - if (this.logToConsole) { - console.error(msg); // eslint-disable-line no-console - console.error(e); // eslint-disable-line no-console - } - - this.handleError(err, res); - - if (errorCallback) { - errorCallback(e, err, res); - } - return; - } - - if (successCallback) { - if (res && res.body !== undefined) { // eslint-disable-line no-undefined - successCallback(res.body, res); - } else { - console.error('Missing response body for ' + methodName); // eslint-disable-line no-console - successCallback('', res); - } - this.handleSuccess(res); - } - } - - // General Routes Section - - getClientConfig(success, error) { - return request. - get(`${this.getGeneralRoute()}/client_props`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getClientConfig', success, error)); - } - - getPing(success, error) { - return request. - get(`${this.getGeneralRoute()}/ping`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getPing', success, error)); - } - - logClientError(msg) { - var l = {}; - l.level = 'ERROR'; - l.message = msg; - - request. - post(`${this.getGeneralRoute()}/log_client`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(l). - end(this.handleResponse.bind(this, 'logClientError', null, null)); - } - - // Admin / Licensing Routes Section - - reloadConfig(success, error) { - return request. - get(`${this.getAdminRoute()}/reload_config`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'reloadConfig', success, error)); - } - - invalidateAllCaches(success, error) { - return request. - get(`${this.getAdminRoute()}/invalidate_all_caches`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'invalidate_all_caches', success, error)); - } - - recycleDatabaseConnection(success, error) { - return request. - get(`${this.getAdminRoute()}/recycle_db_conn`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'recycleDatabaseConnection', success, error)); - } - - getTranslations(url, success, error) { - return request. - get(url). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getTranslations', success, error)); - } - - getComplianceReports(success, error) { - return request. - get(`${this.getAdminRoute()}/compliance_reports`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getComplianceReports', success, error)); - } - - uploadBrandImage(image, success, error) { - request. - post(`${this.getAdminRoute()}/upload_brand_image`). - set(this.defaultHeaders). - accept('application/json'). - attach('image', image, image.name). - end(this.handleResponse.bind(this, 'uploadBrandImage', success, error)); - } - - saveComplianceReports(job, success, error) { - return request. - post(`${this.getAdminRoute()}/save_compliance_report`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(job). - end(this.handleResponse.bind(this, 'saveComplianceReports', success, error)); - } - - getLogs(success, error) { - return request. - get(`${this.getAdminRoute()}/logs`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getLogs', success, error)); - } - - getClusterStatus(success, error) { - return request. - get(`${this.getAdminRoute()}/cluster_status`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getClusterStatus', success, error)); - } - - getServerAudits(success, error) { - return request. - get(`${this.getAdminRoute()}/audits`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getServerAudits', success, error)); - } - - getConfig(success, error) { - return request. - get(`${this.getAdminRoute()}/config`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getConfig', success, error)); - } - - getAnalytics(name, teamId, success, error) { - let url = `${this.getAdminRoute()}/analytics/`; - if (teamId == null) { - url += name; - } else { - url += teamId + '/' + name; - } - - return request. - get(url). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getAnalytics', success, error)); - } - - getTeamAnalytics(teamId, name, success, error) { - return request. - get(`${this.getAdminRoute()}/analytics/${teamId}/${name}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getTeamAnalytics', success, error)); - } - - saveConfig(config, success, error) { - request. - post(`${this.getAdminRoute()}/save_config`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(config). - end(this.handleResponse.bind(this, 'saveConfig', success, error)); - } - - testEmail(config, success, error) { - request. - post(`${this.getAdminRoute()}/test_email`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(config). - end(this.handleResponse.bind(this, 'testEmail', success, error)); - } - - getClientLicenceConfig(success, error) { - request. - get(`${this.getLicenseRoute()}/client_config`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getClientLicenceConfig', success, error)); - } - - removeLicenseFile(success, error) { - request. - post(`${this.getLicenseRoute()}/remove`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'removeLicenseFile', success, error)); - } - - uploadLicenseFile(license, success, error) { - request. - post(`${this.getLicenseRoute()}/add`). - set(this.defaultHeaders). - accept('application/json'). - attach('license', license, license.name). - end(this.handleResponse.bind(this, 'uploadLicenseFile', success, error)); - - this.trackEvent('api', 'api_license_upload'); - } - - importSlack(fileData, success, error) { - request. - post(`${this.getTeamNeededRoute()}/import_team`). - set(this.defaultHeaders). - accept('application/octet-stream'). - send(fileData). - end(this.handleResponse.bind(this, 'importSlack', success, error)); - } - - exportTeam(success, error) { - request. - get(`${this.getTeamsRoute()}/export_team`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'exportTeam', success, error)); - } - - adminResetMfa(userId, success, error) { - const data = {}; - data.user_id = userId; - - request. - post(`${this.getAdminRoute()}/reset_mfa`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'adminResetMfa', success, error)); - } - - adminResetPassword(userId, newPassword, success, error) { - var data = {}; - data.new_password = newPassword; - data.user_id = userId; - - request. - post(`${this.getAdminRoute()}/reset_password`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'adminResetPassword', success, error)); - - this.trackEvent('api', 'api_admin_reset_password'); - } - - ldapSyncNow(success, error) { - request. - post(`${this.getAdminRoute()}/ldap_sync_now`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'ldapSyncNow', success, error)); - } - - ldapTest(success, error) { - request. - post(`${this.getAdminRoute()}/ldap_test`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'ldap_test', success, error)); - } - - // 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`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({name: teamName}). - end(this.handleResponse.bind(this, 'findTeamByName', success, error)); - } - - getTeamByName(teamName, success, error) { - request. - get(`${this.getTeamsRoute()}/name/${teamName}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getTeamByName', success, error)); - } - - createTeam(team, success, error) { - request. - post(`${this.getTeamsRoute()}/create`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(team). - end(this.handleResponse.bind(this, 'createTeam', success, error)); - - this.trackEvent('api', 'api_teams_create'); - } - - updateTeam(team, success, error) { - request. - post(`${this.getTeamNeededRoute()}/update`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(team). - end(this.handleResponse.bind(this, 'updateTeam', success, error)); - - this.trackEvent('api', 'api_teams_update_name', {team_id: this.getTeamId()}); - } - - getAllTeams(success, error) { - request. - get(`${this.getTeamsRoute()}/all`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getAllTeams', success, error)); - } - - getAllTeamListings(success, error) { - request. - get(`${this.getTeamsRoute()}/all_team_listings`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getAllTeamListings', success, error)); - } - - getTeamsForUser(userId, success, error) { - // Call out to API v4 since this call doesn't exist in v3 - request. - get(`${this.url}/api/v4/users/${userId}/teams`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getTeamsForUser', success, error)); - } - - getMyTeam(success, error) { - request. - get(`${this.getTeamNeededRoute()}/me`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getMyTeam', success, error)); - } - - getTeamMembers(teamId, offset, limit, success, error) { - request. - get(`${this.getTeamNeededRoute(teamId)}/members/${offset}/${limit}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getTeamMembers', success, error)); - } - - getTeamMember(teamId, userId, success, error) { - request. - get(`${this.getTeamNeededRoute(teamId)}/members/${userId}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getTeamMember', success, error)); - } - - getMyTeamMembers(success, error) { - request. - get(`${this.getTeamsRoute()}/members`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getMyTeamMembers', success, error)); - } - - getTeamMembersForUser(userId, success, error) { - // Call out to API v4 since this call doesn't exist in v3 - request. - get(`${this.url}/api/v4/users/${userId}/teams/members`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getTeamsForUser', success, error)); - } - - getMyTeamsUnread(teamId, success, error) { - let url = `${this.getTeamsRoute()}/unread`; - - if (teamId) { - url += `?id=${encodeURIComponent(teamId)}`; - } - - request. - get(url). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getMyTeamsUnread', success, error)); - } - - getTeamMembersByIds(teamId, userIds, success, error) { - request. - post(`${this.getTeamNeededRoute(teamId)}/members/ids`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(userIds). - end(this.handleResponse.bind(this, 'getTeamMembersByIds', success, error)); - } - - getTeamStats(teamId, success, error) { - request. - get(`${this.getTeamNeededRoute(teamId)}/stats`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getTeamStats', success, error)); - } - - inviteMembers(data, success, error) { - request. - post(`${this.getTeamNeededRoute()}/invite_members`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'inviteMembers', success, error)); - - this.trackEvent('api', 'api_teams_invite_members', {team_id: this.getTeamId()}); - } - - addUserToTeam(teamId, userId, success, error) { - let nonEmptyTeamId = teamId; - if (nonEmptyTeamId === '') { - nonEmptyTeamId = this.getTeamId(); - } - - request. - post(`${this.getTeamsRoute()}/${nonEmptyTeamId}/add_user_to_team`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({user_id: userId}). - end(this.handleResponse.bind(this, 'addUserToTeam', success, error)); - - this.trackEvent('api', 'api_teams_invite_members', {team_id: nonEmptyTeamId}); - } - - addUserToTeamFromInvite(data, hash, inviteId, success, error) { - request. - post(`${this.getTeamsRoute()}/add_user_to_team_from_invite`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({hash, data, invite_id: inviteId}). - end(this.handleResponse.bind(this, 'addUserToTeam', success, error)); - - 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 === '') { - nonEmptyTeamId = this.getTeamId(); - } - - request. - post(`${this.getTeamsRoute()}/${nonEmptyTeamId}/remove_user_from_team`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({user_id: userId}). - end(this.handleResponse.bind(this, 'removeUserFromTeam', success, error)); - - this.trackEvent('api', 'api_teams_remove_members', {team_id: nonEmptyTeamId}); - } - - getInviteInfo(inviteId, success, error) { - request. - post(`${this.getTeamsRoute()}/get_invite_info`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({invite_id: inviteId}). - end(this.handleResponse.bind(this, 'getInviteInfo', success, error)); - } - - // User Routes Setions - - createUser(user, success, error) { - this.createUserWithInvite(user, null, null, null, success, error); - } - - createUserWithInvite(user, data, emailHash, inviteId, success, error) { - var url = `${this.getUsersRoute()}/create`; - - url += '?d=' + encodeURIComponent(data); - - if (emailHash) { - url += '&h=' + encodeURIComponent(emailHash); - } - - if (inviteId) { - url += '&iid=' + encodeURIComponent(inviteId); - } - - if (emailHash) { - this.trackEvent('api', 'api_users_create_email'); - } else if (inviteId) { - this.trackEvent('api', 'api_users_create_link'); - } else { - this.trackEvent('api', 'api_users_create_spontaneous'); - } - - request. - post(url). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(user). - end(this.handleResponse.bind(this, 'createUser', success, error)); - - this.trackEvent('api', 'api_users_create'); - } - - updateUser(user, type, success, error) { - request. - post(`${this.getUsersRoute()}/update`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(user). - end(this.handleResponse.bind(this, 'updateUser', success, error)); - - if (type) { - this.trackEvent('api', 'api_users_update_' + type); - } else { - this.trackEvent('api', 'api_users_update'); - } - } - - updatePassword(userId, currentPassword, newPassword, success, error) { - var data = {}; - data.user_id = userId; - data.current_password = currentPassword; - data.new_password = newPassword; - - request. - post(`${this.getUsersRoute()}/newpassword`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'updatePassword', success, error)); - - this.trackEvent('api', 'api_users_newpassword'); - } - - updateUserNotifyProps(notifyProps, success, error) { - request. - post(`${this.getUsersRoute()}/update_notify`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(notifyProps). - end(this.handleResponse.bind(this, 'updateUserNotifyProps', success, error)); - - this.trackEvent('api', 'api_users_update_notification_settings'); - } - - updateUserRoles(userId, newRoles, success, error) { - var data = { - new_roles: newRoles - }; - - request. - post(`${this.getUserNeededRoute(userId)}/update_roles`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'updateUserRoles', success, error)); - - this.trackEvent('api', 'api_users_update_roles'); - } - - updateTeamMemberRoles(teamId, userId, newRoles, success, error) { - var data = { - user_id: userId, - new_roles: newRoles - }; - - request. - post(`${this.getTeamNeededRoute(teamId)}/update_member_roles`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'updateTeamMemberRoles', success, error)); - - this.trackEvent('api', 'api_teams_update_member_roles', {team_id: teamId}); - } - - updateActive(userId, active, success, error) { - var data = {}; - data.user_id = userId; - data.active = String(active); - - request. - post(`${this.getUsersRoute()}/update_active`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'updateActive', success, error)); - - this.trackEvent('api', 'api_users_update_active'); - } - - sendPasswordReset(email, success, error) { - var data = {}; - data.email = email; - - request. - post(`${this.getUsersRoute()}/send_password_reset`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'sendPasswordReset', success, error)); - - this.trackEvent('api', 'api_users_send_password_reset'); - } - - resetPassword(code, newPassword, success, error) { - var data = {}; - data.new_password = newPassword; - data.code = code; - - request. - post(`${this.getUsersRoute()}/reset_password`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'resetPassword', success, error)); - - this.trackEvent('api', 'api_users_reset_password'); - } - - emailToOAuth(email, password, token, service, success, error) { - request. - post(`${this.getUsersRoute()}/claim/email_to_oauth`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({password, email, token, service}). - end(this.handleResponse.bind(this, 'emailToOAuth', success, error)); - - this.trackEvent('api', 'api_users_email_to_oauth'); - } - - oauthToEmail(email, password, success, error) { - var data = {}; - data.password = password; - data.email = email; - - request. - post(`${this.getUsersRoute()}/claim/oauth_to_email`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'oauthToEmail', success, error)); - - this.trackEvent('api', 'api_users_oauth_to_email'); - } - - emailToLdap(email, password, token, ldapId, ldapPassword, success, error) { - var data = {}; - data.email_password = password; - data.email = email; - data.ldap_id = ldapId; - data.ldap_password = ldapPassword; - data.token = token; - - request. - post(`${this.getUsersRoute()}/claim/email_to_ldap`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'emailToLdap', success, error)); - - this.trackEvent('api', 'api_users_email_to_ldap'); - } - - ldapToEmail(email, emailPassword, token, ldapPassword, success, error) { - var data = {}; - data.email = email; - data.ldap_password = ldapPassword; - data.email_password = emailPassword; - data.token = token; - - request. - post(`${this.getUsersRoute()}/claim/ldap_to_email`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'ldapToEmail', success, error)); - - this.trackEvent('api', 'api_users_ldap_to_email'); - } - - getInitialLoad(success, error) { - request. - get(`${this.getUsersRoute()}/initial_load`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getInitialLoad', success, error)); - } - - getMe(success, error) { - request. - get(`${this.getUsersRoute()}/me`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getMe', success, error)); - } - - getUser(userId, success, error) { - request. - get(`${this.getUserNeededRoute(userId)}/get`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getUser', success, error)); - } - - getByUsername(userName, success, error) { - request. - get(`${this.getUsersRoute()}/name/${userName}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getByUsername', success, error)); - } - - getByEmail(email, success, error) { - request. - get(`${this.getUsersRoute()}/email/${email}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getByEmail', success, error)); - } - - login(loginId, password, mfaToken, success, error) { - this.doLogin({login_id: loginId, password, token: mfaToken}, success, error); - - this.trackEvent('api', 'api_users_login'); - } - - loginById(id, password, mfaToken, success, error) { - this.doLogin({id, password, token: mfaToken}, success, error); - - this.trackEvent('api', 'api_users_login'); - } - - loginByLdap(loginId, password, mfaToken, success, error) { - this.doLogin({login_id: loginId, password, token: mfaToken, ldap_only: 'true'}, success, error); - - this.trackEvent('api', 'api_users_login'); - this.trackEvent('api', 'api_users_login_ldap'); - } - - doLogin(outgoingData, success, error) { - var outer = this; // eslint-disable-line consistent-this - - request. - post(`${this.getUsersRoute()}/login`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(outgoingData). - end(this.handleResponse.bind( - this, - 'login', - (data, res) => { - if (res && res.header) { - outer.token = res.header[HEADER_TOKEN]; - - if (outer.useToken) { - outer.defaultHeaders[HEADER_AUTH] = `${HEADER_BEARER} ${outer.token}`; - } - } - - if (success) { - success(data, res); - } - }, - error - )); - } - - logout(success, error) { - request. - post(`${this.getUsersRoute()}/logout`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'logout', success, error)); - - this.trackEvent('api', 'api_users_logout'); - } - - checkMfa(loginId, success, error) { - const data = { - login_id: loginId - }; - - request. - post(`${this.getUsersRoute()}/mfa`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'checkMfa', success, error)); - - this.trackEvent('api', 'api_users_oauth_to_email'); - } - - generateMfaSecret(success, error) { - request. - get(`${this.getUsersRoute()}/generate_mfa_secret`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'generateMfaSecret', success, error)); - } - - revokeSession(altId, success, error) { - request. - post(`${this.getUsersRoute()}/revoke_session`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({id: altId}). - end(this.handleResponse.bind(this, 'revokeSession', success, error)); - } - - getSessions(userId, success, error) { - request. - get(`${this.getUserNeededRoute(userId)}/sessions`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getSessions', success, error)); - } - - getAudits(userId, success, error) { - request. - get(`${this.getUserNeededRoute(userId)}/audits`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getAudits', success, error)); - } - - getRecentlyActiveUsers(id, success, error) { - request. - get(`${this.getAdminRoute()}/recently_active_users/${id}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getRecentlyActiveUsers', success, error)); - } - - getProfiles(offset, limit, success, error) { - request. - get(`${this.getUsersRoute()}/${offset}/${limit}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getProfiles', success, error)); - - this.trackEvent('api', 'api_profiles_get'); - } - - getProfilesInTeam(teamId, offset, limit, success, error) { - request. - get(`${this.getTeamNeededRoute(teamId)}/users/${offset}/${limit}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getProfilesInTeam', success, error)); - - 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}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getProfilesInChannel', success, error)); - - this.trackEvent('api', 'api_profiles_get_in_channel', {team_id: this.getTeamId(), channel_id: channelId}); - } - - getProfilesNotInChannel(channelId, offset, limit, success, error) { - request. - get(`${this.getChannelNeededRoute(channelId)}/users/not_in_channel/${offset}/${limit}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getProfilesNotInChannel', success, error)); - - this.trackEvent('api', 'api_profiles_get_not_in_channel', {team_id: this.getTeamId(), channel_id: channelId}); - } - - getProfilesWithoutTeam(page, perPage, 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?without_team=1&page=${page}&per_page=${perPage}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getProfilesWithoutTeam', wrappedSuccess, error)); - - this.trackEvent('api', 'api_profiles_get_without_team'); - } - - getProfilesByIds(userIds, success, error) { - request. - post(`${this.getUsersRoute()}/ids`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(userIds). - end(this.handleResponse.bind(this, 'getProfilesByIds', success, error)); - - this.trackEvent('api', 'api_profiles_get_by_ids'); - } - - searchUsers(term, teamId, options, success, error) { - request. - post(`${this.getUsersRoute()}/search`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({term, team_id: teamId, ...options}). - 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)}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'autocompleteUsersInChannel', success, error)); - } - - autocompleteUsersInTeam(term, success, error) { - request. - get(`${this.getTeamNeededRoute()}/users/autocomplete?term=${encodeURIComponent(term)}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'autocompleteUsersInTeam', success, error)); - } - - autocompleteUsers(term, success, error) { - request. - get(`${this.getUsersRoute()}/autocomplete?term=${encodeURIComponent(term)}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'autocompleteUsers', success, error)); - } - - getStatuses(success, error) { - request. - get(`${this.getUsersRoute()}/status`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getStatuses', success, error)); - } - - getStatusesByIds(userIds, success, error) { - request. - post(`${this.getUsersRoute()}/status/ids`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(userIds). - end(this.handleResponse.bind(this, 'getStatuses', success, error)); - } - - // SCHEDULED FOR DEPRECATION IN 3.8 - use viewChannel instead - setActiveChannel(id, success, error) { - request. - post(`${this.getUsersRoute()}/status/set_active_channel`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({channel_id: id}). - end(this.handleResponse.bind(this, 'setActiveChannel', success, error)); - - this.trackEvent('api', 'api_channels_set_active', {channel_id: id}); - } - - verifyEmail(token, success, error) { - request. - post(`${this.url}/api/v4/users/email/verify`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({token}). - end(this.handleResponse.bind(this, 'verifyEmail', success, error)); - } - - resendVerification(email, success, error) { - request. - post(`${this.url}/api/v4/users/email/verify/send`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({email}). - end(this.handleResponse.bind(this, 'resendVerification', success, error)); - } - - updateMfa(token, activate, success, error) { - const data = {}; - data.activate = activate; - data.token = token; - - request. - post(`${this.getUsersRoute()}/update_mfa`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'updateMfa', success, error)); - } - - uploadProfileImage(image, success, error) { - request. - post(`${this.getUsersRoute()}/newimage`). - set(this.defaultHeaders). - attach('image', image, image.name). - accept('application/json'). - end(this.handleResponse.bind(this, 'uploadProfileImage', success, error)); - - this.trackEvent('api', 'api_users_update_profile_picture'); - } - - getProfilePictureUrl(id, lastPictureUpdate) { - let url = `${this.getUsersRoute()}/${id}/image`; - - if (lastPictureUpdate) { - url += `?time=${lastPictureUpdate}`; - } - - return url; - } - - // Channel Routes Section - - createChannel(channel, success, error) { - request. - post(`${this.getChannelsRoute()}/create`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(channel). - end(this.handleResponse.bind(this, 'createChannel', success, error)); - - this.trackEvent('api', 'api_channels_create', {team_id: this.getTeamId()}); - } - - createDirectChannel(userId, success, error) { - request. - post(`${this.getChannelsRoute()}/create_direct`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({user_id: userId}). - end(this.handleResponse.bind(this, 'createDirectChannel', success, error)); - - this.trackEvent('api', 'api_channels_create_direct', {team_id: this.getTeamId()}); - } - - createGroupChannel(userIds, success, error) { - request. - post(`${this.getChannelsRoute()}/create_group`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(userIds). - end(this.handleResponse.bind(this, 'createGroupChannel', success, error)); - } - - updateChannel(channel, success, error) { - request. - post(`${this.getChannelsRoute()}/update`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(channel). - end(this.handleResponse.bind(this, 'updateChannel', success, error)); - - this.trackEvent('api', 'api_channels_update', {team_id: this.getTeamId(), channel_id: channel.id}); - } - - updateChannelHeader(channelId, header, success, error) { - const data = { - channel_id: channelId, - channel_header: header - }; - - request. - post(`${this.getChannelsRoute()}/update_header`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'updateChannel', success, error)); - - this.trackEvent('api', 'api_channels_header', {team_id: this.getTeamId(), channel_id: channelId}); - } - - updateChannelPurpose(channelId, purpose, success, error) { - const data = { - channel_id: channelId, - channel_purpose: purpose - }; - - request. - post(`${this.getChannelsRoute()}/update_purpose`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'updateChannelPurpose', success, error)); - - this.trackEvent('api', 'api_channels_purpose', {team_id: this.getTeamId(), channel_id: channelId}); - } - - updateChannelNotifyProps(data, success, error) { - request. - post(`${this.getChannelsRoute()}/update_notify_props`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'updateChannelNotifyProps', success, error)); - } - - leaveChannel(channelId, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/leave`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'leaveChannel', success, error)); - - this.trackEvent('api', 'api_channels_leave', {team_id: this.getTeamId(), channel_id: channelId}); - } - - joinChannel(channelId, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/join`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'joinChannel', success, error)); - - this.trackEvent('api', 'api_channels_join', {team_id: this.getTeamId(), channel_id: channelId}); - } - - joinChannelByName(name, success, error) { - request. - post(`${this.getChannelNameRoute(name)}/join`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'joinChannelByName', success, error)); - - this.trackEvent('api', 'api_channels_join_name', {team_id: this.getTeamId()}); - } - - deleteChannel(channelId, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/delete`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'deleteChannel', success, error)); - - this.trackEvent('api', 'api_channels_delete', {team_id: this.getTeamId(), channel_id: channelId}); - } - - viewChannel(channelId, prevChannelId = '', time = 0, success, error) { - request. - post(`${this.getChannelsRoute()}/view`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({channel_id: channelId, prev_channel_id: prevChannelId, time}). - end(this.handleResponse.bind(this, 'viewChannel', success, error)); - } - - // SCHEDULED FOR DEPRECATION IN 3.8 - use viewChannel instead - updateLastViewedAt(channelId, active, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/update_last_viewed_at`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({active}). - end(this.handleResponse.bind(this, 'updateLastViewedAt', success, error)); - } - - // SCHEDULED FOR DEPRECATION IN 3.8 - setLastViewedAt(channelId, lastViewedAt, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/set_last_viewed_at`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({last_viewed_at: lastViewedAt}). - end(this.handleResponse.bind(this, 'setLastViewedAt', success, error)); - } - - getChannels(success, error) { - request. - get(`${this.getChannelsRoute()}/`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getChannels', success, error)); - } - - getChannel(channelId, success, error) { - request. - get(`${this.getChannelNeededRoute(channelId)}/`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getChannel', success, error)); - - this.trackEvent('api', 'api_channel_get', {team_id: this.getTeamId(), channel_id: channelId}); - } - - getMoreChannelsPage(offset, limit, success, error) { - request. - get(`${this.getChannelsRoute()}/more/${offset}/${limit}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getMoreChannelsPage', success, error)); - - this.trackEvent('api', 'api_channels_more_page', {team_id: this.getTeamId()}); - } - - searchMoreChannels(term, success, error) { - request. - post(`${this.getChannelsRoute()}/more/search`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({term}). - end(this.handleResponse.bind(this, 'searchMoreChannels', success, error)); - } - - autocompleteChannels(term, success, error) { - request. - get(`${this.getChannelsRoute()}/autocomplete?term=${encodeURIComponent(term)}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'autocompleteChannels', success, error)); - } - - getChannelCounts(success, error) { - request. - get(`${this.getChannelsRoute()}/counts`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getChannelCounts', success, error)); - } - - getMyChannelMembers(success, error) { - request. - get(`${this.getChannelsRoute()}/members`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getMyChannelMembers', success, error)); - } - - getMyChannelMembersForTeam(teamId, success, error) { - request. - get(`${this.getTeamsRoute()}/${teamId}/channels/members`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getMyChannelMembersForTeam', success, error)); - } - - getChannelByName(channelName, success, error) { - request. - get(`${this.getChannelsRoute()}/name/${channelName}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getChannelByName', success, error)); - } - - getChannelStats(channelId, success, error) { - request. - get(`${this.getChannelNeededRoute(channelId)}/stats`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getChannelStats', success, error)); - } - - getChannelMember(channelId, userId, success, error) { - request. - get(`${this.getChannelNeededRoute(channelId)}/members/${userId}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getChannelMember', success, error)); - } - - getChannelMembersByIds(channelId, userIds, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/members/ids`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(userIds). - end(this.handleResponse.bind(this, 'getChannelMembersByIds', success, error)); - } - - addChannelMember(channelId, userId, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/add`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({user_id: userId}). - end(this.handleResponse.bind(this, 'addChannelMember', success, error)); - - this.trackEvent('api', 'api_channels_add_member', {team_id: this.getTeamId(), channel_id: channelId}); - } - - removeChannelMember(channelId, userId, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/remove`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({user_id: userId}). - end(this.handleResponse.bind(this, 'removeChannelMember', success, error)); - - this.trackEvent('api', 'api_channels_remove_member', {team_id: this.getTeamId(), channel_id: channelId}); - } - - updateChannelMemberRoles(channelId, userId, newRoles, success, error) { - var data = { - user_id: userId, - new_roles: newRoles - }; - - request. - post(`${this.getChannelNeededRoute(channelId)}/update_member_roles`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'updateChannelMemberRoles', success, error)); - } - - // Routes for Commands - - listCommands(success, error) { - request. - get(`${this.getCommandsRoute()}/list`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'listCommands', success, error)); - } - - executeCommand(command, commandArgs, success, error) { - request. - post(`${this.getCommandsRoute()}/execute`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({command, ...commandArgs}). - end(this.handleResponse.bind(this, 'executeCommand', success, error)); - - this.trackEvent('api', 'api_integrations_used'); - } - - addCommand(command, success, error) { - request. - post(`${this.getCommandsRoute()}/create`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(command). - end(this.handleResponse.bind(this, 'addCommand', success, error)); - - this.trackEvent('api', 'api_integrations_created'); - } - - editCommand(command, success, error) { - request. - post(`${this.getCommandsRoute()}/update`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(command). - end(this.handleResponse.bind(this, 'editCommand', success, error)); - - this.trackEvent('api', 'api_integrations_created'); - } - - deleteCommand(commandId, success, error) { - request. - post(`${this.getCommandsRoute()}/delete`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({id: commandId}). - end(this.handleResponse.bind(this, 'deleteCommand', success, error)); - - this.trackEvent('api', 'api_integrations_deleted'); - } - - listTeamCommands(success, error) { - request. - get(`${this.getCommandsRoute()}/list_team_commands`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'listTeamCommands', success, error)); - } - - regenCommandToken(commandId, success, error) { - request. - post(`${this.getCommandsRoute()}/regen_token`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({id: commandId}). - end(this.handleResponse.bind(this, 'regenCommandToken', success, error)); - } - - // Routes for Posts - - createPost(post, success, error) { - request. - post(`${this.getPostsRoute(post.channel_id)}/create`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({...post, create_at: 0}). - end(this.handleResponse.bind(this, 'createPost', success, error)); - - this.trackEvent('api', 'api_posts_create', {team_id: this.getTeamId(), channel_id: post.channel_id}); - - if (post.parent_id != null && post.parent_id !== '') { - this.trackEvent('api', 'api_posts_replied', {team_id: this.getTeamId(), channel_id: post.channel_id}); - } - } - - // This is a temporary route to get around a problem with the permissions system that - // will be fixed in 3.1 or 3.2 - getPermalinkTmp(postId, success, error) { - request. - get(`${this.getTeamNeededRoute()}/pltmp/${postId}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getPermalinkTmp', success, error)); - - this.trackEvent('api', 'api_channels_permalink', {team_id: this.getTeamId()}); - } - - getPostById(postId, success, error) { - request. - get(`${this.getTeamNeededRoute()}/posts/${postId}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getPostById', success, error)); - } - - getPost(channelId, postId, success, error) { - request. - get(`${this.getChannelNeededRoute(channelId)}/posts/${postId}/get`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getPost', success, error)); - } - - updatePost(post, success, error) { - request. - post(`${this.getPostsRoute(post.channel_id)}/update`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(post). - end(this.handleResponse.bind(this, 'updatePost', success, error)); - - this.trackEvent('api', 'api_posts_update', {team_id: this.getTeamId(), channel_id: post.channel_id}); - } - - deletePost(channelId, postId, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/posts/${postId}/delete`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'deletePost', success, error)); - - this.trackEvent('api', 'api_posts_delete', {team_id: this.getTeamId(), channel_id: channelId}); - } - - search(terms, isOrSearch, success, error) { - const data = {}; - data.terms = terms; - data.is_or_search = isOrSearch; - - request. - post(`${this.getTeamNeededRoute()}/posts/search`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(data). - end(this.handleResponse.bind(this, 'search', success, error)); - - this.trackEvent('api', 'api_posts_search', {team_id: this.getTeamId()}); - } - - getPostsPage(channelId, offset, limit, success, error) { - request. - get(`${this.getPostsRoute(channelId)}/page/${offset}/${limit}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getPostsPage', success, error)); - } - - getPosts(channelId, since, success, error) { - request. - get(`${this.getPostsRoute(channelId)}/since/${since}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getPosts', success, error)); - } - - getPostsBefore(channelId, postId, offset, numPost, success, error) { - request. - get(`${this.getPostsRoute(channelId)}/${postId}/before/${offset}/${numPost}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getPostsBefore', success, error)); - - this.trackEvent('api', 'api_posts_get_before', {team_id: this.getTeamId(), channel_id: channelId}); - } - - getPostsAfter(channelId, postId, offset, numPost, success, error) { - request. - get(`${this.getPostsRoute(channelId)}/${postId}/after/${offset}/${numPost}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getPostsAfter', success, error)); - - this.trackEvent('api', 'api_posts_get_after', {team_id: this.getTeamId(), channel_id: channelId}); - } - - getFlaggedPosts(offset, limit, success, error) { - request. - get(`${this.getTeamNeededRoute()}/posts/flagged/${offset}/${limit}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getFlaggedPosts', success, error)); - - this.trackEvent('api', 'api_posts_get_flagged', {team_id: this.getTeamId()}); - } - - getPinnedPosts(channelId, success, error) { - request. - get(`${this.getChannelNeededRoute(channelId)}/pinned`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getPinnedPosts', success, error)); - } - - getFileInfosForPost(channelId, postId, success, error) { - request. - get(`${this.getChannelNeededRoute(channelId)}/posts/${postId}/get_file_infos`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getFileInfosForPost', success, error)); - } - - getOpenGraphMetadata(url, success, error) { - request. - post(`${this.getBaseRoute()}/get_opengraph_metadata`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({url}). - end(this.handleResponse.bind(this, 'getOpenGraphMetadata', success, error)); - } - - // Routes for Files - - uploadFile(file, filename, channelId, clientId, success, error) { - this.trackEvent('api', 'api_files_upload', {team_id: this.getTeamId(), channel_id: channelId}); - - return request. - post(`${this.getTeamFilesRoute()}/upload`). - set(this.defaultHeaders). - attach('files', file, filename). - field('channel_id', channelId). - field('client_ids', clientId). - accept('application/json'). - end(this.handleResponse.bind(this, 'uploadFile', success, error)); - } - - getFile(fileId, success, error) { - request. - get(`${this.getFileRoute(fileId)}/get`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getFile', success, error)); - } - - getFileThumbnail(fileId, success, error) { - request. - get(`${this.getFileRoute(fileId)}/get_thumbnail`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getFileThumbnail', success, error)); - } - - getFilePreview(fileId, success, error) { - request. - get(`${this.getFileRoute(fileId)}/get`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getFilePreview', success, error)); - } - - getFileInfo(fileId, success, error) { - request. - get(`${this.getFileRoute(fileId)}/get_info`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getFileInfo', success, error)); - } - - getPublicLink(fileId, success, error) { - request. - get(`${this.getFileRoute(fileId)}/get_public_link`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getPublicLink', success, error)); - } - - // Routes for OAuth - - registerOAuthApp(app, success, error) { - request. - post(`${this.getOAuthRoute()}/register`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(app). - end(this.handleResponse.bind(this, 'registerOAuthApp', success, error)); - - this.trackEvent('api', 'api_apps_register'); - } - - allowOAuth2(responseType, clientId, redirectUri, state, scope, success, error) { - request. - get(`${this.getOAuthRoute()}/allow`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - query({response_type: responseType}). - query({client_id: clientId}). - query({redirect_uri: redirectUri}). - query({scope}). - query({state}). - end(this.handleResponse.bind(this, 'allowOAuth2', success, error)); - } - - listOAuthApps(success, error) { - request. - get(`${this.getOAuthRoute()}/list`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(). - end(this.handleResponse.bind(this, 'getOAuthApps', success, error)); - } - - deleteOAuthApp(id, success, error) { - request. - post(`${this.getOAuthRoute()}/delete`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({id}). - end(this.handleResponse.bind(this, 'deleteOAuthApp', success, error)); - - this.trackEvent('api', 'api_apps_delete'); - } - - getOAuthAppInfo(id, success, error) { - request. - get(`${this.getOAuthRoute()}/app/${id}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(). - end(this.handleResponse.bind(this, 'getOAuthAppInfo', success, error)); - } - - getAuthorizedApps(success, error) { - request. - get(`${this.getOAuthRoute()}/authorized`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(). - end(this.handleResponse.bind(this, 'getAuthorizedApps', success, error)); - } - - deauthorizeOAuthApp(id, success, error) { - request. - post(`${this.getOAuthRoute()}/${id}/deauthorize`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(). - end(this.handleResponse.bind(this, 'deauthorizeOAuthApp', success, error)); - } - - regenerateOAuthAppSecret(id, success, error) { - request. - post(`${this.getOAuthRoute()}/${id}/regen_secret`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(). - end(this.handleResponse.bind(this, 'regenerateOAuthAppSecret', success, error)); - } - - // Routes for Hooks - - addIncomingHook(hook, success, error) { - request. - post(`${this.getHooksRoute()}/incoming/create`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(hook). - end(this.handleResponse.bind(this, 'addIncomingHook', success, error)); - - this.trackEvent('api', 'api_integrations_created', {team_id: this.getTeamId()}); - } - - updateIncomingHook(hook, success, error) { - request. - post(`${this.getHooksRoute()}/incoming/update`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(hook). - end(this.handleResponse.bind(this, 'updateIncomingHook', success, error)); - - this.trackEvent('api', 'api_integrations_updated', {team_id: this.getTeamId()}); - } - - deleteIncomingHook(hookId, success, error) { - request. - post(`${this.getHooksRoute()}/incoming/delete`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({id: hookId}). - end(this.handleResponse.bind(this, 'deleteIncomingHook', success, error)); - - this.trackEvent('api', 'api_integrations_deleted', {team_id: this.getTeamId()}); - } - - listIncomingHooks(success, error) { - request. - get(`${this.getHooksRoute()}/incoming/list`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'listIncomingHooks', success, error)); - } - - addOutgoingHook(hook, success, error) { - request. - post(`${this.getHooksRoute()}/outgoing/create`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(hook). - end(this.handleResponse.bind(this, 'addOutgoingHook', success, error)); - - this.trackEvent('api', 'api_integrations_created', {team_id: this.getTeamId()}); - } - - updateOutgoingHook(hook, success, error) { - request. - post(`${this.getHooksRoute()}/outgoing/update`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(hook). - end(this.handleResponse.bind(this, 'updateOutgoingHook', success, error)); - - this.trackEvent('api', 'api_integrations_updated', {team_id: this.getTeamId()}); - } - - deleteOutgoingHook(hookId, success, error) { - request. - post(`${this.getHooksRoute()}/outgoing/delete`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({id: hookId}). - end(this.handleResponse.bind(this, 'deleteOutgoingHook', success, error)); - - this.trackEvent('api', 'api_integrations_deleted', {team_id: this.getTeamId()}); - } - - listOutgoingHooks(success, error) { - request. - get(`${this.getHooksRoute()}/outgoing/list`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'listOutgoingHooks', success, error)); - } - - regenOutgoingHookToken(hookId, success, error) { - request. - post(`${this.getHooksRoute()}/outgoing/regen_token`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({id: hookId}). - end(this.handleResponse.bind(this, 'regenOutgoingHookToken', success, error)); - } - - // Routes for Preferences - - getAllPreferences(success, error) { - request. - get(`${this.getBaseRoute()}/preferences/`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getAllPreferences', success, error)); - } - - savePreferences(preferences, success, error) { - request. - post(`${this.getBaseRoute()}/preferences/save`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(preferences). - end(this.handleResponse.bind(this, 'savePreferences', success, error)); - } - - getPreferenceCategory(category, success, error) { - request. - get(`${this.getBaseRoute()}/preferences/${category}`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'getPreferenceCategory', success, error)); - } - - deletePreferences(preferences, success, error) { - request. - post(`${this.getBaseRoute()}/preferences/delete`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(preferences). - end(this.handleResponse.bind(this, 'deletePreferences', success, error)); - } - - // Routes for Emoji - - listEmoji(success, error) { - request. - get(`${this.getEmojiRoute()}/list`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'listEmoji', success, error)); - } - - addEmoji(emoji, image, success, error) { - request. - post(`${this.getEmojiRoute()}/create`). - set(this.defaultHeaders). - accept('application/json'). - attach('image', image, image.name). - field('emoji', JSON.stringify(emoji)). - end(this.handleResponse.bind(this, 'addEmoji', success, error)); - - this.trackEvent('api', 'api_emoji_custom_add'); - } - - deleteEmoji(id, success, error) { - request. - post(`${this.getEmojiRoute()}/delete`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send({id}). - end(this.handleResponse.bind(this, 'deleteEmoji', success, error)); - - this.trackEvent('api', 'api_emoji_custom_delete'); - } - - getCustomEmojiImageUrl(id) { - return `${this.getEmojiRoute()}/${id}`; - } - - uploadCertificateFile(file, success, error) { - request. - post(`${this.getAdminRoute()}/add_certificate`). - set(this.defaultHeaders). - accept('application/json'). - attach('certificate', file, file.name). - end(this.handleResponse.bind(this, 'uploadCertificateFile', success, error)); - } - - removeCertificateFile(filename, success, error) { - request. - post(`${this.getAdminRoute()}/remove_certificate`). - set(this.defaultHeaders). - accept('application/json'). - send({filename}). - end(this.handleResponse.bind(this, 'removeCertificateFile', success, error)); - } - - samlCertificateStatus(success, error) { - request.get(`${this.getAdminRoute()}/saml_cert_status`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end((err, res) => { - if (err) { - return error(err); - } - - if (!res.body) { - console.error('Missing response body for samlCertificateStatus'); // eslint-disable-line no-console - } - - return success(res.body); - }); - } - - pinPost(channelId, postId, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/posts/${postId}/pin`). - set(this.defaultHeaders). - accept('application/json'). - send(). - end(this.handleResponse.bind(this, 'pinPost', success, error)); - } - - unpinPost(channelId, postId, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/posts/${postId}/unpin`). - set(this.defaultHeaders). - accept('application/json'). - send(). - end(this.handleResponse.bind(this, 'unpinPost', success, error)); - } - - saveReaction(channelId, reaction, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/posts/${reaction.post_id}/reactions/save`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(reaction). - end(this.handleResponse.bind(this, 'saveReaction', success, error)); - - this.trackEvent('api', 'api_reactions_save', {team_id: this.getTeamId(), channel_id: channelId, post_id: reaction.post_id}); - } - - deleteReaction(channelId, reaction, success, error) { - request. - post(`${this.getChannelNeededRoute(channelId)}/posts/${reaction.post_id}/reactions/delete`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - send(reaction). - end(this.handleResponse.bind(this, 'deleteReaction', success, error)); - - this.trackEvent('api', 'api_reactions_delete', {team_id: this.getTeamId(), channel_id: channelId, post_id: reaction.post_id}); - } - - listReactions(channelId, postId, success, error) { - request. - get(`${this.getChannelNeededRoute(channelId)}/posts/${postId}/reactions`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'listReactions', success, error)); - } - - webrtcToken(success, error) { - request.post(`${this.getWebrtcRoute()}/token`). - set(this.defaultHeaders). - type('application/json'). - accept('application/json'). - end(this.handleResponse.bind(this, 'webrtcToken', success, error)); - } -} diff --git a/webapp/client/web_client.jsx b/webapp/client/web_client.jsx deleted file mode 100644 index 6ae2e2ebe..000000000 --- a/webapp/client/web_client.jsx +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -// This file is only for testing on non-browser environments. -// See browser_web_client.jsx for the actual implementation for browsers. - -import Client from './client.jsx'; - -var WebClient = new Client(); -export default WebClient; diff --git a/webapp/components/admin_console/system_users/system_users.jsx b/webapp/components/admin_console/system_users/system_users.jsx index f0b3edac7..60f294dbd 100644 --- a/webapp/components/admin_console/system_users/system_users.jsx +++ b/webapp/components/admin_console/system_users/system_users.jsx @@ -16,7 +16,7 @@ import AnalyticsStore from 'stores/analytics_store.jsx'; import TeamStore from 'stores/team_store.jsx'; import UserStore from 'stores/user_store.jsx'; -import {getStandardAnalytics} from 'utils/async_client.jsx'; +import {getStandardAnalytics} from 'actions/admin_actions.jsx'; import {Constants, StatTypes, UserSearchOptions} from 'utils/constants.jsx'; import * as Utils from 'utils/utils.jsx'; diff --git a/webapp/components/admin_console/system_users/system_users_list.jsx b/webapp/components/admin_console/system_users/system_users_list.jsx index bca80428b..6d58137ff 100644 --- a/webapp/components/admin_console/system_users/system_users_list.jsx +++ b/webapp/components/admin_console/system_users/system_users_list.jsx @@ -1,16 +1,19 @@ -import PropTypes from 'prop-types'; - // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; +import PropTypes from 'prop-types'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; import ManageTeamsModal from 'components/admin_console/manage_teams_modal/manage_teams_modal.jsx'; import ResetPasswordModal from 'components/admin_console/reset_password_modal.jsx'; import SearchableUserList from 'components/searchable_user_list/searchable_user_list.jsx'; -import {getUser} from 'utils/async_client.jsx'; +import store from 'stores/redux_store.jsx'; +const dispatch = store.dispatch; +const getState = store.getState; + +import {getUser} from 'mattermost-redux/actions/users'; import {Constants} from 'utils/constants.jsx'; import * as Utils from 'utils/utils.jsx'; @@ -107,7 +110,7 @@ export default class SystemUsersList extends React.Component { } doPasswordResetSubmit(user) { - getUser(user.id); + getUser(user.id)(dispatch, getState); this.setState({ showPasswordModal: false, diff --git a/webapp/components/analytics/system_analytics.jsx b/webapp/components/analytics/system_analytics.jsx index 3abd4f259..9aa4c26c8 100644 --- a/webapp/components/analytics/system_analytics.jsx +++ b/webapp/components/analytics/system_analytics.jsx @@ -8,7 +8,7 @@ import StatisticCount from './statistic_count.jsx'; import AnalyticsStore from 'stores/analytics_store.jsx'; import * as Utils from 'utils/utils.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; +import * as AdminActions from 'actions/admin_actions.jsx'; import Constants from 'utils/constants.jsx'; const StatTypes = Constants.StatTypes; @@ -28,12 +28,12 @@ export default class SystemAnalytics extends React.Component { componentDidMount() { AnalyticsStore.addChangeListener(this.onChange); - AsyncClient.getStandardAnalytics(); - AsyncClient.getPostsPerDayAnalytics(); - AsyncClient.getUsersPerDayAnalytics(); + AdminActions.getStandardAnalytics(); + AdminActions.getPostsPerDayAnalytics(); + AdminActions.getUsersPerDayAnalytics(); if (global.window.mm_license.IsLicensed === 'true') { - AsyncClient.getAdvancedAnalytics(); + AdminActions.getAdvancedAnalytics(); } } diff --git a/webapp/components/analytics/team_analytics/team_analytics.jsx b/webapp/components/analytics/team_analytics/team_analytics.jsx index 6591d293a..c2616fede 100644 --- a/webapp/components/analytics/team_analytics/team_analytics.jsx +++ b/webapp/components/analytics/team_analytics/team_analytics.jsx @@ -11,7 +11,7 @@ import LoadingScreen from 'components/loading_screen.jsx'; import AnalyticsStore from 'stores/analytics_store.jsx'; import BrowserStore from 'stores/browser_store.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; +import * as AdminActions from 'actions/admin_actions.jsx'; import {StatTypes} from 'utils/constants.jsx'; import LineChart from 'components/analytics/line_chart.jsx'; @@ -71,10 +71,9 @@ export default class TeamAnalytics extends React.Component { } getData(id) { - AsyncClient.getStandardAnalytics(id); - AsyncClient.getPostsPerDayAnalytics(id); - AsyncClient.getUsersPerDayAnalytics(id); - AsyncClient.getRecentAndNewUsersAnalytics(id); + AdminActions.getStandardAnalytics(id); + AdminActions.getPostsPerDayAnalytics(id); + AdminActions.getUsersPerDayAnalytics(id); } componentWillUnmount() { diff --git a/webapp/components/announcement_bar/announcement_bar.jsx b/webapp/components/announcement_bar/announcement_bar.jsx index ed097c436..5d64d4d0f 100644 --- a/webapp/components/announcement_bar/announcement_bar.jsx +++ b/webapp/components/announcement_bar/announcement_bar.jsx @@ -9,7 +9,7 @@ import AnalyticsStore from 'stores/analytics_store.jsx'; import ErrorStore from 'stores/error_store.jsx'; import UserStore from 'stores/user_store.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; +import * as AdminActions from 'actions/admin_actions.jsx'; import {ErrorBarTypes, StatTypes} from 'utils/constants.jsx'; import {isLicenseExpiring, isLicenseExpired, isLicensePastGracePeriod, displayExpiryDate} from 'utils/license_utils.jsx'; import * as Utils from 'utils/utils.jsx'; @@ -150,7 +150,7 @@ export default class AnnouncementBar extends React.PureComponent { onErrorChange() { const newState = this.getState(); if (newState.message === ErrorBarTypes.LICENSE_EXPIRING && !this.state.totalUsers) { - AsyncClient.getStandardAnalytics(); + AdminActions.getStandardAnalytics(); } this.setState(newState); } diff --git a/webapp/components/channel_view.jsx b/webapp/components/channel_view.jsx index 35d2a5891..7e2f8069c 100644 --- a/webapp/components/channel_view.jsx +++ b/webapp/components/channel_view.jsx @@ -25,11 +25,9 @@ export default class ChannelView extends React.Component { this.state = this.getStateFromStores(props); } - getStateFromStores(props) { - const channel = ChannelStore.getByName(props.params.channel); - const channelId = channel ? channel.id : ''; + getStateFromStores() { return { - channelId + channelId: ChannelStore.getCurrentId() }; } isStateValid() { diff --git a/webapp/components/emoji/components/add_emoji.jsx b/webapp/components/emoji/components/add_emoji.jsx index 2387ecfff..936e15d6b 100644 --- a/webapp/components/emoji/components/add_emoji.jsx +++ b/webapp/components/emoji/components/add_emoji.jsx @@ -1,11 +1,10 @@ -import PropTypes from 'prop-types'; - // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; +import PropTypes from 'prop-types'; -import * as AsyncClient from 'utils/async_client.jsx'; +import * as EmojiActions from 'actions/emoji_actions.jsx'; import EmojiStore from 'stores/emoji_store.jsx'; import BackstageHeader from 'components/backstage/components/backstage_header.jsx'; @@ -115,7 +114,7 @@ export default class AddEmoji extends React.Component { return; } - AsyncClient.addEmoji( + EmojiActions.addEmoji( emoji, this.state.image, () => { diff --git a/webapp/components/emoji/components/emoji_list.jsx b/webapp/components/emoji/components/emoji_list.jsx index f03638601..94d82caaa 100644 --- a/webapp/components/emoji/components/emoji_list.jsx +++ b/webapp/components/emoji/components/emoji_list.jsx @@ -7,14 +7,12 @@ import LoadingScreen from 'components/loading_screen.jsx'; import EmojiStore from 'stores/emoji_store.jsx'; import UserStore from 'stores/user_store.jsx'; -import {loadEmoji} from 'actions/emoji_actions.jsx'; +import * as EmojiActions from 'actions/emoji_actions.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; import * as Utils from 'utils/utils.jsx'; -import PropTypes from 'prop-types'; - import React from 'react'; +import PropTypes from 'prop-types'; import {Link} from 'react-router'; import {FormattedMessage} from 'react-intl'; @@ -38,7 +36,7 @@ export default class EmojiList extends React.Component { this.state = { emojis: EmojiStore.getCustomEmojiMap(), - loading: !EmojiStore.hasReceivedCustomEmojis(), + loading: true, filter: '', users: UserStore.getProfiles() }; @@ -49,7 +47,7 @@ export default class EmojiList extends React.Component { UserStore.addChangeListener(this.handleUserChange); if (window.mm_config.EnableCustomEmoji === 'true') { - loadEmoji(); + EmojiActions.loadEmoji().then(() => this.setState({loading: false})); } this.updateTitle(); @@ -71,8 +69,7 @@ export default class EmojiList extends React.Component { handleEmojiChange() { this.setState({ - emojis: EmojiStore.getCustomEmojiMap(), - loading: !EmojiStore.hasReceivedCustomEmojis() + emojis: EmojiStore.getCustomEmojiMap() }); } @@ -87,7 +84,7 @@ export default class EmojiList extends React.Component { } deleteEmoji(emoji) { - AsyncClient.deleteEmoji(emoji.id); + EmojiActions.deleteEmoji(emoji.id); } render() { diff --git a/webapp/components/get_public_link_modal.jsx b/webapp/components/get_public_link_modal.jsx index b2903da87..90e2271bb 100644 --- a/webapp/components/get_public_link_modal.jsx +++ b/webapp/components/get_public_link_modal.jsx @@ -3,7 +3,7 @@ import React from 'react'; -import * as AsyncClient from 'utils/async_client.jsx'; +import {getPublicLink} from 'actions/file_actions.jsx'; import Constants from 'utils/constants.jsx'; import ModalStore from 'stores/modal_store.jsx'; import PureRenderMixin from 'react-addons-pure-render-mixin'; @@ -34,7 +34,7 @@ export default class GetPublicLinkModal extends React.Component { componentDidUpdate(prevProps, prevState) { if (this.state.show && !prevState.show) { - AsyncClient.getPublicLink(this.state.fileId, this.handlePublicLink); + getPublicLink(this.state.fileId, this.handlePublicLink); } } diff --git a/webapp/components/login/login_controller.jsx b/webapp/components/login/login_controller.jsx index 212a09bf2..3e9869226 100644 --- a/webapp/components/login/login_controller.jsx +++ b/webapp/components/login/login_controller.jsx @@ -11,8 +11,7 @@ import {checkMfa, webLogin} from 'actions/user_actions.jsx'; import BrowserStore from 'stores/browser_store.jsx'; import UserStore from 'stores/user_store.jsx'; -import Client from 'client/web_client.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; +import {Client4} from 'mattermost-redux/client'; import * as TextFormatting from 'utils/text_formatting.jsx'; import * as Utils from 'utils/utils.jsx'; @@ -71,8 +70,6 @@ export default class LoginController extends React.Component { if (this.props.location.query.extra === Constants.SIGNIN_VERIFIED && this.props.location.query.email) { this.refs.password.focus(); } - - AsyncClient.checkVersion(); } preSubmit(e) { @@ -243,7 +240,7 @@ export default class LoginController extends React.Component { return (

@@ -493,7 +490,7 @@ export default class LoginController extends React.Component { @@ -513,7 +510,7 @@ export default class LoginController extends React.Component { @@ -533,7 +530,7 @@ export default class LoginController extends React.Component { diff --git a/webapp/components/password_reset_send_link.jsx b/webapp/components/password_reset_send_link.jsx index a301fb7d4..84edf8e3d 100644 --- a/webapp/components/password_reset_send_link.jsx +++ b/webapp/components/password_reset_send_link.jsx @@ -4,7 +4,7 @@ import $ from 'jquery'; import ReactDOM from 'react-dom'; import * as Utils from 'utils/utils.jsx'; -import client from 'client/web_client.jsx'; +import {sendPasswordResetEmail} from 'actions/user_actions.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; @@ -45,7 +45,7 @@ class PasswordResetSendLink extends React.Component { error: '' }); - client.sendPasswordReset( + sendPasswordResetEmail( email, () => { this.setState({ diff --git a/webapp/components/post_view/post_list.jsx b/webapp/components/post_view/post_list.jsx index 8d790832e..b630a7d6a 100644 --- a/webapp/components/post_view/post_list.jsx +++ b/webapp/components/post_view/post_list.jsx @@ -40,7 +40,7 @@ export default class PostList extends React.PureComponent { /** * The channel the posts are in */ - channel: PropTypes.object, + channel: PropTypes.object.isRequired, /** * The last time the channel was viewed, sets the new message separator diff --git a/webapp/components/root.jsx b/webapp/components/root.jsx index 9e9ed1111..2ed493b52 100644 --- a/webapp/components/root.jsx +++ b/webapp/components/root.jsx @@ -3,7 +3,7 @@ import * as GlobalActions from 'actions/global_actions.jsx'; import LocalizationStore from 'stores/localization_store.jsx'; -import Client from 'client/web_client.jsx'; +import {Client4} from 'mattermost-redux/client'; import {IntlProvider} from 'react-intl'; @@ -85,7 +85,7 @@ export default class Root extends React.Component { localizationChanged() { const locale = LocalizationStore.getLocale(); - Client.setAcceptLanguage(locale); + Client4.setAcceptLanguage(locale); this.setState({locale, translations: LocalizationStore.getTranslations()}); } diff --git a/webapp/components/sidebar.jsx b/webapp/components/sidebar.jsx index 8b2687e26..040f12c26 100644 --- a/webapp/components/sidebar.jsx +++ b/webapp/components/sidebar.jsx @@ -18,7 +18,6 @@ import PreferenceStore from 'stores/preference_store.jsx'; import ModalStore from 'stores/modal_store.jsx'; import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; import {sortTeamsByDisplayName} from 'utils/team_utils.jsx'; import * as Utils from 'utils/utils.jsx'; import * as ChannelUtils from 'utils/channel_utils.jsx'; @@ -42,8 +41,12 @@ import favicon from 'images/favicon/favicon-16x16.png'; import redFavicon from 'images/favicon/redfavicon-16x16.png'; import store from 'stores/redux_store.jsx'; +const dispatch = store.dispatch; +const getState = store.getState; + import {getMyPreferences} from 'mattermost-redux/selectors/entities/preferences'; import {getUsers} from 'mattermost-redux/selectors/entities/users'; +import {savePreferences} from 'mattermost-redux/actions/preferences'; export default class Sidebar extends React.Component { constructor(props) { @@ -381,13 +384,8 @@ export default class Sidebar extends React.Component { category = Constants.Preferences.CATEGORY_GROUP_CHANNEL_SHOW; } - AsyncClient.savePreference( - category, - id, - 'false', - () => { - this.isLeaving.set(channel.id, false); - }, + const currentUserId = UserStore.getCurrentId(); + savePreferences(currentUserId, [{user_id: currentUserId, category, name: id, value: 'false'}])(dispatch, getState).then( () => { this.isLeaving.set(channel.id, false); } diff --git a/webapp/components/signup/signup_controller.jsx b/webapp/components/signup/signup_controller.jsx index d702b8cdf..eb1020478 100644 --- a/webapp/components/signup/signup_controller.jsx +++ b/webapp/components/signup/signup_controller.jsx @@ -1,9 +1,8 @@ -import PropTypes from 'prop-types'; - // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; +import PropTypes from 'prop-types'; import FormError from 'components/form_error.jsx'; import LoadingScreen from 'components/loading_screen.jsx'; @@ -11,8 +10,7 @@ import LoadingScreen from 'components/loading_screen.jsx'; import UserStore from 'stores/user_store.jsx'; import BrowserStore from 'stores/browser_store.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; -import Client from 'client/web_client.jsx'; +import {Client4} from 'mattermost-redux/client'; import * as GlobalActions from 'actions/global_actions.jsx'; import {addUserToTeamFromInvite, getInviteInfo} from 'actions/team_actions.jsx'; import {loadMe} from 'actions/user_actions.jsx'; @@ -62,7 +60,6 @@ export default class SignupController extends React.Component { } componentDidMount() { - AsyncClient.checkVersion(); BrowserStore.removeGlobalItem('team'); if (this.props.location.query) { const hash = this.props.location.query.h; @@ -160,7 +157,7 @@ export default class SignupController extends React.Component { @@ -180,7 +177,7 @@ export default class SignupController extends React.Component { @@ -200,7 +197,7 @@ export default class SignupController extends React.Component { diff --git a/webapp/components/suggestion/at_mention_provider.jsx b/webapp/components/suggestion/at_mention_provider.jsx index e9d09205a..f967da3e4 100644 --- a/webapp/components/suggestion/at_mention_provider.jsx +++ b/webapp/components/suggestion/at_mention_provider.jsx @@ -10,7 +10,7 @@ import {autocompleteUsersInChannel} from 'actions/user_actions.jsx'; import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import * as Utils from 'utils/utils.jsx'; -import Client from 'client/web_client.jsx'; +import {Client4} from 'mattermost-redux/client'; import {Constants, ActionTypes} from 'utils/constants.jsx'; import React from 'react'; @@ -66,7 +66,7 @@ class AtMentionSuggestion extends Suggestion { icon = ( diff --git a/webapp/components/suggestion/switch_channel_provider.jsx b/webapp/components/suggestion/switch_channel_provider.jsx index d4828ead3..8412332ea 100644 --- a/webapp/components/suggestion/switch_channel_provider.jsx +++ b/webapp/components/suggestion/switch_channel_provider.jsx @@ -4,7 +4,6 @@ import Suggestion from './suggestion.jsx'; import Provider from './provider.jsx'; -import Client from 'client/web_client.jsx'; import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import {Constants, ActionTypes} from 'utils/constants.jsx'; import * as Utils from 'utils/utils.jsx'; @@ -47,7 +46,7 @@ class SwitchChannelSuggestion extends Suggestion {
= this.props.screens.length - 1) { const step = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, UserStore.getCurrentId(), 0); - AsyncClient.savePreference( + savePreference( Preferences.TUTORIAL_STEP, UserStore.getCurrentId(), (step + 1).toString() @@ -91,7 +91,7 @@ export default class TutorialTip extends React.Component { trackEvent('tutorial', tag); } - AsyncClient.savePreference( + savePreference( Preferences.TUTORIAL_STEP, UserStore.getCurrentId(), '999' diff --git a/webapp/components/user_profile.jsx b/webapp/components/user_profile.jsx index b3290d1de..22d6b6b77 100644 --- a/webapp/components/user_profile.jsx +++ b/webapp/components/user_profile.jsx @@ -3,7 +3,7 @@ import ProfilePopover from './profile_popover.jsx'; import * as Utils from 'utils/utils.jsx'; -import Client from 'client/web_client.jsx'; +import {Client4} from 'mattermost-redux/client'; import {OverlayTrigger} from 'react-bootstrap'; @@ -63,7 +63,7 @@ export default class UserProfile extends React.Component { if (this.props.user) { name = Utils.displayUsername(this.props.user.id); - profileImg = Client.getUsersRoute() + '/' + this.props.user.id + '/image?time=' + this.props.user.last_picture_update; + profileImg = Client4.getUsersRoute() + '/' + this.props.user.id + '/image?time=' + this.props.user.last_picture_update; } if (this.props.overwriteName) { diff --git a/webapp/components/user_settings/email_notification_setting.jsx b/webapp/components/user_settings/email_notification_setting.jsx index d92a1d0a6..4dd15f0be 100644 --- a/webapp/components/user_settings/email_notification_setting.jsx +++ b/webapp/components/user_settings/email_notification_setting.jsx @@ -1,11 +1,10 @@ -import PropTypes from 'prop-types'; - // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React from 'react'; +import PropTypes from 'prop-types'; -import {savePreference} from 'utils/async_client.jsx'; +import {savePreference} from 'actions/user_actions.jsx'; import PreferenceStore from 'stores/preference_store.jsx'; import {localizeMessage} from 'utils/utils.jsx'; diff --git a/webapp/components/user_settings/user_settings_advanced.jsx b/webapp/components/user_settings/user_settings_advanced.jsx index 28beff556..1e2ae2386 100644 --- a/webapp/components/user_settings/user_settings_advanced.jsx +++ b/webapp/components/user_settings/user_settings_advanced.jsx @@ -2,21 +2,21 @@ // See License.txt for license information. import $ from 'jquery'; -import * as AsyncClient from 'utils/async_client.jsx'; import SettingItemMin from '../setting_item_min.jsx'; import SettingItemMax from '../setting_item_max.jsx'; -import Constants from 'utils/constants.jsx'; + import PreferenceStore from 'stores/preference_store.jsx'; import UserStore from 'stores/user_store.jsx'; -import * as Utils from 'utils/utils.jsx'; - -import {FormattedMessage} from 'react-intl'; +import Constants from 'utils/constants.jsx'; const PreReleaseFeatures = Constants.PRE_RELEASE_FEATURES; +import * as Utils from 'utils/utils.jsx'; -import PropTypes from 'prop-types'; +import {savePreferences} from 'actions/user_actions.jsx'; import React from 'react'; +import PropTypes from 'prop-types'; +import {FormattedMessage} from 'react-intl'; export default class AdvancedSettingsDisplay extends React.Component { constructor(props) { @@ -133,7 +133,7 @@ export default class AdvancedSettingsDisplay extends React.Component { }); }); - AsyncClient.savePreferences( + savePreferences( preferences, () => { this.updateSection(''); diff --git a/webapp/components/user_settings/user_settings_display.jsx b/webapp/components/user_settings/user_settings_display.jsx index a5ca79c55..ccc70a108 100644 --- a/webapp/components/user_settings/user_settings_display.jsx +++ b/webapp/components/user_settings/user_settings_display.jsx @@ -7,11 +7,11 @@ import SettingItemMax from '../setting_item_max.jsx'; import ManageLanguages from './manage_languages.jsx'; import ThemeSetting from './user_settings_theme.jsx'; -import * as AsyncClient from 'utils/async_client.jsx'; import PreferenceStore from 'stores/preference_store.jsx'; import UserStore from 'stores/user_store.jsx'; import * as Utils from 'utils/utils.jsx'; import * as I18n from 'i18n/i18n.jsx'; +import {savePreferences} from 'actions/user_actions.jsx'; import Constants from 'utils/constants.jsx'; const Preferences = Constants.Preferences; @@ -29,9 +29,8 @@ function getDisplayStateFromStores() { }; } -import PropTypes from 'prop-types'; - import React from 'react'; +import PropTypes from 'prop-types'; export default class UserSettingsDisplay extends React.Component { constructor(props) { @@ -92,7 +91,7 @@ export default class UserSettingsDisplay extends React.Component { value: this.state.collapseDisplay }; - AsyncClient.savePreferences([timePreference, namePreference, fontPreference, channelDisplayModePreference, messageDisplayPreference, collapseDisplayPreference], + savePreferences([timePreference, namePreference, fontPreference, channelDisplayModePreference, messageDisplayPreference, collapseDisplayPreference], () => { this.updateSection(''); }, diff --git a/webapp/components/user_settings/user_settings_general/user_settings_general.jsx b/webapp/components/user_settings/user_settings_general/user_settings_general.jsx index 8aeafd60a..0f0459180 100644 --- a/webapp/components/user_settings/user_settings_general/user_settings_general.jsx +++ b/webapp/components/user_settings/user_settings_general/user_settings_general.jsx @@ -9,7 +9,7 @@ import SettingPicture from 'components/setting_picture.jsx'; import UserStore from 'stores/user_store.jsx'; import ErrorStore from 'stores/error_store.jsx'; -import Client from 'client/web_client.jsx'; +import {Client4} from 'mattermost-redux/client'; import Constants from 'utils/constants.jsx'; import * as Utils from 'utils/utils.jsx'; @@ -1141,7 +1141,7 @@ class UserSettingsGeneralTab extends React.Component { -1 || nextState.location.pathname.indexOf('/pl/') > -1 || nextState.location.pathname.indexOf('/messages/') > -1) { - AsyncClient.getMyTeamsUnread(); + getMyTeamUnreads()(dispatch, getState); fetchMyChannelsAndMembers(team.id)(dispatch, getState); } @@ -172,13 +172,14 @@ function onChannelByIdentifierEnter(state, replace, callback) { replace(`/${state.params.team}/messages/@${teammate.username}`); callback(); } else { - Client.getUser( - userId, + getUser(userId)(dispatch, getState).then( (profile) => { - replace(`/${state.params.team}/messages/@${profile.username}`); - callback(); - }, () => { - handleError(state, replace, callback); + if (profile) { + replace(`/${state.params.team}/messages/@${profile.username}`); + callback(); + } else if (profile == null) { + handleError(state, replace, callback); + } } ); } @@ -224,7 +225,16 @@ function onChannelByIdentifierEnter(state, replace, callback) { if (teammate) { directChannelToUser(teammate, state, replace, callback); } else { - Client.getByUsername(username, success, error); + getUserByUsername(username)(dispatch, getState).then( + (data) => { + if (data && success) { + success(data); + } else if (data == null && error) { + const serverError = getState().requests.users.getUserByUsername.error; + error({id: serverError.server_error_id, ...serverError}); + } + } + ); } } else if (identifier.indexOf('@') > 0) { // email identifier const email = identifier; @@ -232,7 +242,16 @@ function onChannelByIdentifierEnter(state, replace, callback) { if (teammate) { directChannelToUser(teammate, state, replace, callback); } else { - Client.getByEmail(email, success, error); + getUserByEmail(email)(dispatch, getState).then( + (data) => { + if (data && success) { + success(data); + } else if (data == null && error) { + const serverError = getState().requests.users.getUser.error; + error({id: serverError.server_error_id, ...serverError}); + } + } + ); } } } @@ -242,10 +261,6 @@ function directChannelToUser(profile, state, replace, callback) { openDirectChannelToUser( profile.id, (channel) => { - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_CHANNEL, - channel - }); GlobalActions.emitChannelClickEvent(channel); callback(); }, diff --git a/webapp/stores/analytics_store.jsx b/webapp/stores/analytics_store.jsx index 01c60b2f9..63c8a5bee 100644 --- a/webapp/stores/analytics_store.jsx +++ b/webapp/stores/analytics_store.jsx @@ -1,19 +1,31 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; import EventEmitter from 'events'; -import Constants from 'utils/constants.jsx'; -const ActionTypes = Constants.ActionTypes; - const CHANGE_EVENT = 'change'; +import store from 'stores/redux_store.jsx'; + class AnalyticsStoreClass extends EventEmitter { constructor() { super(); - this.systemStats = {}; - this.teamStats = {}; + + this.entities = {}; + + store.subscribe(() => { + const newEntities = store.getState().entities.admin; + + if (newEntities.analytics !== this.entities.analytics) { + this.emitChange(); + } + + if (newEntities.teamAnalytics !== this.entities.teamAnalytics) { + this.emitChange(); + } + + this.entities = newEntities; + }); } emitChange() { @@ -29,57 +41,18 @@ class AnalyticsStoreClass extends EventEmitter { } getAllSystem() { - return JSON.parse(JSON.stringify(this.systemStats)); + return JSON.parse(JSON.stringify(store.getState().entities.admin.analytics)); } getAllTeam(id) { - if (id in this.teamStats) { - return JSON.parse(JSON.stringify(this.teamStats[id])); + const teamStats = store.getState().entities.admin.teamAnalytics[id]; + if (teamStats) { + return JSON.parse(JSON.stringify(teamStats)); } return {}; } - - storeSystemStats(newStats) { - for (const stat in newStats) { - if (!newStats.hasOwnProperty(stat)) { - continue; - } - this.systemStats[stat] = newStats[stat]; - } - } - - storeTeamStats(id, newStats) { - if (!(id in this.teamStats)) { - this.teamStats[id] = {}; - } - - for (const stat in newStats) { - if (!newStats.hasOwnProperty(stat)) { - continue; - } - this.teamStats[id][stat] = newStats[stat]; - } - } - } var AnalyticsStore = new AnalyticsStoreClass(); - -AnalyticsStore.dispatchToken = AppDispatcher.register((payload) => { - var action = payload.action; - - switch (action.type) { - case ActionTypes.RECEIVED_ANALYTICS: - if (action.teamId == null) { - AnalyticsStore.storeSystemStats(action.stats); - } else { - AnalyticsStore.storeTeamStats(action.teamId, action.stats); - } - AnalyticsStore.emitChange(); - break; - default: - } -}); - export default AnalyticsStore; diff --git a/webapp/stores/emoji_store.jsx b/webapp/stores/emoji_store.jsx index 812688995..d8af75dbc 100644 --- a/webapp/stores/emoji_store.jsx +++ b/webapp/stores/emoji_store.jsx @@ -1,12 +1,15 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -import Client from '../client/web_client.jsx'; -import AppDispatcher from '../dispatcher/app_dispatcher.jsx'; +import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import Constants from 'utils/constants.jsx'; import EventEmitter from 'events'; import * as Emoji from 'utils/emoji.jsx'; +import store from 'stores/redux_store.jsx'; +import {getCustomEmojisByName} from 'mattermost-redux/selectors/entities/emojis'; +import {Client4} from 'mattermost-redux/client'; + const ActionTypes = Constants.ActionTypes; const CHANGE_EVENT = 'changed'; @@ -72,10 +75,20 @@ class EmojiStore extends EventEmitter { this.setMaxListeners(600); - this.receivedCustomEmojis = false; - this.customEmojis = new Map(); + this.map = new EmojiMap(getCustomEmojisByName(store.getState())); + + this.entities = {}; - this.map = new EmojiMap(this.customEmojis); + store.subscribe(() => { + const newEntities = store.getState().entities.emojis.customEmoji; + + if (newEntities !== this.entities) { + this.map = new EmojiMap(getCustomEmojisByName(store.getState())); + this.emitChange(); + } + + this.entities = newEntities; + }); } addChangeListener(callback) { @@ -90,41 +103,12 @@ class EmojiStore extends EventEmitter { this.emit(CHANGE_EVENT); } - hasReceivedCustomEmojis() { - return this.receivedCustomEmojis; - } - - setCustomEmojis(customEmojis) { - customEmojis.sort((a, b) => a.name.localeCompare(b.name)); - - this.customEmojis = new Map(); - - for (const emoji of customEmojis) { - this.addCustomEmoji(emoji); - } - - this.map = new EmojiMap(this.customEmojis); - } - - addCustomEmoji(emoji) { - this.customEmojis.set(emoji.name, emoji); - } - - removeCustomEmoji(id) { - for (const [name, emoji] of this.customEmojis) { - if (emoji.id === id) { - this.customEmojis.delete(name); - break; - } - } - } - hasSystemEmoji(name) { return Emoji.EmojiIndicesByAlias.has(name); } getCustomEmojiMap() { - return this.customEmojis; + return getCustomEmojisByName(store.getState()); } getEmojis() { @@ -202,7 +186,7 @@ class EmojiStore extends EventEmitter { getEmojiImageUrl(emoji) { if (emoji.id) { - return Client.getCustomEmojiImageUrl(emoji.id); + return Client4.getUrlVersion() + '/emoji/' + emoji.id + '/image'; } const filename = emoji.filename || emoji.aliases[0]; @@ -214,20 +198,6 @@ class EmojiStore extends EventEmitter { const action = payload.action; switch (action.type) { - case ActionTypes.RECEIVED_CUSTOM_EMOJIS: - this.setCustomEmojis(action.emojis); - this.receivedCustomEmojis = true; - this.emitChange(); - break; - case ActionTypes.RECEIVED_CUSTOM_EMOJI: - this.addCustomEmoji(action.emoji); - this.emitChange(); - break; - case ActionTypes.REMOVED_CUSTOM_EMOJI: - this.removeCustomEmoji(action.id); - this.removeRecentEmoji(action.id); - this.emitChange(); - break; case ActionTypes.EMOJI_POSTED: this.addRecentEmoji(action.alias); this.emitChange(); diff --git a/webapp/stores/user_store.jsx b/webapp/stores/user_store.jsx index 79052d77e..c2ea619e8 100644 --- a/webapp/stores/user_store.jsx +++ b/webapp/stores/user_store.jsx @@ -3,9 +3,6 @@ import EventEmitter from 'events'; -import ChannelStore from 'stores/channel_store.jsx'; -import TeamStore from 'stores/team_store.jsx'; - import Constants from 'utils/constants.jsx'; const UserStatuses = Constants.UserStatuses; @@ -23,6 +20,9 @@ import store from 'stores/redux_store.jsx'; import * as Selectors from 'mattermost-redux/selectors/entities/users'; import {UserTypes} from 'mattermost-redux/action_types'; +import ChannelStore from 'stores/channel_store.jsx'; +import TeamStore from 'stores/team_store.jsx'; + var Utils; class UserStoreClass extends EventEmitter { diff --git a/webapp/tests/client/client_admin.test.jsx b/webapp/tests/client/client_admin.test.jsx deleted file mode 100644 index cfd539d22..000000000 --- a/webapp/tests/client/client_admin.test.jsx +++ /dev/null @@ -1,291 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe('Client.Admin', function() { - test('Admin.reloadConfig', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().reloadConfig( - function() { - done.fail(new Error('should need system admin permissions')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.recycleDatabaseConnection', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().recycleDatabaseConnection( - function() { - done.fail(new Error('should need system admin permissions')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.getComplianceReports', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().getComplianceReports( - function() { - done.fail(new Error('should need system admin permissions')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.saveComplianceReports', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - var job = {}; - job.desc = 'desc'; - job.emails = ''; - job.keywords = 'test'; - job.start_at = new Date(); - job.end_at = new Date(); - - TestHelper.basicClient().saveComplianceReports( - job, - function() { - done.fail(new Error('should need system admin permissions')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.getLogs', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().getLogs( - function() { - done.fail(new Error('should need system admin permissions')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.getServerAudits', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().getServerAudits( - function() { - done.fail(new Error('should need system admin permissions')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.getConfig', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().getConfig( - function() { - done.fail(new Error('should need system admin permissions')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.getAnalytics', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().getAnalytics( - 'standard', - null, - function() { - done.fail(new Error('should need system admin permissions')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.getTeamAnalytics', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().getTeamAnalytics( - TestHelper.basicTeam().id, - 'standard', - function() { - done.fail(new Error('should need system admin permissions')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.saveConfig', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - var config = {}; - config.site_name = 'test'; - - TestHelper.basicClient().saveConfig( - config, - function() { - done.fail(new Error('should need system admin permissions')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.testEmail', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - var config = {}; - config.site_name = 'test'; - - TestHelper.basicClient().testEmail( - config, - function() { - done.fail(new Error('should need system admin permissions')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.adminResetMfa', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - TestHelper.basicClient().adminResetMfa( - TestHelper.basicUser().id, - function() { - done.fail(new Error('should need a license')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.adminResetPassword', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - var user = TestHelper.basicUser(); - - TestHelper.basicClient().resetPassword( - user.id, - 'new_password', - function() { - throw Error('shouldnt work'); - }, - function(err) { - // this should fail since you're not a system admin - expect(err.id).toBe('api.context.invalid_param.app_error'); - done(); - } - ); - }); - }); - - test('License.getClientLicenceConfig', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getClientLicenceConfig( - function(data) { - expect(data.IsLicensed).toBe('false'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('License.removeLicenseFile', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().removeLicenseFile( - function() { - done.fail(new Error('not enabled')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); - - test('Admin.ldapSyncNow', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - TestHelper.basicClient().ldapSyncNow( - function() { - throw Error('shouldnt work'); - }, - function() { - // this should fail since you're not a system admin - done(); - } - ); - }); - }); - - test.skip('License.uploadLicenseFile', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().uploadLicenseFile( - 'form data', - function() { - done.fail(new Error('not enabled')); - }, - function(err) { - expect(err.id).toBe('api.context.permissions.app_error'); - done(); - } - ); - }); - }); -}); - diff --git a/webapp/tests/client/client_channel.test.jsx b/webapp/tests/client/client_channel.test.jsx deleted file mode 100644 index 8f69b8619..000000000 --- a/webapp/tests/client/client_channel.test.jsx +++ /dev/null @@ -1,457 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe('Client.Channels', function() { - test('createChannel', function(done) { - TestHelper.initBasic(done, () => { - var channel = TestHelper.fakeChannel(); - channel.team_id = TestHelper.basicTeam().id; - TestHelper.basicClient().createChannel( - channel, - function(data) { - expect(data.id.length).toBeGreaterThan(0); - expect(data.name).toBe(channel.name); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('createDirectChannel', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().createUser( - TestHelper.fakeUser(), - function(user2) { - TestHelper.basicClient().createDirectChannel( - user2.id, - function(data) { - expect(data.id.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('createGroupChannel', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().createUser( - TestHelper.fakeUser(), - (user1) => { - TestHelper.basicClient().createUser( - TestHelper.fakeUser(), - function(user2) { - TestHelper.basicClient().createGroupChannel( - [user2.id, user1.id], - function(data) { - expect(data.id.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updateChannel', function(done) { - TestHelper.initBasic(done, () => { - var channel = TestHelper.basicChannel(); - channel.display_name = 'changed'; - TestHelper.basicClient().updateChannel( - channel, - function(data) { - expect(data.id.length).toBeGreaterThan(0); - expect(data.display_name).toEqual('changed'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updateChannelHeader', function(done) { - TestHelper.initBasic(done, () => { - var channel = TestHelper.basicChannel(); - channel.display_name = 'changed'; - TestHelper.basicClient().updateChannelHeader( - channel.id, - 'new header', - function(data) { - expect(data.id.length).toBeGreaterThan(0); - expect(data.header).toBe('new header'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updateChannelPurpose', function(done) { - TestHelper.initBasic(done, () => { - var channel = TestHelper.basicChannel(); - channel.display_name = 'changed'; - TestHelper.basicClient().updateChannelPurpose( - channel.id, - 'new purpose', - function(data) { - expect(data.id.length).toBeGreaterThan(0); - expect(data.purpose).toEqual('new purpose'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updateChannelNotifyProps', function(done) { - TestHelper.initBasic(done, () => { - var props = {}; - props.channel_id = TestHelper.basicChannel().id; - props.user_id = TestHelper.basicUser().id; - props.desktop = 'all'; - TestHelper.basicClient().updateChannelNotifyProps( - props, - function(data) { - expect(data.desktop).toEqual('all'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('leaveChannel', function(done) { - TestHelper.initBasic(done, () => { - var channel = TestHelper.basicChannel(); - TestHelper.basicClient().leaveChannel( - channel.id, - function(data) { - expect(data.id).toEqual(channel.id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('joinChannel', function(done) { - TestHelper.initBasic(done, () => { - var channel = TestHelper.basicChannel(); - TestHelper.basicClient().leaveChannel( - channel.id, - function() { - TestHelper.basicClient().joinChannel( - channel.id, - function() { - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('joinChannelByName', function(done) { - TestHelper.initBasic(done, () => { - var channel = TestHelper.basicChannel(); - TestHelper.basicClient().leaveChannel( - channel.id, - function() { - TestHelper.basicClient().joinChannelByName( - channel.name, - function() { - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('deleteChannel', function(done) { - TestHelper.initBasic(done, () => { - var channel = TestHelper.basicChannel(); - TestHelper.basicClient().deleteChannel( - channel.id, - function(data) { - expect(data.id).toEqual(channel.id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('viewChannel', function(done) { - TestHelper.initBasic(done, () => { - var channel = TestHelper.basicChannel(); - TestHelper.basicClient().viewChannel( - channel.id, - '', - 0, - function() { - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getChannels', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getChannels( - function(data) { - expect(data.length).toBe(3); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getChannel', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getChannel( - TestHelper.basicChannel().id, - function(data) { - expect(TestHelper.basicChannel().id).toEqual(data.channel.id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getMoreChannelsPage', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getMoreChannelsPage( - 0, - 100, - function(data) { - expect(data.length).toBe(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('searchMoreChannels', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().searchMoreChannels( - 'blargh', - function(data) { - expect(data.length).toBe(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('autocompleteChannels', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().autocompleteChannels( - TestHelper.basicChannel().name, - function(data) { - expect(data).not.toBeNull(); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getChannelCounts', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getChannelCounts( - function(data) { - expect(data.counts[TestHelper.basicChannel().id]).toBe(1); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getMyChannelMembers', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getMyChannelMembers( - function(data) { - expect(data.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getMyChannelMembersForTeam', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getMyChannelMembersForTeam( - TestHelper.basicTeam().id, - function(data) { - expect(data.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getChannelStats', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getChannelStats( - TestHelper.basicChannel().id, - function(data) { - expect(data.member_count).toBe(1); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getChannelMember', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getChannelMember( - TestHelper.basicChannel().id, - TestHelper.basicUser().id, - function(data) { - expect(data.channel_id).toEqual(TestHelper.basicChannel().id); - expect(data.user_id).toEqual(TestHelper.basicUser().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('addChannelMember', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().createUserWithInvite( - TestHelper.fakeUser(), - null, - null, - TestHelper.basicTeam().invite_id, - function(user2) { - TestHelper.basicClient().addChannelMember( - TestHelper.basicChannel().id, - user2.id, - function(data) { - expect(data.channel_id.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('removeChannelMember', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().removeChannelMember( - TestHelper.basicChannel().id, - TestHelper.basicUser().id, - function(data) { - expect(data.channel_id.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getChannelByName', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getChannelByName( - TestHelper.basicChannel().name, - function(data) { - expect(data.name).toEqual(TestHelper.basicChannel().name); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); -}); - diff --git a/webapp/tests/client/client_command.test.jsx b/webapp/tests/client/client_command.test.jsx deleted file mode 100644 index 160f61ba8..000000000 --- a/webapp/tests/client/client_command.test.jsx +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe('Client.Commands', function() { - test('listCommands', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().listCommands( - function(data) { - expect(data.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('listTeamCommands', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().listTeamCommands( - function() { - done.fail(new Error('cmds not enabled')); - }, - function(err) { - expect(err.id).toEqual('api.command.disabled.app_error'); - done(); - } - ); - }); - }); - - test('executeCommand', function(done) { - TestHelper.initBasic(done, () => { - const args = {}; - args.channel_id = TestHelper.basicChannel().id; - TestHelper.basicClient().executeCommand( - '/shrug', - args, - function(data) { - expect(data.response_type).toEqual('in_channel'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('addCommand', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - var cmd = {}; - cmd.url = 'http://www.gonowhere.com'; - cmd.trigger = '/hello'; - cmd.method = 'P'; - cmd.username = ''; - cmd.icon_url = ''; - cmd.auto_complete = false; - cmd.auto_complete_desc = ''; - cmd.auto_complete_hint = ''; - cmd.display_name = 'Unit Test'; - - TestHelper.basicClient().addCommand( - cmd, - function() { - done.fail(new Error('cmds not enabled')); - }, - function(err) { - expect(err.id).toEqual('api.command.disabled.app_error'); - done(); - } - ); - }); - }); - - test('editCommand', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - var cmd = {}; - cmd.url = 'http://www.gonowhere.com'; - cmd.trigger = '/hello'; - cmd.method = 'P'; - cmd.username = ''; - cmd.icon_url = ''; - cmd.auto_complete = false; - cmd.auto_complete_desc = ''; - cmd.auto_complete_hint = ''; - cmd.display_name = 'Unit Test'; - - TestHelper.basicClient().editCommand( - cmd, - function() { - done.fail(new Error('cmds not enabled')); - }, - function(err) { - expect(err.id).toEqual('api.command.disabled.app_error'); - done(); - } - ); - }); - }); - - test('deleteCommand', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().deleteCommand( - TestHelper.generateId(), - function() { - done.fail(new Error('cmds not enabled')); - }, - function(err) { - expect(err.id).toEqual('api.command.disabled.app_error'); - done(); - } - ); - }); - }); - - test('regenCommandToken', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().regenCommandToken( - TestHelper.generateId(), - function() { - done.fail(new Error('cmds not enabled')); - }, - function(err) { - expect(err.id).toEqual('api.command.disabled.app_error'); - done(); - } - ); - }); - }); -}); - diff --git a/webapp/tests/client/client_emoji.test.jsx b/webapp/tests/client/client_emoji.test.jsx deleted file mode 100644 index 8946a5ccc..000000000 --- a/webapp/tests/client/client_emoji.test.jsx +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -const fs = require('fs'); - -describe('Client.Emoji', function() { - const testGifFileName = 'testEmoji.gif'; - - beforeAll(function() { - // write a temporary file so that we have something to upload for testing - const buffer = new Buffer('R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=', 'base64'); - const testGif = fs.openSync(testGifFileName, 'w+'); - fs.writeFileSync(testGif, buffer); - }); - - afterAll(function() { - fs.unlinkSync(testGifFileName); - }); - - test('addEmoji', function(done) { - TestHelper.initBasic(done, () => { - const name = TestHelper.generateId(); - - TestHelper.basicClient().addEmoji( - {creator_id: TestHelper.basicUser().id, name}, - fs.createReadStream(testGifFileName), - function(data) { - expect(data.name).toEqual(name); - expect(data.id).not.toBeNull(); - - //TestHelper.basicClient().deleteEmoji(data.id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('deleteEmoji', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().addEmoji( - {creator_id: TestHelper.basicUser().id, name: TestHelper.generateId()}, - fs.createReadStream(testGifFileName), - function(data) { - TestHelper.basicClient().deleteEmoji( - data.id, - function() { - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('listEmoji', function(done) { - TestHelper.initBasic(done, () => { - const name = TestHelper.generateId(); - TestHelper.basicClient().addEmoji( - {creator_id: TestHelper.basicUser().id, name}, - fs.createReadStream(testGifFileName), - function() { - TestHelper.basicClient().listEmoji( - function(data) { - expect(data.length).toBeGreaterThan(0); - - let found = false; - for (const emoji of data) { - if (emoji.name === name) { - found = true; - break; - } - } - - if (found) { - done(); - } else { - done.fail(new Error('test emoji wasn\'t returned')); - } - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); -}); diff --git a/webapp/tests/client/client_file.test.jsx b/webapp/tests/client/client_file.test.jsx deleted file mode 100644 index a1f12a899..000000000 --- a/webapp/tests/client/client_file.test.jsx +++ /dev/null @@ -1,248 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -const fs = require('fs'); - -describe('Client.File', function() { - const testGifFileName = 'testFile.gif'; - - beforeAll(function() { - // write a temporary file so that we have something to upload for testing - const buffer = new Buffer('R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=', 'base64'); - - const testGif = fs.openSync(testGifFileName, 'w+'); - fs.writeFileSync(testGif, buffer); - }); - - afterAll(function() { - fs.unlinkSync(testGifFileName); - }); - - test('uploadFile', function(done) { - TestHelper.initBasic(done, () => { - const clientId = TestHelper.generateId(); - - TestHelper.basicClient().uploadFile( - fs.createReadStream(testGifFileName), - testGifFileName, - TestHelper.basicChannel().id, - clientId, - function(resp) { - expect(resp.file_infos.length).toBe(1); - expect(resp.client_ids.length).toBe(1); - expect(resp.client_ids[0]).toEqual(clientId); - - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getFile', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().uploadFile( - fs.createReadStream(testGifFileName), - testGifFileName, - TestHelper.basicChannel().id, - '', - function(resp) { - TestHelper.basicClient().getFile( - resp.file_infos[0].id, - function() { - done(); - }, - function(err2) { - done.fail(new Error(err2.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getFileThumbnail', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().uploadFile( - fs.createReadStream(testGifFileName), - testGifFileName, - TestHelper.basicChannel().id, - '', - function(resp) { - TestHelper.basicClient().getFileThumbnail( - resp.file_infos[0].id, - function() { - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getFilePreview', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().uploadFile( - fs.createReadStream(testGifFileName), - testGifFileName, - TestHelper.basicChannel().id, - '', - function(resp) { - TestHelper.basicClient().getFilePreview( - resp.file_infos[0].id, - function() { - done(); - }, - function(err2) { - done.fail(new Error(err2.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getFileInfo', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().uploadFile( - fs.createReadStream(testGifFileName), - testGifFileName, - TestHelper.basicChannel().id, - '', - function(resp) { - const fileId = resp.file_infos[0].id; - - TestHelper.basicClient().getFileInfo( - fileId, - function(info) { - expect(info.id).toEqual(fileId); - expect(info.name).toEqual(testGifFileName); - - done(); - }, - function(err2) { - done.fail(new Error(err2.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getPublicLink', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().uploadFile( - fs.createReadStream(testGifFileName), - testGifFileName, - TestHelper.basicChannel().id, - '', - function(resp) { - const post = TestHelper.fakePost(); - post.channel_id = TestHelper.basicChannel().id; - post.file_ids = resp.file_infos.map((info) => info.id); - - TestHelper.basicClient().createPost( - post, - function(data) { - expect(data.file_ids).toEqual(post.file_ids); - - TestHelper.basicClient().getPublicLink( - post.file_ids[0], - function() { - done.fail(new Error('public links should be disabled by default')); - - // request. - // get(link). - // end(TestHelper.basicChannel().handleResponse.bind( - // this, - // 'getPublicLink', - // function() { - // done(); - // }, - // function(err4) { - // done.fail(new Error(err4.message)); - // } - // )); - }, - function() { - done(); - - // done.fail(new Error(err3.message)); - } - ); - }, - function(err2) { - done.fail(new Error(err2.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getFileInfosForPost', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().uploadFile( - fs.createReadStream(testGifFileName), - testGifFileName, - TestHelper.basicChannel().id, - '', - function(resp) { - const post = TestHelper.fakePost(); - post.channel_id = TestHelper.basicChannel().id; - post.file_ids = resp.file_infos.map((info) => info.id); - - TestHelper.basicClient().createPost( - post, - function(data) { - expect(data.file_ids).toEqual(post.file_ids); - - TestHelper.basicClient().getFileInfosForPost( - post.channel_id, - data.id, - function(files) { - expect(files.length).toBe(1); - expect(files[0].id).toEqual(resp.file_infos[0].id); - - done(); - }, - function(err3) { - done.fail(new Error(err3.message)); - } - ); - }, - function(err2) { - done.fail(new Error(err2.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); -}); diff --git a/webapp/tests/client/client_general.test.jsx b/webapp/tests/client/client_general.test.jsx deleted file mode 100644 index c18b89ffb..000000000 --- a/webapp/tests/client/client_general.test.jsx +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe('Client.General', function() { - test('General.getClientConfig', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getClientConfig( - function(data) { - expect(data.SiteName).toEqual('Mattermost'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('General.getPing', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getPing( - function(data) { - expect(data.version.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('General.logClientError', function(done) { - TestHelper.initBasic(done, () => { - var config = {}; - config.site_name = 'test'; - TestHelper.basicClient().logClientError('this is a test'); - done(); - }); - }); -}); - diff --git a/webapp/tests/client/client_hooks.test.jsx b/webapp/tests/client/client_hooks.test.jsx deleted file mode 100644 index 81f1aa7a0..000000000 --- a/webapp/tests/client/client_hooks.test.jsx +++ /dev/null @@ -1,173 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe('Client.Hooks', function() { - test('addIncomingHook', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - var hook = {}; - hook.channel_id = TestHelper.basicChannel().id; - hook.description = 'desc'; - hook.display_name = 'Unit Test'; - - TestHelper.basicClient().addIncomingHook( - hook, - function() { - done.fail(new Error('hooks not enabled')); - }, - function(err) { - expect(err.id).toBe('api.incoming_webhook.disabled.app_error'); - done(); - } - ); - }); - }); - - test('updateIncomingHook', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - var hook = {}; - hook.channel_id = TestHelper.basicChannel().id; - hook.description = 'desc'; - hook.display_name = 'Unit Test'; - - TestHelper.basicClient().updateIncomingHook( - hook, - function() { - done.fail(new Error('hooks not enabled')); - }, - function(err) { - expect(err.id).toBe('api.incoming_webhook.disabled.app_error'); - done(); - } - ); - }); - }); - - test('deleteIncomingHook', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().deleteIncomingHook( - TestHelper.generateId(), - function() { - done.fail(new Error('hooks not enabled')); - }, - function(err) { - expect(err.id).toBe('api.incoming_webhook.disabled.app_error'); - done(); - } - ); - }); - }); - - test('listIncomingHooks', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().listIncomingHooks( - function() { - done.fail(new Error('hooks not enabled')); - }, - function(err) { - expect(err.id).toBe('api.incoming_webhook.disabled.app_error'); - done(); - } - ); - }); - }); - - test('addOutgoingHook', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - var hook = {}; - hook.channel_id = TestHelper.basicChannel().id; - hook.description = 'desc'; - hook.display_name = 'Unit Test'; - - TestHelper.basicClient().addOutgoingHook( - hook, - function() { - done.fail(new Error('hooks not enabled')); - }, - function(err) { - expect(err.id).toBe('api.outgoing_webhook.disabled.app_error'); - done(); - } - ); - }); - }); - - test('deleteOutgoingHook', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().deleteOutgoingHook( - TestHelper.generateId(), - function() { - done.fail(new Error('hooks not enabled')); - }, - function(err) { - expect(err.id).toBe('api.outgoing_webhook.disabled.app_error'); - done(); - } - ); - }); - }); - - test('listOutgoingHooks', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().listOutgoingHooks( - function() { - done.fail(new Error('hooks not enabled')); - }, - function(err) { - expect(err.id).toBe('api.outgoing_webhook.disabled.app_error'); - done(); - } - ); - }); - }); - - test('regenOutgoingHookToken', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().regenOutgoingHookToken( - TestHelper.generateId(), - function() { - done.fail(new Error('hooks not enabled')); - }, - function(err) { - expect(err.id).toBe('api.outgoing_webhook.disabled.app_error'); - done(); - } - ); - }); - }); - - test('updateOutgoingHook', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - var hook = {}; - hook.channel_id = TestHelper.basicChannel().id; - hook.description = 'desc'; - hook.display_name = 'Unit Test'; - - TestHelper.basicClient().updateOutgoingHook( - hook, - function() { - done.fail(new Error('hooks not enabled')); - }, - function(err) { - expect(err.id).toBe('api.outgoing_webhook.disabled.app_error'); - done(); - } - ); - }); - }); -}); - diff --git a/webapp/tests/client/client_oauth.test.jsx b/webapp/tests/client/client_oauth.test.jsx deleted file mode 100644 index 44ce95a19..000000000 --- a/webapp/tests/client/client_oauth.test.jsx +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe('Client.OAuth', function() { - test('registerOAuthApp', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - var app = {}; - app.name = 'test'; - app.homepage = 'homepage'; - app.description = 'desc'; - app.callback_urls = ['']; - - TestHelper.basicClient().registerOAuthApp( - app, - function() { - done.fail(new Error('not enabled')); - }, - function(err) { - expect(err.id).toBe('api.oauth.register_oauth_app.turn_off.app_error'); - done(); - } - ); - }); - }); - - test('allowOAuth2', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - TestHelper.basicClient().allowOAuth2( - 'GET', - '12345678901234567890123456', - 'http://nowhere.com', - 'state', - 'scope', - function() { - done.fail(new Error('not enabled')); - }, - function(err) { - expect(err.id).toBe('api.oauth.allow_oauth.turn_off.app_error'); - done(); - } - ); - }); - }); -}); diff --git a/webapp/tests/client/client_post.test.jsx b/webapp/tests/client/client_post.test.jsx deleted file mode 100644 index ee63c9aaa..000000000 --- a/webapp/tests/client/client_post.test.jsx +++ /dev/null @@ -1,233 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe('Client.Posts', function() { - test('createPost', function(done) { - TestHelper.initBasic(done, () => { - var post = TestHelper.fakePost(); - post.channel_id = TestHelper.basicChannel().id; - - TestHelper.basicClient().createPost( - post, - function(data) { - expect(data.id.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getPostById', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getPostById( - TestHelper.basicPost().id, - function(data) { - expect(data.order[0]).toEqual(TestHelper.basicPost().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getPost', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getPost( - TestHelper.basicChannel().id, - TestHelper.basicPost().id, - function(data) { - expect(data.order[0]).toEqual(TestHelper.basicPost().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updatePost', function(done) { - TestHelper.initBasic(done, () => { - var post = TestHelper.basicPost(); - post.message = 'new message'; - post.channel_id = TestHelper.basicChannel().id; - - TestHelper.basicClient().updatePost( - post, - function(data) { - expect(data.id.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('deletePost', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().deletePost( - TestHelper.basicChannel().id, - TestHelper.basicPost().id, - function(data) { - expect(data.id).toEqual(TestHelper.basicPost().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('searchPost', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().search( - 'unit test', - false, - function(data) { - expect(data.order[0]).toEqual(TestHelper.basicPost().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getPostsPage', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getPostsPage( - TestHelper.basicChannel().id, - 0, - 10, - function(data) { - expect(data.order[0]).toEqual(TestHelper.basicPost().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getPosts', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getPosts( - TestHelper.basicChannel().id, - 0, - function(data) { - expect(data.order[0]).toEqual(TestHelper.basicPost().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getPostsBefore', function(done) { - TestHelper.initBasic(done, () => { - var post = TestHelper.fakePost(); - post.channel_id = TestHelper.basicChannel().id; - - TestHelper.basicClient().createPost( - post, - function(rpost) { - TestHelper.basicClient().getPostsBefore( - TestHelper.basicChannel().id, - rpost.id, - 0, - 10, - function(data) { - expect(data.order[0]).toEqual(TestHelper.basicPost().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getPostsAfter', function(done) { - TestHelper.initBasic(done, () => { - var post = TestHelper.fakePost(); - post.channel_id = TestHelper.basicChannel().id; - - TestHelper.basicClient().createPost( - post, - function(rpost) { - TestHelper.basicClient().getPostsAfter( - TestHelper.basicChannel().id, - TestHelper.basicPost().id, - 0, - 10, - function(data) { - expect(data.order[0]).toEqual(rpost.id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getFlaggedPosts', function(done) { - TestHelper.initBasic(done, () => { - var pref = {}; - pref.user_id = TestHelper.basicUser().id; - pref.category = 'flagged_post'; - pref.name = TestHelper.basicPost().id; - pref.value = 'true'; - - var prefs = []; - prefs.push(pref); - - TestHelper.basicClient().savePreferences( - prefs, - function() { - TestHelper.basicClient().getFlaggedPosts( - 0, - 2, - function(data) { - expect(data.order[0]).toEqual(TestHelper.basicPost().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - // getFileInfosForPost is tested in client_files.test.jsx -}); - diff --git a/webapp/tests/client/client_preferences.test.jsx b/webapp/tests/client/client_preferences.test.jsx deleted file mode 100644 index 49241c72c..000000000 --- a/webapp/tests/client/client_preferences.test.jsx +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe('Client.Preferences', function() { - test('getAllPreferences', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getAllPreferences( - function(data) { - expect(data[0].category).toBe('tutorial_step'); - expect(data[0].user_id).toEqual(TestHelper.basicUser().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('savePreferences', function(done) { - TestHelper.initBasic(done, () => { - var perf = {}; - perf.user_id = TestHelper.basicUser().id; - perf.category = 'test'; - perf.name = 'name'; - perf.value = 'value'; - - var perfs = []; - perfs.push(perf); - - TestHelper.basicClient().savePreferences( - perfs, - function(data) { - expect(data).toBe(true); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getPreferenceCategory', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getPreferenceCategory( - 'tutorial_step', - function(data) { - expect(data[0].category).toBe('tutorial_step'); - expect(data[0].user_id).toEqual(TestHelper.basicUser().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); -}); - diff --git a/webapp/tests/client/client_reaction.test.jsx b/webapp/tests/client/client_reaction.test.jsx deleted file mode 100644 index d1571d3ae..000000000 --- a/webapp/tests/client/client_reaction.test.jsx +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe('Client.Reaction', function() { - test('saveListReaction', function(done) { - TestHelper.initBasic(done, () => { - const channelId = TestHelper.basicChannel().id; - const postId = TestHelper.basicPost().id; - - const reaction = { - post_id: postId, - user_id: TestHelper.basicUser().id, - emoji_name: 'upside_down_face' - }; - - TestHelper.basicClient().saveReaction( - channelId, - reaction, - function() { - TestHelper.basicClient().listReactions( - channelId, - postId, - function(reactions) { - if (reactions.length === 1 && - reactions[0].post_id === reaction.post_id && - reactions[0].user_id === reaction.user_id && - reactions[0].emoji_name === reaction.emoji_name) { - done(); - } else { - done.fail(new Error('test reaction wasn\'t returned')); - } - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('deleteReaction', function(done) { - TestHelper.initBasic(done, () => { - const channelId = TestHelper.basicChannel().id; - const postId = TestHelper.basicPost().id; - - const reaction = { - post_id: postId, - user_id: TestHelper.basicUser().id, - emoji_name: 'upside_down_face' - }; - - TestHelper.basicClient().saveReaction( - channelId, - reaction, - function() { - TestHelper.basicClient().deleteReaction( - channelId, - reaction, - function() { - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); -}); diff --git a/webapp/tests/client/client_team.test.jsx b/webapp/tests/client/client_team.test.jsx deleted file mode 100644 index 66927d44d..000000000 --- a/webapp/tests/client/client_team.test.jsx +++ /dev/null @@ -1,309 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe('Client.Team', function() { - test('findTeamByName', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().findTeamByName( - TestHelper.basicTeam().name, - function(data) { - expect(data).toBe(true); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('createTeam', function(done) { - var team = TestHelper.fakeTeam(); - TestHelper.initBasic(done, () => { - TestHelper.basicClient().createTeam( - team, - function(data) { - expect(data.id.length).toBeGreaterThan(0); - expect(data.name).toEqual(team.name); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getAllTeams', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getAllTeams( - function(data) { - expect(data[TestHelper.basicTeam().id].name).toEqual(TestHelper.basicTeam().name); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getAllTeamListings', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getAllTeamListings( - function(data) { - expect(data).not.toBeNull(); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getMyTeam', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getMyTeam( - function(data) { - expect(data.name).toEqual(TestHelper.basicTeam().name); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getMyTeamMembers', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getMyTeamMembers( - function(data) { - expect(data.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getTeamMembers', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getTeamMembers( - TestHelper.basicTeam().id, - 0, - 100, - function(data) { - expect(data.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getTeamMember', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getTeamMember( - TestHelper.basicTeam().id, - TestHelper.basicUser().id, - function(data) { - expect(data.user_id).toEqual(TestHelper.basicUser().id); - expect(data.team_id).toEqual(TestHelper.basicTeam().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getTeamStats', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getTeamStats( - TestHelper.basicTeam().id, - function(data) { - expect(data.total_member_count).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getTeamMembersByIds', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getTeamMembersByIds( - TestHelper.basicTeam().id, - [TestHelper.basicUser().id], - function(data) { - expect(data[0].user_id).toEqual(TestHelper.basicUser().id); - expect(data[0].team_id).toEqual(TestHelper.basicTeam().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('inviteMembers', function(done) { - TestHelper.initBasic(done, () => { - var data = {}; - data.invites = []; - var invite = {}; - invite.email = TestHelper.fakeEmail(); - invite.firstName = 'first'; - invite.lastName = 'last'; - data.invites.push(invite); - - TestHelper.basicClient().inviteMembers( - data, - function(dataBack) { - expect(dataBack.invites.length).toBe(1); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updateTeam', function(done) { - TestHelper.initBasic(done, () => { - var team = TestHelper.basicTeam(); - team.display_name = 'test_updated'; - - TestHelper.basicClient().updateTeam( - team, - function(data) { - expect(data.display_name).toBe('test_updated'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updateTeamDescription', function(done) { - TestHelper.initBasic(done, () => { - var team = TestHelper.basicTeam(); - team.description = 'test_updated'; - - TestHelper.basicClient().updateTeam( - team, - function(data) { - expect(data.description).toBe('test_updated'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('addUserToTeam', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().createUser( - TestHelper.fakeUser(), - function(user2) { - TestHelper.basicClient().addUserToTeam( - '', - user2.id, - function(data) { - expect(data.user_id).toEqual(user2.id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('removeUserFromTeam', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().removeUserFromTeam( - '', - TestHelper.basicUser().id, - function(data) { - expect(data.user_id).toEqual(TestHelper.basicUser().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getInviteInfo', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getInviteInfo( - TestHelper.basicTeam().invite_id, - function(data) { - expect(data.display_name.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updateTeamMemberRoles', function(done) { - TestHelper.initBasic(done, () => { - var user = TestHelper.basicUser(); - var team = TestHelper.basicTeam(); - - TestHelper.basicClient().updateTeamMemberRoles( - team.id, - user.id, - '', - function() { - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getTeamByName', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getTeamByName( - TestHelper.basicTeam().name, - function(data) { - expect(data.name).toEqual(TestHelper.basicTeam().name); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); -}); - diff --git a/webapp/tests/client/client_user.test.jsx b/webapp/tests/client/client_user.test.jsx deleted file mode 100644 index 480d7df10..000000000 --- a/webapp/tests/client/client_user.test.jsx +++ /dev/null @@ -1,700 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe('Client.User', function() { - test('getMe', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getMe( - function(data) { - expect(data.id).toEqual(TestHelper.basicUser().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getUser', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getUser( - TestHelper.basicUser().id, - function(data) { - expect(data.id).toEqual(TestHelper.basicUser().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getByUsername', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getByUsername( - TestHelper.basicUser().username, - function(data) { - expect(data.username).toEqual(TestHelper.basicUser().username); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getByEmail', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getByEmail( - TestHelper.basicUser().email, - function(data) { - expect(data.email).toEqual(TestHelper.basicUser().email); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getInitialLoad', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getInitialLoad( - function(data) { - expect(data.user.id.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('createUser', function(done) { - var client = TestHelper.createClient(); - var user = TestHelper.fakeUser(); - client.createUser( - user, - function(data) { - expect(data.id.length).toBeGreaterThan(0); - expect(data.email).toEqual(user.email); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - - test('loginByEmail', function(done) { - var client = TestHelper.createClient(); - var user = TestHelper.fakeUser(); - client.createUser( - user, - function() { - client.login( - user.email, - user.password, - null, - function(data) { - expect(data.id.length).toBeGreaterThan(0); - expect(data.email).toEqual(user.email); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - - test('loginById', function(done) { - var client = TestHelper.createClient(); - var user = TestHelper.fakeUser(); - client.createUser( - user, - function(newUser) { - expect(user.email).toEqual(newUser.email); - client.loginById( - newUser.id, - user.password, - null, - function(data) { - expect(data.id.length).toBeGreaterThan(0); - expect(data.email).toEqual(user.email); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - - test('loginByUsername', function(done) { - var client = TestHelper.createClient(); - var user = TestHelper.fakeUser(); - client.createUser( - user, - function() { - client.login( - user.username, - user.password, - null, - function(data) { - expect(data.id.length).toBeGreaterThan(0); - expect(data.email).toEqual(user.email); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - - test('updateUser', function(done) { - TestHelper.initBasic(done, () => { - var user = TestHelper.basicUser(); - user.nickname = 'updated'; - - TestHelper.basicClient().updateUser( - user, null, - function(data) { - expect(data.nickname).toBe('updated'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updatePassword', function(done) { - TestHelper.initBasic(done, () => { - var user = TestHelper.basicUser(); - - TestHelper.basicClient().updatePassword( - user.id, - user.password, - 'update_password', - function(data) { - expect(data.user_id).toEqual(user.id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updateUserNotifyProps', function(done) { - TestHelper.initBasic(done, () => { - var user = TestHelper.basicUser(); - - var notifyProps = { - all: 'true', - channel: 'true', - desktop: 'all', - desktop_sound: 'true', - email: 'false', - first_name: 'false', - mention_keys: '', - comments: 'any', - user_id: user.id - }; - - TestHelper.basicClient().updateUserNotifyProps( - notifyProps, - function(data) { - expect(data.notify_props.email).toBe('false'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updateUserRoles', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - var user = TestHelper.basicUser(); - - TestHelper.basicClient().updateUserRoles( - user.id, - '', - function() { - done.fail(new Error('Not supposed to work')); - }, - function() { - done(); - } - ); - }); - }); - - test('updateActive', function(done) { - TestHelper.initBasic(done, () => { - const user = TestHelper.basicUser(); - - TestHelper.basicClient().updateActive( - user.id, - false, - function(data) { - expect(data.delete_at).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('sendPasswordReset', function(done) { - TestHelper.initBasic(done, () => { - var user = TestHelper.basicUser(); - - TestHelper.basicClient().sendPasswordReset( - user.email, - function(data) { - expect(data.email).toEqual(user.email); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('resetPassword', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - - TestHelper.basicClient().resetPassword( - '', - 'new_password', - function() { - throw Error('shouldnt work'); - }, - function(err) { - // this should fail since you're not a system admin - expect(err.id).toBe('api.context.invalid_param.app_error'); - done(); - } - ); - }); - }); - - test('emailToOAuth', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - var user = TestHelper.basicUser(); - - TestHelper.basicClient().emailToOAuth( - user.email, - 'new_password', - '', - 'gitlab', - function() { - throw Error('shouldnt work'); - }, - function(err) { - // this should fail since you're not a system admin - expect(err.id).toBe('api.user.check_user_password.invalid.app_error'); - done(); - } - ); - }); - }); - - test('oauthToEmail', function(done) { - TestHelper.initBasic(done, () => { - var user = TestHelper.basicUser(); - - TestHelper.basicClient().oauthToEmail( - user.email, - 'new_password', - function(data) { - expect(data.follow_link.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('emailToLdap', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - var user = TestHelper.basicUser(); - - TestHelper.basicClient().emailToLdap( - user.email, - user.password, - '', - 'unknown_id', - 'unknown_pwd', - function() { - throw Error('shouldnt work'); - }, - function() { - done(); - } - ); - }); - }); - - test('ldapToEmail', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - var user = TestHelper.basicUser(); - - TestHelper.basicClient().ldapToEmail( - user.email, - 'new_password', - '', - 'new_password', - function() { - throw Error('shouldnt work'); - }, - function(err) { - expect(err.id).toBe('api.user.ldap_to_email.not_ldap_account.app_error'); - done(); - } - ); - }); - }); - - test('logout', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().logout( - function(data) { - expect(data.user_id).toEqual(TestHelper.basicUser().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('checkMfa', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().checkMfa( - TestHelper.generateId(), - function(data) { - expect(data.mfa_required).toBe('false'); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('generateMfaSecret', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().generateMfaSecret( - function() { - done.fail(new Error('not enabled')); - }, - function() { - done(); - } - ); - }); - }); - - test('getSessions', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getSessions( - TestHelper.basicUser().id, - function(data) { - expect(data[0].user_id).toEqual(TestHelper.basicUser().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('revokeSession', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getSessions( - TestHelper.basicUser().id, - function(sessions) { - TestHelper.basicClient().revokeSession( - sessions[0].id, - function(data) { - expect(data.id).toEqual(sessions[0].id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getAudits', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getAudits( - TestHelper.basicUser().id, - function(data) { - expect(data[0].user_id).toEqual(TestHelper.basicUser().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getProfiles', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getProfiles( - 0, - 100, - function(data) { - expect(Object.keys(data).length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getProfilesInTeam', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getProfilesInTeam( - TestHelper.basicTeam().id, - 0, - 100, - function(data) { - expect(data[TestHelper.basicUser().id].id).toEqual(TestHelper.basicUser().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getProfilesByIds', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getProfilesByIds( - [TestHelper.basicUser().id], - function(data) { - expect(data[TestHelper.basicUser().id].id).toEqual(TestHelper.basicUser().id); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getProfilesInChannel', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getProfilesInChannel( - TestHelper.basicChannel().id, - 0, - 100, - function(data) { - expect(Object.keys(data).length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getProfilesNotInChannel', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().getProfilesNotInChannel( - TestHelper.basicChannel().id, - 0, - 100, - function(data) { - expect(Object.keys(data).length).not.toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('searchUsers', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().searchUsers( - 'uid', - TestHelper.basicTeam().id, - {}, - function(data) { - expect(data.length).toBeGreaterThan(0); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('autocompleteUsersInChannel', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().autocompleteUsersInChannel( - 'uid', - TestHelper.basicChannel().id, - function(data) { - expect(data).not.toBeNull(); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('autocompleteUsersInTeam', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().autocompleteUsersInTeam( - 'uid', - function(data) { - expect(data).not.toBeNull(); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('autocompleteUsers', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().autocompleteUsers( - 'uid', - function(data) { - expect(data).not.toBeNull(); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('getStatusesByIds', function(done) { - TestHelper.initBasic(done, () => { - var ids = []; - ids.push(TestHelper.basicUser().id); - - TestHelper.basicClient().getStatusesByIds( - ids, - function(data) { - expect(data[TestHelper.basicUser().id]).not.toBeNull(); - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('verifyEmail', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().verifyEmail( - 'junk', - function() { - done.fail(new Error('should be invalid')); - }, - function(err) { - expect(err.id).toBe('api.context.invalid_body_param.app_error'); - done(); - } - ); - }); - }); - - test('resendVerification', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().resendVerification( - TestHelper.basicUser().email, - function() { - done(); - }, - function(err) { - done.fail(new Error(err.message)); - } - ); - }); - }); - - test('updateMfa', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicClient().enableLogErrorsToConsole(false); // Disabling since this unit test causes an error - TestHelper.basicClient().updateMfa( - 'junk', - true, - function() { - done.fail(new Error('not enabled')); - }, - function() { - done(); - } - ); - }); - }); -}); diff --git a/webapp/tests/client/client_websocket.test.jsx b/webapp/tests/client/client_websocket.test.jsx deleted file mode 100644 index c5b60011e..000000000 --- a/webapp/tests/client/client_websocket.test.jsx +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import TestHelper from 'tests/helpers/client-test-helper.jsx'; - -describe.skip('Client.WebSocket', function() { - test('WebSocket.getStatusesByIds', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicWebSocketClient().getStatusesByIds( - [TestHelper.basicUser().id], - function(resp) { - TestHelper.basicWebSocketClient().close(); - expect(resp.data[TestHelper.basicUser().id]).toBe('online'); - done(); - } - ); - }, true); - }); - - test('WebSocket.getStatuses', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicWebSocketClient().getStatuses( - function(resp) { - TestHelper.basicWebSocketClient().close(); - expect(resp.data).not.toBe(null); - done(); - } - ); - }, true); - }); - - test('WebSocket.userTyping', function(done) { - TestHelper.initBasic(done, () => { - TestHelper.basicWebSocketClient().userTyping( - TestHelper.basicChannel().id, - '', - function(resp) { - TestHelper.basicWebSocketClient().close(); - expect(resp.status).toBe('OK'); - done(); - } - ); - }, true); - }); -}); - diff --git a/webapp/utils/async_client.jsx b/webapp/utils/async_client.jsx deleted file mode 100644 index 820199339..000000000 --- a/webapp/utils/async_client.jsx +++ /dev/null @@ -1,889 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import UserStore from 'stores/user_store.jsx'; -import TeamStore from 'stores/team_store.jsx'; - -import * as GlobalActions from 'actions/global_actions.jsx'; - -import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; -import Client from 'client/web_client.jsx'; -import * as utils from 'utils/utils.jsx'; -import * as UserAgent from 'utils/user_agent.jsx'; - -import Constants from 'utils/constants.jsx'; -const ActionTypes = Constants.ActionTypes; -const StatTypes = Constants.StatTypes; - -// Used to track in progress async calls -const callTracker = {}; - -const ASYNC_CLIENT_TIMEOUT = 5000; - -// Redux actions -import store from 'stores/redux_store.jsx'; -const dispatch = store.dispatch; -const getState = store.getState; -import {setServerVersion} from 'mattermost-redux/actions/general'; - -export function dispatchError(err, method) { - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_ERROR, - err, - method - }); -} - -function isCallInProgress(callName) { - if (!(callName in callTracker)) { - return false; - } - - if (callTracker[callName] === 0) { - return false; - } - - if (utils.getTimestamp() - callTracker[callName] > ASYNC_CLIENT_TIMEOUT) { - //console.log('AsyncClient call ' + callName + ' expired after more than 5 seconds'); - return false; - } - - return true; -} - -export function checkVersion() { - setServerVersion(Client.getServerVersion())(dispatch, getState); -} - -export function getUser(userId, success, error) { - const callName = `getUser${userId}`; - - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - Client.getUser( - userId, - (data) => { - callTracker[callName] = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_PROFILE, - profile: data - }); - - if (success) { - success(data); - } - }, - (err) => { - if (error) { - error(err); - } else { - callTracker[callName] = 0; - dispatchError(err, 'getUser'); - } - } - ); -} - -export function getLogs() { - if (isCallInProgress('getLogs')) { - return; - } - - callTracker.getLogs = utils.getTimestamp(); - Client.getLogs( - (data) => { - callTracker.getLogs = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_LOGS, - logs: data - }); - }, - (err) => { - callTracker.getLogs = 0; - dispatchError(err, 'getLogs'); - } - ); -} - -export function getServerAudits() { - if (isCallInProgress('getServerAudits')) { - return; - } - - callTracker.getServerAudits = utils.getTimestamp(); - Client.getServerAudits( - (data) => { - callTracker.getServerAudits = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_SERVER_AUDITS, - audits: data - }); - }, - (err) => { - callTracker.getServerAudits = 0; - dispatchError(err, 'getServerAudits'); - } - ); -} - -export function getComplianceReports() { - if (isCallInProgress('getComplianceReports')) { - return; - } - - callTracker.getComplianceReports = utils.getTimestamp(); - Client.getComplianceReports( - (data) => { - callTracker.getComplianceReports = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_SERVER_COMPLIANCE_REPORTS, - complianceReports: data - }); - }, - (err) => { - callTracker.getComplianceReports = 0; - dispatchError(err, 'getComplianceReports'); - } - ); -} - -export function getConfig(success, error) { - if (isCallInProgress('getConfig')) { - return; - } - - callTracker.getConfig = utils.getTimestamp(); - Client.getConfig( - (data) => { - callTracker.getConfig = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_CONFIG, - config: data, - clusterId: Client.clusterId - }); - - if (success) { - success(data); - } - }, - (err) => { - callTracker.getConfig = 0; - - if (!error) { - dispatchError(err, 'getConfig'); - } - } - ); -} - -export function search(terms, isOrSearch) { - if (isCallInProgress('search_' + String(terms))) { - return; - } - - callTracker['search_' + String(terms)] = utils.getTimestamp(); - Client.search( - terms, - isOrSearch, - (data) => { - callTracker['search_' + String(terms)] = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_SEARCH, - results: data - }); - }, - (err) => { - callTracker['search_' + String(terms)] = 0; - dispatchError(err, 'search'); - } - ); -} - -export function getFileInfosForPost(channelId, postId) { - const callName = 'getFileInfosForPost' + postId; - - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - Client.getFileInfosForPost( - channelId, - postId, - (data) => { - callTracker[callName] = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_FILE_INFOS, - postId, - infos: data - }); - }, - (err) => { - callTracker[callName] = 0; - dispatchError(err, 'getPostFile'); - } - ); -} - -export function getMe() { - if (isCallInProgress('getMe')) { - return null; - } - - callTracker.getMe = utils.getTimestamp(); - return Client.getMe( - (data) => { - callTracker.getMe = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_ME, - me: data - }); - - GlobalActions.newLocalizationSelected(data.locale); - }, - (err) => { - callTracker.getMe = 0; - dispatchError(err, 'getMe'); - } - ); -} - -export function getStatuses() { - if (isCallInProgress('getStatuses')) { - return; - } - - callTracker.getStatuses = utils.getTimestamp(); - Client.getStatuses( - (data) => { - callTracker.getStatuses = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_STATUSES, - statuses: data - }); - }, - (err) => { - callTracker.getStatuses = 0; - dispatchError(err, 'getStatuses'); - } - ); -} - -export function getMyTeamsUnread(teamId) { - const members = TeamStore.getMyTeamMembers(); - if (members.length > 1) { - const callName = 'getMyTeamsUnread'; - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - Client.getMyTeamsUnread( - teamId, - (data) => { - callTracker[callName] = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_MY_TEAMS_UNREAD, - team_members: data - }); - }, - (err) => { - callTracker[callName] = 0; - dispatchError(err, 'getMyTeamsUnread'); - } - ); - } -} - -export function getAllPreferences() { - if (isCallInProgress('getAllPreferences')) { - return; - } - - callTracker.getAllPreferences = utils.getTimestamp(); - Client.getAllPreferences( - (data) => { - callTracker.getAllPreferences = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_PREFERENCES, - preferences: data - }); - }, - (err) => { - callTracker.getAllPreferences = 0; - dispatchError(err, 'getAllPreferences'); - } - ); -} - -export function savePreference(category, name, value, success, error) { - const preference = { - user_id: UserStore.getCurrentId(), - category, - name, - value - }; - - savePreferences([preference], success, error); -} - -export function savePreferences(preferences, success, error) { - Client.savePreferences( - preferences, - (data) => { - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_PREFERENCES, - preferences - }); - - if (success) { - success(data); - } - }, - (err) => { - dispatchError(err, 'savePreferences'); - - if (error) { - error(); - } - } - ); -} - -export function deletePreferences(preferences, success, error) { - Client.deletePreferences( - preferences, - (data) => { - AppDispatcher.handleServerAction({ - type: ActionTypes.DELETED_PREFERENCES, - preferences - }); - - if (success) { - success(data); - } - }, - (err) => { - dispatchError(err, 'deletePreferences'); - - if (error) { - error(); - } - } - ); -} - -export function getSuggestedCommands(command, suggestionId, component) { - Client.listCommands( - (data) => { - var matches = []; - data.forEach((cmd) => { - if (cmd.trigger !== 'shortcuts' || !UserAgent.isMobile()) { - if (('/' + cmd.trigger).indexOf(command) === 0) { - const s = '/' + cmd.trigger; - let hint = ''; - if (cmd.auto_complete_hint && cmd.auto_complete_hint.length !== 0) { - hint = cmd.auto_complete_hint; - } - matches.push({ - suggestion: s, - hint, - description: cmd.auto_complete_desc - }); - } - } - }); - - matches = matches.sort((a, b) => a.suggestion.localeCompare(b.suggestion)); - - // pull out the suggested commands from the returned data - const terms = matches.map((suggestion) => suggestion.suggestion); - - if (terms.length > 0) { - AppDispatcher.handleServerAction({ - type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS, - id: suggestionId, - matchedPretext: command, - terms, - items: matches, - component - }); - } - }, - (err) => { - dispatchError(err, 'getSuggestedCommands'); - } - ); -} - -export function getStandardAnalytics(teamId) { - const callName = 'getStandardAnaytics' + teamId; - - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - - Client.getAnalytics( - 'standard', - teamId, - (data) => { - callTracker[callName] = 0; - - const stats = {}; - - for (const index in data) { - if (data[index].name === 'channel_open_count') { - stats[StatTypes.TOTAL_PUBLIC_CHANNELS] = data[index].value; - } - - if (data[index].name === 'channel_private_count') { - stats[StatTypes.TOTAL_PRIVATE_GROUPS] = data[index].value; - } - - if (data[index].name === 'post_count') { - stats[StatTypes.TOTAL_POSTS] = data[index].value; - } - - if (data[index].name === 'unique_user_count') { - stats[StatTypes.TOTAL_USERS] = data[index].value; - } - - if (data[index].name === 'team_count' && teamId == null) { - stats[StatTypes.TOTAL_TEAMS] = data[index].value; - } - - if (data[index].name === 'total_websocket_connections') { - stats[StatTypes.TOTAL_WEBSOCKET_CONNECTIONS] = data[index].value; - } - - if (data[index].name === 'total_master_db_connections') { - stats[StatTypes.TOTAL_MASTER_DB_CONNECTIONS] = data[index].value; - } - - if (data[index].name === 'total_read_db_connections') { - stats[StatTypes.TOTAL_READ_DB_CONNECTIONS] = data[index].value; - } - - if (data[index].name === 'daily_active_users') { - stats[StatTypes.DAILY_ACTIVE_USERS] = data[index].value; - } - - if (data[index].name === 'monthly_active_users') { - stats[StatTypes.MONTHLY_ACTIVE_USERS] = data[index].value; - } - } - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_ANALYTICS, - teamId, - stats - }); - }, - (err) => { - callTracker[callName] = 0; - - dispatchError(err, 'getStandardAnalytics'); - } - ); -} - -export function getAdvancedAnalytics(teamId) { - const callName = 'getAdvancedAnalytics' + teamId; - - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - - Client.getAnalytics( - 'extra_counts', - teamId, - (data) => { - callTracker[callName] = 0; - - const stats = {}; - - for (const index in data) { - if (data[index].name === 'file_post_count') { - stats[StatTypes.TOTAL_FILE_POSTS] = data[index].value; - } - - if (data[index].name === 'hashtag_post_count') { - stats[StatTypes.TOTAL_HASHTAG_POSTS] = data[index].value; - } - - if (data[index].name === 'incoming_webhook_count') { - stats[StatTypes.TOTAL_IHOOKS] = data[index].value; - } - - if (data[index].name === 'outgoing_webhook_count') { - stats[StatTypes.TOTAL_OHOOKS] = data[index].value; - } - - if (data[index].name === 'command_count') { - stats[StatTypes.TOTAL_COMMANDS] = data[index].value; - } - - if (data[index].name === 'session_count') { - stats[StatTypes.TOTAL_SESSIONS] = data[index].value; - } - } - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_ANALYTICS, - teamId, - stats - }); - }, - (err) => { - callTracker[callName] = 0; - - dispatchError(err, 'getAdvancedAnalytics'); - } - ); -} - -export function getPostsPerDayAnalytics(teamId) { - const callName = 'getPostsPerDayAnalytics' + teamId; - - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - - Client.getAnalytics( - 'post_counts_day', - teamId, - (data) => { - callTracker[callName] = 0; - - data.reverse(); - - const stats = {}; - stats[StatTypes.POST_PER_DAY] = data; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_ANALYTICS, - teamId, - stats - }); - }, - (err) => { - callTracker[callName] = 0; - - dispatchError(err, 'getPostsPerDayAnalytics'); - } - ); -} - -export function getUsersPerDayAnalytics(teamId) { - const callName = 'getUsersPerDayAnalytics' + teamId; - - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - - Client.getAnalytics( - 'user_counts_with_posts_day', - teamId, - (data) => { - callTracker[callName] = 0; - - data.reverse(); - - const stats = {}; - stats[StatTypes.USERS_WITH_POSTS_PER_DAY] = data; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_ANALYTICS, - teamId, - stats - }); - }, - (err) => { - callTracker[callName] = 0; - - dispatchError(err, 'getUsersPerDayAnalytics'); - } - ); -} - -export function getRecentAndNewUsersAnalytics(teamId) { - const callName = 'getRecentAndNewUsersAnalytics' + teamId; - - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - - Client.getRecentlyActiveUsers( - teamId, - (users) => { - const stats = {}; - - const usersList = []; - for (const id in users) { - if (users.hasOwnProperty(id)) { - usersList.push(users[id]); - } - } - - usersList.sort((a, b) => { - if (a.last_activity_at < b.last_activity_at) { - return 1; - } - - if (a.last_activity_at > b.last_activity_at) { - return -1; - } - - return 0; - }); - - const recentActive = []; - for (let i = 0; i < usersList.length; i++) { - if (usersList[i].last_activity_at == null) { - continue; - } - - recentActive.push(usersList[i]); - if (i >= Constants.STAT_MAX_ACTIVE_USERS) { - break; - } - } - - stats[StatTypes.RECENTLY_ACTIVE_USERS] = recentActive; - - usersList.sort((a, b) => { - if (a.create_at < b.create_at) { - return 1; - } - - if (a.create_at > b.create_at) { - return -1; - } - - return 0; - }); - - var newlyCreated = []; - for (let i = 0; i < usersList.length; i++) { - newlyCreated.push(usersList[i]); - if (i >= Constants.STAT_MAX_NEW_USERS) { - break; - } - } - - stats[StatTypes.NEWLY_CREATED_USERS] = newlyCreated; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_ANALYTICS, - teamId, - stats - }); - callTracker[callName] = 0; - }, - (err) => { - callTracker[callName] = 0; - - dispatchError(err, 'getRecentAndNewUsersAnalytics'); - } - ); -} - -export function getPublicLink(fileId, success, error) { - const callName = 'getPublicLink' + fileId; - - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - - Client.getPublicLink( - fileId, - (link) => { - callTracker[callName] = 0; - - success(link); - }, - (err) => { - callTracker[callName] = 0; - - if (error) { - error(err); - } else { - dispatchError(err, 'getPublicLink'); - } - } - ); -} - -export function addEmoji(emoji, image, success, error) { - const callName = 'addEmoji' + emoji.name; - - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - - Client.addEmoji( - emoji, - image, - (data) => { - callTracker[callName] = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_CUSTOM_EMOJI, - emoji: data - }); - - if (success) { - success(); - } - }, - (err) => { - callTracker[callName] = 0; - - if (error) { - error(err); - } else { - dispatchError(err, 'addEmoji'); - } - } - ); -} - -export function deleteEmoji(id) { - const callName = 'deleteEmoji' + id; - - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - - Client.deleteEmoji( - id, - () => { - callTracker[callName] = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.REMOVED_CUSTOM_EMOJI, - id - }); - }, - (err) => { - callTracker[callName] = 0; - dispatchError(err, 'deleteEmoji'); - } - ); -} - -export function pinPost(channelId, reaction) { - Client.pinPost( - channelId, - reaction, - () => { - // the "post_edited" websocket event take cares of updating the posts - // the action below is mostly dispatched for the RHS to update - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_POST_PINNED, - reaction - }); - }, - (err) => { - dispatchError(err, 'pinPost'); - } - ); -} - -export function unpinPost(channelId, reaction) { - Client.unpinPost( - channelId, - reaction, - () => { - // the "post_edited" websocket event take cares of updating the posts - // the action below is mostly dispatched for the RHS to update - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_POST_UNPINNED, - reaction - }); - }, - (err) => { - dispatchError(err, 'unpinPost'); - } - ); -} - -export function saveReaction(channelId, reaction) { - Client.saveReaction( - channelId, - reaction, - null, // the added reaction will be sent over the websocket - (err) => { - dispatchError(err, 'saveReaction'); - } - ); -} - -export function deleteReaction(channelId, reaction) { - Client.deleteReaction( - channelId, - reaction, - null, // the removed reaction will be sent over the websocket - (err) => { - dispatchError(err, 'deleteReaction'); - } - ); -} - -export function listReactions(channelId, postId) { - const callName = 'deleteEmoji' + postId; - - if (isCallInProgress(callName)) { - return; - } - - callTracker[callName] = utils.getTimestamp(); - - Client.listReactions( - channelId, - postId, - (data) => { - callTracker[callName] = 0; - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_REACTIONS, - postId, - reactions: data - }); - }, - (err) => { - callTracker[callName] = 0; - dispatchError(err, 'listReactions'); - } - ); -} diff --git a/webapp/utils/channel_intro_messages.jsx b/webapp/utils/channel_intro_messages.jsx index 31ba8708d..c874bfc73 100644 --- a/webapp/utils/channel_intro_messages.jsx +++ b/webapp/utils/channel_intro_messages.jsx @@ -11,9 +11,10 @@ import UserStore from 'stores/user_store.jsx'; import TeamStore from 'stores/team_store.jsx'; import Constants from 'utils/constants.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; -import Client from 'client/web_client.jsx'; import ProfilePicture from 'components/profile_picture.jsx'; +import {Client4} from 'mattermost-redux/client'; + import {showManagementOptions} from './channel_utils.jsx'; import React from 'react'; @@ -51,7 +52,7 @@ export function createGMIntroMessage(channel, centeredIntro) { pictures.push(