diff options
Diffstat (limited to 'webapp/actions')
-rw-r--r-- | webapp/actions/admin_actions.jsx | 51 | ||||
-rw-r--r-- | webapp/actions/channel_actions.jsx | 121 | ||||
-rw-r--r-- | webapp/actions/diagnostics_actions.jsx | 22 | ||||
-rw-r--r-- | webapp/actions/emoji_actions.jsx | 53 | ||||
-rw-r--r-- | webapp/actions/file_actions.jsx | 13 | ||||
-rw-r--r-- | webapp/actions/global_actions.jsx | 101 | ||||
-rw-r--r-- | webapp/actions/integration_actions.jsx | 68 | ||||
-rw-r--r-- | webapp/actions/post_actions.jsx | 86 | ||||
-rw-r--r-- | webapp/actions/team_actions.jsx | 49 | ||||
-rw-r--r-- | webapp/actions/user_actions.jsx | 43 | ||||
-rw-r--r-- | webapp/actions/webrtc_actions.jsx | 10 | ||||
-rw-r--r-- | webapp/actions/websocket_actions.jsx | 66 |
12 files changed, 353 insertions, 330 deletions
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: {<url>: 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 }); } |