summaryrefslogtreecommitdiffstats
path: root/webapp/actions
diff options
context:
space:
mode:
Diffstat (limited to 'webapp/actions')
-rw-r--r--webapp/actions/admin_actions.jsx397
-rw-r--r--webapp/actions/channel_actions.jsx413
-rw-r--r--webapp/actions/diagnostics_actions.jsx24
-rw-r--r--webapp/actions/emoji_actions.jsx72
-rw-r--r--webapp/actions/file_actions.jsx93
-rw-r--r--webapp/actions/global_actions.jsx626
-rw-r--r--webapp/actions/integration_actions.jsx301
-rw-r--r--webapp/actions/job_actions.jsx34
-rw-r--r--webapp/actions/notification_actions.jsx132
-rw-r--r--webapp/actions/oauth_actions.jsx21
-rw-r--r--webapp/actions/post_actions.jsx357
-rw-r--r--webapp/actions/status_actions.jsx128
-rw-r--r--webapp/actions/team_actions.jsx200
-rw-r--r--webapp/actions/user_actions.jsx839
-rw-r--r--webapp/actions/webrtc_actions.jsx38
-rw-r--r--webapp/actions/websocket_actions.jsx473
16 files changed, 0 insertions, 4148 deletions
diff --git a/webapp/actions/admin_actions.jsx b/webapp/actions/admin_actions.jsx
deleted file mode 100644
index 4dd0f848f..000000000
--- a/webapp/actions/admin_actions.jsx
+++ /dev/null
@@ -1,397 +0,0 @@
-// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import {clientLogout} from 'actions/global_actions.jsx';
-
-import store from 'stores/redux_store.jsx';
-const dispatch = store.dispatch;
-const getState = store.getState;
-
-import * as AdminActions from 'mattermost-redux/actions/admin';
-import * as UserActions from 'mattermost-redux/actions/users';
-import {Client4} from 'mattermost-redux/client';
-
-export function saveConfig(config, success, error) {
- AdminActions.updateConfig(config)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.updateConfig.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function reloadConfig(success, error) {
- AdminActions.reloadConfig()(dispatch, getState).then(
- (data) => {
- if (data && success) {
- AdminActions.getConfig()(dispatch, getState);
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.reloadConfig.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function adminResetMfa(userId, success, error) {
- UserActions.updateUserMfa(userId, false)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.updateUser.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function getClusterStatus(success, error) {
- AdminActions.getClusterStatus()(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.getClusterStatus.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function testEmail(config, success, error) {
- AdminActions.testEmail(config)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.testEmail.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function ldapTest(success, error) {
- AdminActions.testLdap()(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.testLdap.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function invalidateAllCaches(success, error) {
- AdminActions.invalidateCaches()(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.invalidateCaches.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function recycleDatabaseConnection(success, error) {
- AdminActions.recycleDatabase()(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.recycleDatabase.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function adminResetPassword(userId, password, success, error) {
- UserActions.updateUserPassword(userId, '', password)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.updateUser.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function samlCertificateStatus(success, error) {
- AdminActions.getSamlCertificateStatus()(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.getSamlCertificateStatus.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function ldapSyncNow(success, error) {
- AdminActions.syncLdap()(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.syncLdap.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function getOAuthAppInfo(clientId, success, error) {
- Client4.getOAuthAppInfo(clientId).then(
- (data) => {
- if (success) {
- success(data);
- }
- }
- ).catch(
- (err) => {
- if (error) {
- error(err);
- }
- }
- );
-}
-
-export function allowOAuth2(params, success, error) {
- const responseType = params.response_type;
- const clientId = params.client_id;
- const redirectUri = params.redirect_uri;
- const state = params.state;
- const scope = params.scope;
-
- Client4.authorizeOAuthApp(responseType, clientId, redirectUri, state, scope).then(
- (data) => {
- if (success) {
- success(data);
- }
- }
- ).catch(
- (err) => {
- if (error) {
- error(err);
- }
- }
- );
-}
-
-export function emailToLdap(loginId, password, token, ldapId, ldapPassword, success, error) {
- UserActions.switchEmailToLdap(loginId, password, ldapId, ldapPassword, token)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.switchLogin.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function emailToOAuth(loginId, password, token, newType, success, error) {
- UserActions.switchEmailToOAuth(newType, loginId, password, token)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.switchLogin.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function oauthToEmail(currentService, email, password, success, error) {
- UserActions.switchOAuthToEmail(currentService, email, password)(dispatch, getState).then(
- (data) => {
- if (data) {
- if (data.follow_link) {
- clientLogout(data.follow_link);
- }
- if (success) {
- success(data);
- }
- } else if (data == null && error) {
- const serverError = getState().requests.users.switchLogin.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function uploadBrandImage(brandImage, success, error) {
- AdminActions.uploadBrandImage(brandImage)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.uploadBrandImage.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function uploadLicenseFile(file, success, error) {
- 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) {
- 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});
- }
- }
- );
-}
-
-export function uploadPublicSamlCertificate(file, success, error) {
- AdminActions.uploadPublicSamlCertificate(file)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.uploadPublicSamlCertificate.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function uploadPrivateSamlCertificate(file, success, error) {
- AdminActions.uploadPrivateSamlCertificate(file)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.uploadPrivateSamlCertificate.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function uploadIdpSamlCertificate(file, success, error) {
- AdminActions.uploadIdpSamlCertificate(file)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.uploadIdpSamlCertificate.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function removePublicSamlCertificate(success, error) {
- AdminActions.removePublicSamlCertificate()(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.removePublicSamlCertificate.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function removePrivateSamlCertificate(success, error) {
- AdminActions.removePrivateSamlCertificate()(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.removePrivateSamlCertificate.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function removeIdpSamlCertificate(success, error) {
- AdminActions.removeIdpSamlCertificate()(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.removeIdpSamlCertificate.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-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);
-}
-
-export function elasticsearchTest(config, success, error) {
- AdminActions.testElasticsearch(config)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.testElasticsearch.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function elasticsearchPurgeIndexes(success, error) {
- AdminActions.purgeElasticsearchIndexes()(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.admin.purgeElasticsearchIndexes.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx
deleted file mode 100644
index 1df0d12f5..000000000
--- a/webapp/actions/channel_actions.jsx
+++ /dev/null
@@ -1,413 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import TeamStore from 'stores/team_store.jsx';
-import UserStore from 'stores/user_store.jsx';
-import ChannelStore from 'stores/channel_store.jsx';
-import * as ChannelUtils from 'utils/channel_utils.jsx';
-import PreferenceStore from 'stores/preference_store.jsx';
-
-import * as GlobalActions from 'actions/global_actions.jsx';
-import * as PostActions from 'actions/post_actions.jsx';
-
-import {loadProfilesForSidebar, loadNewDMIfNeeded, loadNewGMIfNeeded} from 'actions/user_actions.jsx';
-import {trackEvent} from 'actions/diagnostics_actions.jsx';
-
-import * as UserAgent from 'utils/user_agent.jsx';
-import * as Utils from 'utils/utils.jsx';
-import {Constants, Preferences} from 'utils/constants.jsx';
-
-import {browserHistory} from 'react-router/es6';
-
-import store from 'stores/redux_store.jsx';
-const dispatch = store.dispatch;
-const getState = store.getState;
-
-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';
-
-export function goToChannel(channel) {
- if (channel.fake) {
- const user = UserStore.getProfileByUsername(channel.display_name);
- if (!user) {
- return;
- }
- openDirectChannelToUser(
- user.id,
- () => {
- browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + channel.name);
- },
- null
- );
- } else {
- browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + channel.name);
- }
-}
-
-export function executeCommand(message, args, success, error) {
- let msg = message;
-
- let cmdLength = msg.indexOf(' ');
- if (cmdLength < 0) {
- cmdLength = msg.length;
- }
- const cmd = msg.substring(0, cmdLength).toLowerCase();
- msg = cmd + msg.substring(cmdLength, msg.length);
-
- switch (cmd) {
- case '/search':
- PostActions.searchForTerm(msg.substring(cmdLength + 1, msg.length));
- return;
- case '/shortcuts':
- if (UserAgent.isMobile()) {
- const err = {message: Utils.localizeMessage('create_post.shortcutsNotSupported', 'Keyboard shortcuts are not supported on your device')};
- error(err);
- return;
- }
-
- GlobalActions.showShortcutsModal();
- return;
- case '/leave': {
- // /leave command not supported in reply threads.
- if (args.channel_id && (args.root_id || args.parent_id)) {
- GlobalActions.sendEphemeralPost('/leave is not supported in reply threads. Use it in the center channel instead.', args.channel_id, args.parent_id);
- return;
- }
- const channel = ChannelStore.getCurrent();
- if (channel.type === Constants.PRIVATE_CHANNEL) {
- GlobalActions.showLeavePrivateChannelModal(channel);
- return;
- } else if (
- channel.type === Constants.DM_CHANNEL ||
- channel.type === Constants.GM_CHANNEL
- ) {
- let name;
- let category;
- if (channel.type === Constants.DM_CHANNEL) {
- name = Utils.getUserIdFromChannelName(channel);
- category = Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW;
- } else {
- name = channel.id;
- category = Constants.Preferences.CATEGORY_GROUP_CHANNEL_SHOW;
- }
- const currentUserId = UserStore.getCurrentId();
- savePreferences(currentUserId, [{category, name, user_id: currentUserId, value: 'false'}])(dispatch, getState);
- if (ChannelUtils.isFavoriteChannel(channel)) {
- unmarkFavorite(channel.id);
- }
- browserHistory.push(`${TeamStore.getCurrentTeamRelativeUrl()}/channels/town-square`);
- return;
- }
- break;
- }
- case '/settings':
- GlobalActions.showAccountSettingsModal();
- return;
- }
-
- Client4.executeCommand(msg, args).then(success).catch(
- (err) => {
- if (error) {
- error(err);
- }
- }
- );
-}
-
-export function setChannelAsRead(channelIdParam) {
- const channelId = channelIdParam || ChannelStore.getCurrentId();
- ChannelActions.viewChannel(channelId)(dispatch, getState);
- ChannelStore.resetCounts([channelId]);
- ChannelStore.emitChange();
- if (channelId === ChannelStore.getCurrentId()) {
- ChannelStore.emitLastViewed(Number.MAX_VALUE, false);
- }
-}
-
-export function addUserToChannel(channelId, userId, success, error) {
- ChannelActions.addChannelMember(channelId, userId)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.channels.addChannelMember.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function removeUserFromChannel(channelId, userId, success, error) {
- ChannelActions.removeChannelMember(channelId, userId)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.channels.removeChannelMember.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function makeUserChannelAdmin(channelId, userId, success, error) {
- ChannelActions.updateChannelMemberRoles(channelId, userId, 'channel_user channel_admin')(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.channels.updateChannelMember.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function makeUserChannelMember(channelId, userId, success, error) {
- ChannelActions.updateChannelMemberRoles(channelId, userId, 'channel_user')(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.channels.updateChannelMember.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function openDirectChannelToUser(userId, success, error) {
- const channelName = Utils.getDirectChannelName(UserStore.getCurrentId(), userId);
- const channel = ChannelStore.getByName(channelName);
-
- if (channel) {
- trackEvent('api', 'api_channels_join_direct');
- PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'true');
- loadProfilesForSidebar();
-
- 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);
- }
-
- return;
- }
-
- ChannelActions.createDirectChannel(UserStore.getCurrentId(), userId)(dispatch, getState).then(
- (result) => {
- loadProfilesForSidebar();
- if (result.data && success) {
- success(result.data, false);
- } else if (result.error && error) {
- error({id: result.error.server_error_id, ...result.error});
- }
- }
- );
-}
-
-export function openGroupChannelToUsers(userIds, success, error) {
- ChannelActions.createGroupChannel(userIds)(dispatch, getState).then(
- (result) => {
- loadProfilesForSidebar();
- if (result.data && success) {
- success(result.data, false);
- } else if (result.error && error) {
- browserHistory.push(TeamStore.getCurrentTeamUrl());
- error({id: result.error.server_error_id, ...result.error});
- }
- }
- );
-}
-
-export function markFavorite(channelId) {
- trackEvent('api', 'api_channels_favorited');
- 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: currentUserId,
- category: Preferences.CATEGORY_FAVORITE_CHANNEL,
- name: channelId
- };
-
- deletePreferences(currentUserId, [pref])(dispatch, getState);
-}
-
-export function loadChannelsForCurrentUser() {
- ChannelActions.fetchMyChannelsAndMembers(TeamStore.getCurrentId())(dispatch, getState).then(
- () => {
- loadDMsAndGMsForUnreads();
- }
- );
-}
-
-export function loadDMsAndGMsForUnreads() {
- const unreads = ChannelStore.getUnreadCounts();
- for (const id in unreads) {
- if (!unreads.hasOwnProperty(id)) {
- continue;
- }
-
- if (unreads[id].msgs > 0 || unreads[id].mentions > 0) {
- const channel = ChannelStore.get(id);
- if (channel && channel.type === Constants.DM_CHANNEL) {
- loadNewDMIfNeeded(channel.id);
- } else if (channel && channel.type === Constants.GM_CHANNEL) {
- loadNewGMIfNeeded(channel.id);
- }
- }
- }
-}
-
-export async function joinChannel(channel, success, error) {
- const {data, serverError} = await ChannelActions.joinChannel(UserStore.getCurrentId(), null, channel.id)(dispatch, getState);
-
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- error({id: serverError.server_error_id, ...serverError});
- }
-}
-
-export function updateChannel(channel, success, error) {
- ChannelActions.updateChannel(channel)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.channels.updateChannel.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function searchMoreChannels(term, success, error) {
- ChannelActions.searchChannels(TeamStore.getCurrentId(), term)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- const myMembers = getMyChannelMemberships(getState());
- const channels = data.filter((c) => !myMembers[c.id]);
- success(channels);
- } else if (data == null && error) {
- const serverError = getState().requests.channels.getChannels.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function autocompleteChannels(term, success, error) {
- ChannelActions.searchChannels(TeamStore.getCurrentId(), term)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.channels.getChannels.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function updateChannelNotifyProps(data, options, success, error) {
- ChannelActions.updateChannelNotifyProps(data.user_id, data.channel_id, Object.assign({}, data, options))(dispatch, getState).then(
- (result) => {
- if (result && success) {
- success(result);
- } else if (result == null && error) {
- const serverError = getState().requests.channels.updateChannelNotifyProps.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function createChannel(channel, success, error) {
- ChannelActions.createChannel(channel)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.channels.createChannel.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function updateChannelPurpose(channelId, purpose, success, error) {
- ChannelActions.patchChannel(channelId, {purpose})(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.channels.updateChannel.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function updateChannelHeader(channelId, header, success, error) {
- ChannelActions.patchChannel(channelId, {header})(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.channels.updateChannel.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function getChannelMembersForUserIds(channelId, userIds, success, error) {
- ChannelActions.getChannelMembersByIds(channelId, userIds)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.channels.members.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function leaveChannel(channelId, success) {
- ChannelActions.leaveChannel(channelId)(dispatch, getState).then(
- () => {
- if (ChannelUtils.isFavoriteChannelId(channelId)) {
- unmarkFavorite(channelId);
- }
-
- const townsquare = ChannelStore.getByName('town-square');
- browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + townsquare.name);
-
- if (success) {
- success();
- }
- }
- );
-}
-
-export async function deleteChannel(channelId, success, error) {
- const {data, serverError} = await ChannelActions.deleteChannel(channelId)(dispatch, getState);
-
- if (data && success) {
- success(data);
- } else if (serverError && error) {
- error({id: serverError.server_error_id, ...serverError});
- }
-}
diff --git a/webapp/actions/diagnostics_actions.jsx b/webapp/actions/diagnostics_actions.jsx
deleted file mode 100644
index 72cf387b4..000000000
--- a/webapp/actions/diagnostics_actions.jsx
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import UserStore from 'stores/user_store.jsx';
-
-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
deleted file mode 100644
index 1c0d8b5ea..000000000
--- a/webapp/actions/emoji_actions.jsx
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-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 * as EmojiActions from 'mattermost-redux/actions/emojis';
-
-export async function loadEmoji(getProfiles = true) {
- const data = await EmojiActions.getAllCustomEmojis()(dispatch, getState);
-
- if (data && getProfiles) {
- loadProfilesForEmoji(data);
- }
-}
-
-function loadProfilesForEmoji(emojiList) {
- const profilesToLoad = {};
- for (let i = 0; i < emojiList.length; i++) {
- const emoji = emojiList[i];
- if (!UserStore.hasProfile(emoji.creator_id)) {
- profilesToLoad[emoji.creator_id] = true;
- }
- }
-
- const list = Object.keys(profilesToLoad);
- if (list.length === 0) {
- return;
- }
-
- 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
deleted file mode 100644
index 1d9617901..000000000
--- a/webapp/actions/file_actions.jsx
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import {batchActions} from 'redux-batched-actions';
-import request from 'superagent';
-
-import store from 'stores/redux_store.jsx';
-
-import * as Utils from 'utils/utils.jsx';
-
-import {FileTypes} from 'mattermost-redux/action_types';
-import {forceLogoutIfNecessary} from 'mattermost-redux/actions/helpers';
-import {getLogErrorAction} from 'mattermost-redux/actions/errors';
-import {Client4} from 'mattermost-redux/client';
-
-export function uploadFile(file, name, channelId, clientId, successCallback, errorCallback) {
- const {dispatch, getState} = store;
-
- function handleResponse(err, res) {
- if (err) {
- let e;
- if (res && res.body && res.body.id) {
- e = res.body;
- } else if (err.status === 0 || !err.status) {
- e = {message: Utils.localizeMessage('channel_loader.connection_error', 'There appears to be a problem with your internet connection.')};
- } else {
- e = {message: Utils.localizeMessage('channel_loader.unknown_error', 'We received an unexpected status code from the server.') + ' (' + err.status + ')'};
- }
-
- forceLogoutIfNecessary(err, dispatch);
-
- const failure = {
- type: FileTypes.UPLOAD_FILES_FAILURE,
- clientIds: [clientId],
- channelId,
- rootId: null,
- error: err
- };
-
- dispatch(batchActions([failure, getLogErrorAction(err)]), getState);
-
- if (errorCallback) {
- errorCallback(e, err, res);
- }
- } else if (res) {
- const data = res.body.file_infos.map((fileInfo, index) => {
- return {
- ...fileInfo,
- clientId: res.body.client_ids[index]
- };
- });
-
- dispatch(batchActions([
- {
- type: FileTypes.RECEIVED_UPLOAD_FILES,
- data,
- channelId,
- rootId: null
- },
- {
- type: FileTypes.UPLOAD_FILES_SUCCESS
- }
- ]), getState);
-
- if (successCallback) {
- successCallback(res.body, res);
- }
- }
- }
-
- dispatch({type: FileTypes.UPLOAD_FILES_REQUEST}, getState);
-
- return request.
- post(Client4.getFilesRoute()).
- set(Client4.getOptions().headers).
- attach('files', file, name).
- field('channel_id', channelId).
- field('client_ids', clientId).
- accept('application/json').
- end(handleResponse);
-}
-
-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
deleted file mode 100644
index 73a57e0b0..000000000
--- a/webapp/actions/global_actions.jsx
+++ /dev/null
@@ -1,626 +0,0 @@
-// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
-
-import ChannelStore from 'stores/channel_store.jsx';
-import UserStore from 'stores/user_store.jsx';
-import BrowserStore from 'stores/browser_store.jsx';
-import ErrorStore from 'stores/error_store.jsx';
-import TeamStore from 'stores/team_store.jsx';
-import SearchStore from 'stores/search_store.jsx';
-
-import {handleNewPost} from 'actions/post_actions.jsx';
-import {loadProfilesForSidebar, loadNewDMIfNeeded, loadNewGMIfNeeded} from 'actions/user_actions.jsx';
-import {loadChannelsForCurrentUser} from 'actions/channel_actions.jsx';
-import {stopPeriodicStatusUpdates} from 'actions/status_actions.jsx';
-import * as WebsocketActions from 'actions/websocket_actions.jsx';
-import {trackEvent} from 'actions/diagnostics_actions.jsx';
-
-import {ActionTypes, Constants, ErrorPageTypes} from 'utils/constants.jsx';
-import EventTypes from 'utils/event_types.jsx';
-
-import WebSocketClient from 'client/web_websocket_client.jsx';
-import {sortTeamsByDisplayName} from 'utils/team_utils.jsx';
-import * as Utils from 'utils/utils.jsx';
-
-import en from 'i18n/en.json';
-import * as I18n from 'i18n/i18n.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 {Client4} from 'mattermost-redux/client';
-
-import {removeUserFromTeam} from 'mattermost-redux/actions/teams';
-import {viewChannel, getChannelStats, getMyChannelMember, getChannelAndMyMember, createDirectChannel, joinChannel} 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);
- createDirectChannel(currentUserId, otherUserId)(dispatch, getState).then(
- (result) => {
- const receivedChannel = result.data;
-
- if (receivedChannel) {
- success(receivedChannel);
- } else {
- fail();
- }
- }
- );
- }
- function switchToChannel(chan) {
- const channelMember = ChannelStore.getMyMember(chan.id);
- const getMyChannelMemberPromise = getMyChannelMember(chan.id)(dispatch, getState);
- const oldChannelId = ChannelStore.getCurrentId();
-
- getMyChannelMemberPromise.then(() => {
- getChannelStats(chan.id)(dispatch, getState);
- viewChannel(chan.id, oldChannelId)(dispatch, getState);
-
- // Mark previous and next channel as read
- ChannelStore.resetCounts([chan.id, oldChannelId]);
- reloadIfServerVersionChanged();
- });
-
- // Subtract mentions for the team
- const {msgs, mentions} = ChannelStore.getUnreadCounts()[chan.id] || {msgs: 0, mentions: 0};
- TeamStore.subtractUnread(chan.team_id, msgs, mentions);
-
- BrowserStore.setGlobalItem(chan.team_id, chan.id);
-
- loadProfilesForSidebar();
-
- AppDispatcher.handleViewAction({
- type: ActionTypes.CLICK_CHANNEL,
- name: chan.name,
- id: chan.id,
- team_id: chan.team_id,
- total_msg_count: chan.total_msg_count,
- channelMember,
- prev: oldChannelId
- });
- }
-
- if (channel.fake) {
- userVisitedFakeChannel(
- channel,
- (data) => {
- switchToChannel(data);
- },
- () => {
- browserHistory.push('/' + this.state.currentTeam.name);
- }
- );
- } else {
- switchToChannel(channel);
- }
-}
-
-export async function doFocusPost(channelId, postId, data) {
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_FOCUSED_POST,
- postId,
- channelId,
- post_list: data
- });
-
- dispatch({
- type: ActionTypes.RECEIVED_FOCUSED_POST,
- data: postId,
- channelId
- });
-
- const member = getState().entities.channels.myMembers[channelId];
- if (member == null) {
- await joinChannel(UserStore.getCurrentId(), null, channelId)(dispatch, getState);
- }
-
- loadChannelsForCurrentUser();
- getChannelStats(channelId)(dispatch, getState);
-}
-
-export function emitPostFocusEvent(postId, onSuccess) {
- loadChannelsForCurrentUser();
- getPostThread(postId)(dispatch, getState).then(
- (data) => {
- if (data) {
- const channelId = data.posts[data.order[0]].channel_id;
- const channel = ChannelStore.getChannelById(channelId);
- if (channel && channel.type === Constants.DM_CHANNEL) {
- loadNewDMIfNeeded(channel.id);
- } else if (channel && channel.type === Constants.GM_CHANNEL) {
- loadNewGMIfNeeded(channel.id);
- }
-
- doFocusPost(channelId, postId, data).then(() => {
- if (onSuccess) {
- onSuccess();
- }
- });
- } else {
- browserHistory.push('/error?type=' + ErrorPageTypes.PERMALINK_NOT_FOUND);
- }
- }
- );
-}
-
-export function emitCloseRightHandSide() {
- SearchStore.storeSearchResults(null, false, false);
- SearchStore.emitSearchChange();
-
- dispatch({
- type: ActionTypes.SELECT_POST,
- postId: ''
- });
-}
-
-export function emitPostFocusRightHandSideFromSearch(post, isMentionSearch) {
- getPostThread(post.id)(dispatch, getState).then(
- () => {
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_POST_SELECTED,
- postId: Utils.getRootId(post),
- from_search: SearchStore.getSearchTerm(),
- from_flagged_posts: SearchStore.getIsFlaggedPosts(),
- from_pinned_posts: SearchStore.getIsPinnedPosts()
- });
-
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_SEARCH,
- results: null,
- is_mention_search: isMentionSearch
- });
- }
- );
-}
-
-export function emitLeaveTeam() {
- removeUserFromTeam(TeamStore.getCurrentId(), UserStore.getCurrentId())(dispatch, getState);
-}
-
-export function emitUserPostedEvent(post) {
- AppDispatcher.handleServerAction({
- type: ActionTypes.CREATE_POST,
- post
- });
-}
-
-export function emitUserCommentedEvent(post) {
- AppDispatcher.handleServerAction({
- type: ActionTypes.CREATE_COMMENT,
- post
- });
-}
-
-export function showAccountSettingsModal() {
- AppDispatcher.handleViewAction({
- type: ActionTypes.TOGGLE_ACCOUNT_SETTINGS_MODAL,
- value: true
- });
-}
-
-export function showShortcutsModal() {
- AppDispatcher.handleViewAction({
- type: ActionTypes.TOGGLE_SHORTCUTS_MODAL,
- value: true
- });
-}
-
-export function showDeletePostModal(post, commentCount = 0) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.TOGGLE_DELETE_POST_MODAL,
- value: true,
- post,
- commentCount
- });
-}
-
-export function showChannelHeaderUpdateModal(channel) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.TOGGLE_CHANNEL_HEADER_UPDATE_MODAL,
- value: true,
- channel
- });
-}
-
-export function showChannelPurposeUpdateModal(channel) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.TOGGLE_CHANNEL_PURPOSE_UPDATE_MODAL,
- value: true,
- channel
- });
-}
-
-export function showChannelNameUpdateModal(channel) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.TOGGLE_CHANNEL_NAME_UPDATE_MODAL,
- value: true,
- channel
- });
-}
-
-export function showGetPostLinkModal(post) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.TOGGLE_GET_POST_LINK_MODAL,
- value: true,
- post
- });
-}
-
-export function showGetPublicLinkModal(fileId) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.TOGGLE_GET_PUBLIC_LINK_MODAL,
- value: true,
- fileId
- });
-}
-
-export function showGetTeamInviteLinkModal() {
- AppDispatcher.handleViewAction({
- type: Constants.ActionTypes.TOGGLE_GET_TEAM_INVITE_LINK_MODAL,
- value: true
- });
-}
-
-export function showInviteMemberModal() {
- AppDispatcher.handleViewAction({
- type: ActionTypes.TOGGLE_INVITE_MEMBER_MODAL,
- value: true
- });
-}
-
-export function showLeaveTeamModal() {
- AppDispatcher.handleViewAction({
- type: ActionTypes.TOGGLE_LEAVE_TEAM_MODAL,
- value: true
- });
-}
-
-export function showLeavePrivateChannelModal(channel) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.TOGGLE_LEAVE_PRIVATE_CHANNEL_MODAL,
- value: channel
- });
-}
-
-export function emitSuggestionPretextChanged(suggestionId, pretext) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.SUGGESTION_PRETEXT_CHANGED,
- id: suggestionId,
- pretext
- });
-}
-
-export function emitSelectNextSuggestion(suggestionId) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.SUGGESTION_SELECT_NEXT,
- id: suggestionId
- });
-}
-
-export function emitSelectPreviousSuggestion(suggestionId) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.SUGGESTION_SELECT_PREVIOUS,
- id: suggestionId
- });
-}
-
-export function emitCompleteWordSuggestion(suggestionId, term = '') {
- AppDispatcher.handleViewAction({
- type: Constants.ActionTypes.SUGGESTION_COMPLETE_WORD,
- id: suggestionId,
- term
- });
-}
-
-export function emitClearSuggestions(suggestionId) {
- AppDispatcher.handleViewAction({
- type: Constants.ActionTypes.SUGGESTION_CLEAR_SUGGESTIONS,
- id: suggestionId
- });
-}
-
-export function emitPreferenceChangedEvent(preference) {
- AppDispatcher.handleServerAction({
- type: Constants.ActionTypes.RECEIVED_PREFERENCE,
- preference
- });
-
- if (addedNewDmUser(preference)) {
- loadProfilesForSidebar();
- }
-}
-
-export function emitPreferencesChangedEvent(preferences) {
- AppDispatcher.handleServerAction({
- type: Constants.ActionTypes.RECEIVED_PREFERENCES,
- preferences
- });
-
- if (preferences.findIndex(addedNewDmUser) !== -1) {
- loadProfilesForSidebar();
- }
-}
-
-function addedNewDmUser(preference) {
- return preference.category === Constants.Preferences.CATEGORY_DIRECT_CHANNEL_SHOW && preference.value === 'true';
-}
-
-export function emitPreferencesDeletedEvent(preferences) {
- AppDispatcher.handleServerAction({
- type: Constants.ActionTypes.DELETED_PREFERENCES,
- preferences
- });
-}
-
-export function sendEphemeralPost(message, channelId, parentId) {
- const timestamp = Utils.getTimestamp();
- const post = {
- id: Utils.generateId(),
- user_id: '0',
- channel_id: channelId || ChannelStore.getCurrentId(),
- message,
- type: Constants.PostTypes.EPHEMERAL,
- create_at: timestamp,
- update_at: timestamp,
- root_id: parentId,
- parent_id: parentId,
- props: {}
- };
-
- handleNewPost(post);
-}
-
-export function newLocalizationSelected(locale) {
- const localeInfo = I18n.getLanguageInfo(locale);
-
- if (locale === 'en' || !localeInfo) {
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_LOCALE,
- locale,
- translations: en
- });
- } else {
- Client4.getTranslations(localeInfo.url).then(
- (data, res) => {
- let translations = data;
- if (!data && res.text) {
- translations = JSON.parse(res.text);
- }
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_LOCALE,
- locale,
- translations
- });
- }
- ).catch(
- () => {} //eslint-disable-line no-empty-function
- );
- }
-}
-
-export function loadCurrentLocale() {
- const user = UserStore.getCurrentUser();
-
- if (user && user.locale) {
- newLocalizationSelected(user.locale);
- } else {
- loadDefaultLocale();
- }
-}
-
-export function loadDefaultLocale() {
- let locale = global.window.mm_config.DefaultClientLocale;
-
- if (!I18n.getLanguageInfo(locale)) {
- locale = 'en';
- }
-
- return newLocalizationSelected(locale);
-}
-
-let lastTimeTypingSent = 0;
-export function emitLocalUserTypingEvent(channelId, parentId) {
- const t = Date.now();
- const membersInChannel = ChannelStore.getStats(channelId).member_count;
-
- if (global.mm_license.IsLicensed === 'true' && global.mm_config.ExperimentalTownSquareIsReadOnly === 'true') {
- const channel = ChannelStore.getChannelById(channelId);
- if (channel && ChannelStore.isDefault(channel)) {
- return;
- }
- }
-
- if (((t - lastTimeTypingSent) > global.window.mm_config.TimeBetweenUserTypingUpdatesMilliseconds) && membersInChannel < global.window.mm_config.MaxNotificationsPerChannel && global.window.mm_config.EnableUserTypingMessages === 'true') {
- WebSocketClient.userTyping(channelId, parentId);
- lastTimeTypingSent = t;
- }
-}
-
-export function emitRemoteUserTypingEvent(channelId, userId, postParentId) {
- AppDispatcher.handleViewAction({
- type: Constants.ActionTypes.USER_TYPING,
- channelId,
- userId,
- postParentId
- });
-}
-
-export function emitUserLoggedOutEvent(redirectTo = '/', shouldSignalLogout = true) {
- Client4.logout().then(
- () => {
- if (shouldSignalLogout) {
- BrowserStore.signalLogout();
- }
-
- clientLogout(redirectTo);
- }
- ).catch(
- () => {
- browserHistory.push(redirectTo);
- }
- );
-}
-
-export function clientLogout(redirectTo = '/') {
- BrowserStore.clear();
- ErrorStore.clearLastError();
- ChannelStore.clear();
- stopPeriodicStatusUpdates();
- WebsocketActions.close();
- document.cookie = 'MMUSERID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
- window.location.href = redirectTo;
-}
-
-export function emitSearchMentionsEvent(user) {
- let terms = '';
- if (user.notify_props) {
- const termKeys = UserStore.getMentionKeys(user.id);
-
- if (termKeys.indexOf('@channel') !== -1) {
- termKeys[termKeys.indexOf('@channel')] = '';
- }
-
- if (termKeys.indexOf('@all') !== -1) {
- termKeys[termKeys.indexOf('@all')] = '';
- }
-
- terms = termKeys.join(' ');
- }
-
- trackEvent('api', 'api_posts_search_mention');
-
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_SEARCH_TERM,
- term: terms,
- do_search: true,
- is_mention_search: true
- });
-}
-
-export function toggleSideBarAction(visible) {
- if (!visible) {
- //Array of actions resolving in the closing of the sidebar
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_SEARCH,
- results: null
- });
-
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_SEARCH_TERM,
- term: null,
- do_search: false,
- is_mention_search: false
- });
-
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_POST_SELECTED,
- postId: null
- });
- }
-}
-
-export function toggleSideBarRightMenuAction() {
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_SEARCH,
- results: null
- });
-
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_POST_SELECTED,
- postId: null
- });
-
- document.querySelector('.app__body .inner-wrap').classList.remove('move--right', 'move--left', 'move--left-small');
- document.querySelector('.app__body .sidebar--left').classList.remove('move--right');
- document.querySelector('.app__body .sidebar--right').classList.remove('move--left');
- document.querySelector('.app__body .sidebar--menu').classList.remove('move--left');
-}
-
-export function emitBrowserFocus(focus) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.BROWSER_CHANGE_FOCUS,
- focus
- });
-}
-
-export function redirectUserToDefaultTeam() {
- const teams = TeamStore.getAll();
- const teamMembers = TeamStore.getMyTeamMembers();
- let teamId = BrowserStore.getGlobalItem('team');
-
- function redirect(teamName, channelName) {
- browserHistory.push(`/${teamName}/channels/${channelName}`);
- }
-
- if (!teams[teamId] && teamMembers.length > 0) {
- let myTeams = [];
- for (const index in teamMembers) {
- if (teamMembers.hasOwnProperty(index)) {
- const teamMember = teamMembers[index];
- myTeams.push(teams[teamMember.team_id]);
- }
- }
-
- if (myTeams.length > 0) {
- myTeams = myTeams.sort(sortTeamsByDisplayName);
- teamId = myTeams[0].id;
- }
- }
-
- if (teams[teamId]) {
- const channelId = BrowserStore.getGlobalItem(teamId);
- const channel = ChannelStore.getChannelById(channelId);
- if (channel) {
- redirect(teams[teamId].name, channel);
- } else if (channelId) {
- getChannelAndMyMember(channelId)(dispatch, getState).then(
- (data) => {
- if (data) {
- redirect(teams[teamId].name, data.channel.name);
- } else {
- redirect(teams[teamId].name, 'town-square');
- }
- }
- );
- } else {
- redirect(teams[teamId].name, 'town-square');
- }
- } else {
- browserHistory.push('/select_team');
- }
-}
-
-export function postListScrollChange(forceScrollToBottom = false) {
- AppDispatcher.handleViewAction({
- type: EventTypes.POST_LIST_SCROLL_CHANGE,
- value: forceScrollToBottom
- });
-}
-
-export function emitPopoverMentionKeyClick(isRHS, mentionKey) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.POPOVER_MENTION_KEY_CLICK,
- isRHS,
- mentionKey
- });
-}
-
-let serverVersion = '';
-
-export function reloadIfServerVersionChanged() {
- const newServerVersion = Client4.getServerVersion();
- if (serverVersion && serverVersion !== newServerVersion) {
- console.log('Detected version update refreshing the page'); //eslint-disable-line no-console
- window.location.reload(true);
- }
-
- serverVersion = newServerVersion;
-}
diff --git a/webapp/actions/integration_actions.jsx b/webapp/actions/integration_actions.jsx
deleted file mode 100644
index cc20b3ab8..000000000
--- a/webapp/actions/integration_actions.jsx
+++ /dev/null
@@ -1,301 +0,0 @@
-// Copyright (c) 2016-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 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) => {
- if (data) {
- loadProfilesForIncomingHooks(data);
- }
-
- if (complete) {
- complete(data);
- }
- }
- );
-}
-
-export function loadIncomingHooksForTeam(teamId, complete) {
- IntegrationActions.getIncomingHooks(teamId, 0, 10000)(dispatch, getState).then(
- (data) => {
- if (data) {
- loadProfilesForIncomingHooks(data);
- }
-
- if (complete) {
- complete(data);
- }
- }
- );
-}
-
-function loadProfilesForIncomingHooks(hooks) {
- const profilesToLoad = {};
- for (let i = 0; i < hooks.length; i++) {
- const hook = hooks[i];
- if (!UserStore.hasProfile(hook.user_id)) {
- profilesToLoad[hook.user_id] = true;
- }
- }
-
- const list = Object.keys(profilesToLoad);
- if (list.length === 0) {
- return;
- }
-
- getProfilesByIds(list)(dispatch, getState);
-}
-
-export function loadOutgoingHooks(complete) {
- IntegrationActions.getOutgoingHooks('', '', 0, 10000)(dispatch, getState).then(
- (data) => {
- if (data) {
- loadProfilesForOutgoingHooks(data);
- }
-
- if (complete) {
- complete(data);
- }
- }
- );
-}
-
-export function loadOutgoingHooksForTeam(teamId, complete) {
- IntegrationActions.getOutgoingHooks('', teamId, 0, 10000)(dispatch, getState).then(
- (data) => {
- if (data) {
- loadProfilesForOutgoingHooks(data);
- }
-
- if (complete) {
- complete(data);
- }
- }
- );
-}
-
-function loadProfilesForOutgoingHooks(hooks) {
- const profilesToLoad = {};
- for (let i = 0; i < hooks.length; i++) {
- const hook = hooks[i];
- if (!UserStore.hasProfile(hook.creator_id)) {
- profilesToLoad[hook.creator_id] = true;
- }
- }
-
- const list = Object.keys(profilesToLoad);
- if (list.length === 0) {
- return;
- }
-
- getProfilesByIds(list)(dispatch, getState);
-}
-
-export function loadTeamCommands(complete) {
- IntegrationActions.getCustomTeamCommands(TeamStore.getCurrentId())(dispatch, getState).then(
- (data) => {
- if (data) {
- loadProfilesForCommands(data);
- }
-
- if (complete) {
- complete(data);
- }
- }
- );
-}
-
-function loadProfilesForCommands(commands) {
- const profilesToLoad = {};
- for (let i = 0; i < commands.length; i++) {
- const command = commands[i];
- if (!UserStore.hasProfile(command.creator_id)) {
- profilesToLoad[command.creator_id] = true;
- }
- }
-
- const list = Object.keys(profilesToLoad);
- if (list.length === 0) {
- return;
- }
-
- getProfilesByIds(list)(dispatch, getState);
-}
-
-export function addIncomingHook(hook, success, error) {
- IntegrationActions.createIncomingHook(hook)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.integrations.createIncomingHook.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function updateIncomingHook(hook, success, error) {
- IntegrationActions.updateIncomingHook(hook)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.integrations.updateIncomingHook.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function addOutgoingHook(hook, success, error) {
- IntegrationActions.createOutgoingHook(hook)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.integrations.createOutgoingHook.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function updateOutgoingHook(hook, success, error) {
- IntegrationActions.updateOutgoingHook(hook)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.integrations.updateOutgoingHook.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function deleteIncomingHook(id) {
- IntegrationActions.removeIncomingHook(id)(dispatch, getState);
-}
-
-export function deleteOutgoingHook(id) {
- IntegrationActions.removeOutgoingHook(id)(dispatch, getState);
-}
-
-export function regenOutgoingHookToken(id) {
- IntegrationActions.regenOutgoingHookToken(id)(dispatch, getState);
-}
-
-export function addCommand(command, success, error) {
- IntegrationActions.addCommand(command)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.integrations.addCommand.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function editCommand(command, success, error) {
- IntegrationActions.editCommand(command)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.integrations.editCommand.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function deleteCommand(id) {
- IntegrationActions.deleteCommand(id)(dispatch, getState);
-}
-
-export function regenCommandToken(id) {
- IntegrationActions.regenCommandToken(id)(dispatch, getState);
-}
-
-export function getSuggestedCommands(command, suggestionId, component) {
- Client4.getCommandsList(TeamStore.getCurrentId()).then(
- (data) => {
- let matches = [];
- data.forEach((cmd) => {
- if (!cmd.auto_complete) {
- return;
- }
-
- 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/job_actions.jsx b/webapp/actions/job_actions.jsx
deleted file mode 100644
index 75d70faec..000000000
--- a/webapp/actions/job_actions.jsx
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import * as JobsActions from 'mattermost-redux/actions/jobs';
-
-import store from 'stores/redux_store.jsx';
-const dispatch = store.dispatch;
-const getState = store.getState;
-
-export function createJob(job, success, error) {
- JobsActions.createJob(job)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.jobs.createJob.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function cancelJob(jobId, success, error) {
- JobsActions.cancelJob(jobId)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.jobs.cancelJob.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
diff --git a/webapp/actions/notification_actions.jsx b/webapp/actions/notification_actions.jsx
deleted file mode 100644
index 33709458a..000000000
--- a/webapp/actions/notification_actions.jsx
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import Constants from 'utils/constants.jsx';
-import UserStore from 'stores/user_store.jsx';
-import ChannelStore from 'stores/channel_store.jsx';
-import NotificationStore from 'stores/notification_store.jsx';
-
-import {isSystemMessage} from 'utils/post_utils.jsx';
-import {buildGroupChannelName} from 'utils/channel_utils.jsx';
-import {isWindowsApp, isMacApp, isMobileApp} from 'utils/user_agent.jsx';
-import * as Utils from 'utils/utils.jsx';
-
-export function sendDesktopNotification(post, msgProps) {
- if ((UserStore.getCurrentId() === post.user_id && post.props.from_webhook !== 'true')) {
- return;
- }
-
- if (isSystemMessage(post)) {
- return;
- }
-
- let mentions = [];
- if (msgProps.mentions) {
- mentions = JSON.parse(msgProps.mentions);
- }
- const teamId = msgProps.team_id;
-
- let channel = ChannelStore.get(post.channel_id);
- const user = UserStore.getCurrentUser();
- const member = ChannelStore.getMyMember(post.channel_id);
-
- let notifyLevel = member && member.notify_props ? member.notify_props.desktop : 'default';
- if (notifyLevel === 'default') {
- notifyLevel = user.notify_props.desktop;
- }
-
- if (notifyLevel === 'none') {
- return;
- } else if (notifyLevel === 'mention' && mentions.indexOf(user.id) === -1 && msgProps.channel_type !== Constants.DM_CHANNEL) {
- return;
- }
-
- let username = Utils.localizeMessage('channel_loader.someone', 'Someone');
- if (post.props.override_username && global.window.mm_config.EnablePostUsernameOverride === 'true') {
- username = post.props.override_username;
- } else if (msgProps.sender_name) {
- username = msgProps.sender_name;
- } else if (UserStore.hasProfile(post.user_id)) {
- username = UserStore.getProfile(post.user_id).username;
- }
-
- let title = Utils.localizeMessage('channel_loader.posted', 'Posted');
- if (!channel) {
- title = msgProps.channel_display_name;
- channel = {
- name: msgProps.channel_name,
- type: msgProps.channel_type
- };
- } else if (channel.type === Constants.DM_CHANNEL) {
- title = Utils.localizeMessage('notification.dm', 'Direct Message');
- } else if (channel.type === Constants.GM_CHANNEL) {
- title = buildGroupChannelName(channel.id);
- } else {
- title = channel.display_name;
- }
-
- if (title === '') {
- if (msgProps.channel_type === Constants.DM_CHANNEL) {
- title = Utils.localizeMessage('notification.dm', 'Direct Message');
- } else {
- title = msgProps.channel_display_name;
- }
- }
-
- let notifyText = post.message;
-
- const msgPropsPost = JSON.parse(msgProps.post);
- const attachments = msgPropsPost && msgPropsPost.props && msgPropsPost.props.attachments ? msgPropsPost.props.attachments : [];
- let image = false;
- attachments.forEach((attachment) => {
- if (notifyText.length === 0) {
- notifyText = attachment.fallback ||
- attachment.pretext ||
- attachment.text;
- }
- image |= attachment.image_url.length > 0;
- });
-
- notifyText = notifyText.replace(/\n+/g, ' ');
- if (notifyText.length > 50) {
- notifyText = notifyText.substring(0, 49) + '...';
- }
-
- let body = '';
- if (notifyText.length === 0) {
- if (msgProps.image) {
- body = username + Utils.localizeMessage('channel_loader.uploadedImage', ' uploaded an image');
- } else if (msgProps.otherFile) {
- body = username + Utils.localizeMessage('channel_loader.uploadedFile', ' uploaded a file');
- } else if (image) {
- body = username + Utils.localizeMessage('channel_loader.postedImage', ' posted an image');
- } else {
- body = username + Utils.localizeMessage('channel_loader.something', ' did something new');
- }
- } else {
- body = username + Utils.localizeMessage('channel_loader.wrote', ' wrote: ') + notifyText;
- }
-
- let duration = Constants.DEFAULT_NOTIFICATION_DURATION;
- if (user.notify_props && user.notify_props.desktop_duration) {
- duration = parseInt(user.notify_props.desktop_duration, 10) * 1000;
- }
-
- //Play a sound if explicitly set in settings
- const sound = !user.notify_props || user.notify_props.desktop_sound === 'true';
-
- // Notify if you're not looking in the right channel or when
- // the window itself is not active
- const activeChannel = ChannelStore.getCurrent();
- const channelId = channel ? channel.id : null;
- const notify = (activeChannel && activeChannel.id !== channelId) || !NotificationStore.getFocus();
-
- if (notify) {
- Utils.notifyMe(title, body, channel, teamId, duration, !sound);
-
- //Don't add extra sounds on native desktop clients
- if (sound && !isWindowsApp() && !isMacApp() && !isMobileApp()) {
- Utils.ding();
- }
- }
-}
diff --git a/webapp/actions/oauth_actions.jsx b/webapp/actions/oauth_actions.jsx
deleted file mode 100644
index 54823a324..000000000
--- a/webapp/actions/oauth_actions.jsx
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import store from 'stores/redux_store.jsx';
-const dispatch = store.dispatch;
-const getState = store.getState;
-
-import * as IntegrationActions from 'mattermost-redux/actions/integrations';
-
-export function deleteOAuthApp(id, success, error) {
- IntegrationActions.deleteOAuthApp(id)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.integrations.deleteOAuthApp.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
deleted file mode 100644
index cb111ec39..000000000
--- a/webapp/actions/post_actions.jsx
+++ /dev/null
@@ -1,357 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-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 {sendDesktopNotification} from 'actions/notification_actions.jsx';
-
-import {ActionTypes, Constants} from 'utils/constants.jsx';
-import {EMOJI_PATTERN} from 'utils/emoticons.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 * 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';
-
-export function handleNewPost(post, msg) {
- let websocketMessageProps = {};
- if (msg) {
- websocketMessageProps = msg.data;
- }
-
- if (ChannelStore.getMyMember(post.channel_id)) {
- completePostReceive(post, websocketMessageProps);
- } else {
- getMyChannelMember(post.channel_id)(dispatch, getState).then(() => completePostReceive(post, websocketMessageProps));
- }
-
- if (msg && msg.data) {
- if (msg.data.channel_type === Constants.DM_CHANNEL) {
- loadNewDMIfNeeded(post.channel_id);
- } else if (msg.data.channel_type === Constants.GM_CHANNEL) {
- loadNewGMIfNeeded(post.channel_id);
- }
- }
-}
-
-function completePostReceive(post, websocketMessageProps) {
- if (post.root_id && Selectors.getPost(getState(), post.root_id) == null) {
- PostActions.getPostThread(post.root_id)(dispatch, getState).then(
- (data) => {
- dispatchPostActions(post, websocketMessageProps);
- PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
- }
- );
-
- return;
- }
-
- dispatchPostActions(post, websocketMessageProps);
-}
-
-function dispatchPostActions(post, websocketMessageProps) {
- const {currentChannelId} = getState().entities.channels;
-
- if (post.channel_id === currentChannelId) {
- dispatch({
- type: ActionTypes.INCREASE_POST_VISIBILITY,
- data: post.channel_id,
- amount: 1
- });
- }
-
- // Need manual dispatch to remove pending post
- dispatch({
- type: PostTypes.RECEIVED_POSTS,
- data: {
- order: [],
- posts: {
- [post.id]: post
- }
- },
- channelId: post.channel_id
- });
-
- // Still needed to update unreads
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_POST,
- post,
- websocketMessageProps
- });
-
- sendDesktopNotification(post, websocketMessageProps);
-}
-
-export function flagPost(postId) {
- PostActions.flagPost(postId)(dispatch, getState);
-}
-
-export function unflagPost(postId) {
- PostActions.unflagPost(postId)(dispatch, getState);
-}
-
-export function getFlaggedPosts() {
- Client4.getFlaggedPosts(UserStore.getCurrentId(), '', TeamStore.getCurrentId()).then(
- (data) => {
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_SEARCH_TERM,
- term: null,
- do_search: false,
- is_mention_search: false
- });
-
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_SEARCH,
- results: data,
- is_flagged_posts: true,
- is_pinned_posts: false
- });
-
- PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
- }
- ).catch(
- () => {} //eslint-disable-line no-empty-function
- );
-}
-
-export function getPinnedPosts(channelId = ChannelStore.getCurrentId()) {
- Client4.getPinnedPosts(channelId).then(
- (data) => {
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_SEARCH_TERM,
- term: null,
- do_search: false,
- is_mention_search: false
- });
-
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_SEARCH,
- results: data,
- is_flagged_posts: false,
- is_pinned_posts: true
- });
-
- PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
- }
- ).catch(
- () => {} //eslint-disable-line no-empty-function
- );
-}
-
-export function addReaction(channelId, postId, emojiName) {
- PostActions.addReaction(postId, emojiName)(dispatch, getState);
-}
-
-export function removeReaction(channelId, postId, emojiName) {
- PostActions.removeReaction(postId, emojiName)(dispatch, getState);
-}
-
-export function createPost(post, files, success) {
- // parse message and emit emoji event
- const emojis = post.message.match(EMOJI_PATTERN);
- if (emojis) {
- for (const emoji of emojis) {
- const trimmed = emoji.substring(1, emoji.length - 1);
- emitEmojiPosted(trimmed);
- }
- }
-
- PostActions.createPost(post, files)(dispatch, getState).then(() => {
- if (post.root_id) {
- PostStore.storeCommentDraft(post.root_id, null);
- } else {
- PostStore.storeDraft(post.channel_id, null);
- }
-
- if (success) {
- success();
- }
- });
-}
-
-export function updatePost(post, success) {
- PostActions.editPost(post)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success();
- } else {
- const serverError = getState().requests.posts.editPost.error;
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_ERROR,
- err: {id: serverError.server_error_id, ...serverError},
- method: 'editPost'
- });
- }
- }
- );
-}
-
-export function emitEmojiPosted(emoji) {
- AppDispatcher.handleServerAction({
- type: ActionTypes.EMOJI_POSTED,
- alias: emoji
- });
-}
-
-export function deletePost(channelId, post, success) {
- const {currentUserId} = getState().entities.users;
-
- let hardDelete = false;
- if (post.user_id === currentUserId) {
- hardDelete = true;
- }
-
- PostActions.deletePost(post, hardDelete)(dispatch, getState).then(
- () => {
- if (post.id === getState().views.rhs.selectedPostId) {
- dispatch({
- type: ActionTypes.SELECT_POST,
- postId: ''
- });
- }
-
- dispatch({
- type: PostTypes.REMOVE_POST,
- data: post
- });
-
- // Needed for search store
- AppDispatcher.handleViewAction({
- type: Constants.ActionTypes.REMOVE_POST,
- post
- });
-
- const {focusedPostId} = getState().views.channel;
- const channel = getState().entities.channels.channels[post.channel_id];
- if (post.id === focusedPostId && channel) {
- browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + channel.name);
- }
-
- if (success) {
- success();
- }
- }
- );
-}
-
-export function performSearch(terms, isMentionSearch, success, error) {
- Client4.searchPosts(TeamStore.getCurrentId(), terms, isMentionSearch).then(
- (data) => {
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_SEARCH,
- results: data,
- is_mention_search: isMentionSearch
- });
-
- PostActions.getProfilesAndStatusesForPosts(data.posts, dispatch, getState);
-
- if (success) {
- success(data);
- }
- }
- ).catch(
- (err) => {
- if (error) {
- error(err);
- }
- }
- );
-}
-
-const POST_INCREASE_AMOUNT = Constants.POST_CHUNK_SIZE / 2;
-
-// Returns true if there are more posts to load
-export function increasePostVisibility(channelId, focusedPostId) {
- return async (doDispatch, doGetState) => {
- if (doGetState().views.channel.loadingPosts[channelId]) {
- return true;
- }
-
- const currentPostVisibility = doGetState().views.channel.postVisibility[channelId];
-
- if (currentPostVisibility >= Constants.MAX_POST_VISIBILITY) {
- return true;
- }
-
- doDispatch(batchActions([
- {
- type: ActionTypes.LOADING_POSTS,
- data: true,
- channelId
- },
- {
- type: ActionTypes.INCREASE_POST_VISIBILITY,
- data: channelId,
- amount: POST_INCREASE_AMOUNT
- }
- ]));
-
- const page = Math.floor(currentPostVisibility / POST_INCREASE_AMOUNT);
-
- let posts;
- if (focusedPostId) {
- posts = await PostActions.getPostsBefore(channelId, focusedPostId, page, POST_INCREASE_AMOUNT)(dispatch, getState);
- } else {
- posts = await PostActions.getPosts(channelId, page, POST_INCREASE_AMOUNT)(doDispatch, doGetState);
- }
-
- doDispatch({
- type: ActionTypes.LOADING_POSTS,
- data: false,
- channelId
- });
-
- return posts.order.length >= POST_INCREASE_AMOUNT;
- };
-}
-
-export function searchForTerm(term) {
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_SEARCH_TERM,
- term,
- do_search: true
- });
-}
-
-export function pinPost(postId) {
- return async (doDispatch, doGetState) => {
- await PostActions.pinPost(postId)(doDispatch, doGetState);
-
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_POST_PINNED,
- postId
- });
- };
-}
-
-export function unpinPost(postId) {
- return async (doDispatch, doGetState) => {
- await PostActions.unpinPost(postId)(doDispatch, doGetState);
-
- AppDispatcher.handleServerAction({
- type: ActionTypes.RECEIVED_POST_UNPINNED,
- postId
- });
- };
-}
-
-export function doPostAction(postId, actionId) {
- PostActions.doPostAction(postId, actionId)(dispatch, getState);
-}
diff --git a/webapp/actions/status_actions.jsx b/webapp/actions/status_actions.jsx
deleted file mode 100644
index e8559bd65..000000000
--- a/webapp/actions/status_actions.jsx
+++ /dev/null
@@ -1,128 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import ChannelStore from 'stores/channel_store.jsx';
-import PostStore from 'stores/post_store.jsx';
-import PreferenceStore from 'stores/preference_store.jsx';
-import UserStore from 'stores/user_store.jsx';
-
-import {Preferences, Constants} from 'utils/constants.jsx';
-
-// Redux actions
-import store from 'stores/redux_store.jsx';
-const dispatch = store.dispatch;
-const getState = store.getState;
-
-import {getStatusesByIds} from 'mattermost-redux/actions/users';
-
-export function loadStatusesForChannel(channelId = ChannelStore.getCurrentId()) {
- const postList = PostStore.getVisiblePosts(channelId);
- if (!postList || !postList.posts) {
- return;
- }
-
- const statuses = UserStore.getStatuses();
- const statusesToLoad = {};
- for (const pid in postList.posts) {
- if (!postList.posts.hasOwnProperty(pid)) {
- continue;
- }
-
- const post = postList.posts[pid];
- if (statuses[post.user_id] == null) {
- statusesToLoad[post.user_id] = true;
- }
- }
-
- loadStatusesByIds(Object.keys(statusesToLoad));
-}
-
-export function loadStatusesForDMSidebar() {
- const dmPrefs = PreferenceStore.getCategory(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW);
- const statusesToLoad = [];
-
- for (const [key, value] of dmPrefs) {
- if (value === 'true') {
- statusesToLoad.push(key);
- }
- }
-
- loadStatusesByIds(statusesToLoad);
-}
-
-export function loadStatusesForChannelAndSidebar() {
- const statusesToLoad = {};
-
- const channelId = ChannelStore.getCurrentId();
- const posts = PostStore.getVisiblePosts(channelId) || [];
- for (const post of posts) {
- statusesToLoad[post.user_id] = true;
- }
-
- const dmPrefs = PreferenceStore.getCategory(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW);
-
- for (const [key, value] of dmPrefs) {
- if (value === 'true') {
- statusesToLoad[key] = true;
- }
- }
-
- const {currentUserId} = getState().entities.users;
- statusesToLoad[currentUserId] = true;
-
- loadStatusesByIds(Object.keys(statusesToLoad));
-}
-
-export function loadStatusesForProfilesList(users) {
- if (users == null) {
- return;
- }
-
- const statusesToLoad = [];
- for (let i = 0; i < users.length; i++) {
- statusesToLoad.push(users[i].id);
- }
-
- loadStatusesByIds(statusesToLoad);
-}
-
-export function loadStatusesForProfilesMap(users) {
- if (users == null) {
- return;
- }
-
- const statusesToLoad = [];
- for (const userId in users) {
- if (!users.hasOwnProperty(userId)) {
- return;
- }
- statusesToLoad.push(userId);
- }
-
- loadStatusesByIds(statusesToLoad);
-}
-
-export function loadStatusesByIds(userIds) {
- if (userIds.length === 0) {
- return;
- }
-
- getStatusesByIds(userIds)(dispatch, getState);
-}
-
-let intervalId = '';
-
-export function startPeriodicStatusUpdates() {
- clearInterval(intervalId);
-
- intervalId = setInterval(
- () => {
- loadStatusesForChannelAndSidebar();
- },
- Constants.STATUS_INTERVAL
- );
-}
-
-export function stopPeriodicStatusUpdates() {
- clearInterval(intervalId);
-}
diff --git a/webapp/actions/team_actions.jsx b/webapp/actions/team_actions.jsx
deleted file mode 100644
index af132b139..000000000
--- a/webapp/actions/team_actions.jsx
+++ /dev/null
@@ -1,200 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import TeamStore from 'stores/team_store.jsx';
-import ChannelStore from 'stores/channel_store.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 {Client4} from 'mattermost-redux/client';
-
-import {getUser} from 'mattermost-redux/actions/users';
-import {viewChannel} from 'mattermost-redux/actions/channels';
-import * as TeamActions from 'mattermost-redux/actions/teams';
-
-import {TeamTypes} from 'mattermost-redux/action_types';
-
-export function checkIfTeamExists(teamName, onSuccess, onError) {
- TeamActions.checkIfTeamExists(teamName)(dispatch, getState).then(
- (exists) => {
- if (exists != null && onSuccess) {
- onSuccess(exists);
- } else if (exists == null && onError) {
- const serverError = getState().requests.teams.getTeam.error;
- onError({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function createTeam(team, onSuccess, onError) {
- TeamActions.createTeam(team)(dispatch, getState).then(
- (rteam) => {
- if (rteam && onSuccess) {
- browserHistory.push('/' + rteam.name + '/channels/town-square');
- onSuccess(rteam);
- } else if (rteam == null && onError) {
- const serverError = getState().requests.teams.createTeam.error;
- onError({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function updateTeam(team, onSuccess, onError) {
- TeamActions.updateTeam(team)(dispatch, getState).then(
- (rteam) => {
- if (rteam && onSuccess) {
- browserHistory.push('/' + rteam.name + '/channels/town-square');
- onSuccess(rteam);
- } else if (rteam == null && onError) {
- const serverError = getState().requests.teams.updateTeam.error;
- onError({id: serverError.server_error_id, ...serverError});
- }
- },
- );
-}
-
-export function removeUserFromTeam(teamId, userId, success, error) {
- TeamActions.removeUserFromTeam(teamId, userId)(dispatch, getState).then(
- (data) => {
- getUser(userId)(dispatch, getState);
- TeamActions.getTeamStats(teamId)(dispatch, getState);
-
- if (data && success) {
- success();
- } else if (data == null && error) {
- const serverError = getState().requests.teams.removeUserFromTeam.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- },
- );
-}
-
-export function updateTeamMemberRoles(teamId, userId, newRoles, success, error) {
- TeamActions.updateTeamMemberRoles(teamId, userId, newRoles)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success();
- } else if (data == null && error) {
- const serverError = getState().requests.teams.updateTeamMember.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function addUserToTeamFromInvite(data, hash, inviteId, success, error) {
- Client4.addToTeamFromInvite(hash, data, inviteId).then(
- (member) => {
- TeamActions.getTeam(member.team_id)(dispatch, getState).then(
- (team) => {
- dispatch({
- type: TeamTypes.RECEIVED_MY_TEAM_MEMBER,
- data: {
- ...member,
- delete_at: 0,
- msg_count: 0,
- mention_count: 0
- }
- });
-
- if (success) {
- success(team);
- }
- }
- );
- },
- ).catch(
- (err) => {
- if (error) {
- error(err);
- }
- }
- );
-}
-
-export function addUsersToTeam(teamId, userIds, success, error) {
- TeamActions.addUsersToTeam(teamId, userIds)(dispatch, getState).then(
- (teamMembers) => {
- if (teamMembers && success) {
- success(teamMembers);
- } else if (teamMembers == null && error) {
- const serverError = getState().requests.teams.addUserToTeam.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function getInviteInfo(inviteId, success, error) {
- Client4.getTeamInviteInfo(inviteId).then(
- (inviteData) => {
- if (success) {
- success(inviteData);
- }
- }
- ).catch(
- (err) => {
- if (error) {
- error(err);
- }
- }
- );
-}
-
-export function inviteMembers(data, success, error) {
- if (!data.invites) {
- success();
- }
- const emails = [];
- data.invites.forEach((i) => {
- emails.push(i.email);
- });
- TeamActions.sendEmailInvitesToTeam(TeamStore.getCurrentId(), emails)(dispatch, getState).then(
- (result) => {
- if (result && success) {
- success();
- } else if (result == null && error) {
- const serverError = getState().requests.teams.emailInvite.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function switchTeams(url) {
- viewChannel(ChannelStore.getCurrentId())(dispatch, getState);
- browserHistory.push(url);
-}
-
-export function getTeamsForUser(userId, success, error) {
- TeamActions.getTeamsForUser(userId)(dispatch, getState).then(
- (result) => {
- if (result && success) {
- success(result);
- } else if (result == null && error) {
- const serverError = getState().requests.teams.getTeams.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function getTeamMembersForUser(userId, success, error) {
- TeamActions.getTeamMembersForUser(userId)(dispatch, getState).then(
- (result) => {
- if (result && success) {
- success(result);
- } else if (result == null && error) {
- const serverError = getState().requests.teams.getTeamMembers.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
diff --git a/webapp/actions/user_actions.jsx b/webapp/actions/user_actions.jsx
deleted file mode 100644
index 7c8f0afd5..000000000
--- a/webapp/actions/user_actions.jsx
+++ /dev/null
@@ -1,839 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import PreferenceStore from 'stores/preference_store.jsx';
-import TeamStore from 'stores/team_store.jsx';
-import UserStore from 'stores/user_store.jsx';
-import ChannelStore from 'stores/channel_store.jsx';
-
-import {getChannelMembersForUserIds} from 'actions/channel_actions.jsx';
-import {loadCurrentLocale, clientLogout} from 'actions/global_actions.jsx';
-import {loadStatusesForProfilesList, loadStatusesForProfilesMap} from 'actions/status_actions.jsx';
-
-import {getDirectChannelName, getUserIdFromChannelName} from 'utils/utils.jsx';
-
-import {Constants, ActionTypes, Preferences} from 'utils/constants.jsx';
-import {browserHistory} from 'react-router/es6';
-
-import store from 'stores/redux_store.jsx';
-const dispatch = store.dispatch;
-const getState = store.getState;
-
-import * as Selectors from 'mattermost-redux/selectors/entities/users';
-import {getBool} from 'mattermost-redux/selectors/entities/preferences';
-
-import * as UserActions from 'mattermost-redux/actions/users';
-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 as savePreferencesRedux, deletePreferences} from 'mattermost-redux/actions/preferences';
-
-import {Preferences as PreferencesRedux} from 'mattermost-redux/constants';
-
-export async function loadMe() {
- await UserActions.loadMe()(dispatch, getState);
-
- if (window.mm_config) {
- loadCurrentLocale();
- }
-}
-
-export function loadMeAndConfig(callback) {
- getClientConfig()(store.dispatch, store.getState).then((config) => {
- global.window.mm_config = config;
-
- if (global.window && global.window.analytics) {
- global.window.analytics.identify(global.window.mm_config.DiagnosticId, {}, {
- context: {
- ip: '0.0.0.0'
- },
- page: {
- path: '',
- referrer: '',
- search: '',
- title: '',
- url: ''
- },
- anonymousId: '00000000000000000000000000'
- });
- }
-
- Promise.all([
- loadMe(),
- getLicenseConfig()(store.dispatch, store.getState).then(
- (license) => {
- global.window.mm_license = license;
- }
- )
- ]).then(callback);
- });
-}
-
-export function switchFromLdapToEmail(email, password, token, ldapPassword, success, error) {
- UserActions.switchLdapToEmail(ldapPassword, email, password, token)(dispatch, getState).then(
- (data) => {
- if (data) {
- if (data.follow_link) {
- clientLogout(data.follow_link);
- }
- if (success) {
- success(data);
- }
- } else if (data == null && error) {
- const serverError = getState().requests.users.switchLogin.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function loadProfilesAndTeamMembers(page, perPage, teamId = TeamStore.getCurrentId(), success) {
- UserActions.getProfilesInTeam(teamId, page, perPage)(dispatch, getState).then(
- (data) => {
- loadTeamMembersForProfilesList(data, teamId, success);
- loadStatusesForProfilesList(data);
- }
- );
-}
-
-export function loadProfilesAndTeamMembersAndChannelMembers(page, perPage, teamId = TeamStore.getCurrentId(), channelId = ChannelStore.getCurrentId(), success, error) {
- UserActions.getProfilesInChannel(channelId, page, perPage)(dispatch, getState).then(
- (data) => {
- loadTeamMembersForProfilesList(
- data,
- teamId,
- () => {
- loadChannelMembersForProfilesList(data, channelId, success, error);
- loadStatusesForProfilesList(data);
- }
- );
- }
- );
-}
-
-export function loadTeamMembersForProfilesList(profiles, teamId = TeamStore.getCurrentId(), success, error) {
- const membersToLoad = {};
- for (let i = 0; i < profiles.length; i++) {
- const pid = profiles[i].id;
-
- if (!TeamStore.hasActiveMemberInTeam(teamId, pid)) {
- membersToLoad[pid] = true;
- }
- }
-
- const list = Object.keys(membersToLoad);
- if (list.length === 0) {
- if (success) {
- success({});
- }
- return;
- }
-
- loadTeamMembersForProfiles(list, teamId, success, error);
-}
-
-export function loadProfilesWithoutTeam(page, perPage, success) {
- UserActions.getProfilesWithoutTeam(page, perPage)(dispatch, getState).then(
- (data) => {
- loadStatusesForProfilesMap(data);
-
- if (success) {
- success(data);
- }
- }
- );
-}
-
-function loadTeamMembersForProfiles(userIds, teamId, success, error) {
- getTeamMembersByIds(teamId, userIds)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.teams.getTeamMembers.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function loadChannelMembersForProfilesMap(profiles, channelId = ChannelStore.getCurrentId(), success, error) {
- const membersToLoad = {};
- for (const pid in profiles) {
- if (!profiles.hasOwnProperty(pid)) {
- continue;
- }
-
- if (!ChannelStore.hasActiveMemberInChannel(channelId, pid)) {
- membersToLoad[pid] = true;
- }
- }
-
- const list = Object.keys(membersToLoad);
- if (list.length === 0) {
- if (success) {
- success({});
- }
- return;
- }
-
- getChannelMembersForUserIds(channelId, list, success, error);
-}
-
-export function loadTeamMembersAndChannelMembersForProfilesList(profiles, teamId = TeamStore.getCurrentId(), channelId = ChannelStore.getCurrentId(), success, error) {
- loadTeamMembersForProfilesList(profiles, teamId, () => {
- loadChannelMembersForProfilesList(profiles, channelId, success, error);
- }, error);
-}
-
-export function loadChannelMembersForProfilesList(profiles, channelId = ChannelStore.getCurrentId(), success, error) {
- const membersToLoad = {};
- for (let i = 0; i < profiles.length; i++) {
- const pid = profiles[i].id;
-
- if (!ChannelStore.hasActiveMemberInChannel(channelId, pid)) {
- membersToLoad[pid] = true;
- }
- }
-
- const list = Object.keys(membersToLoad);
- if (list.length === 0) {
- if (success) {
- success({});
- }
- return;
- }
-
- getChannelMembersForUserIds(channelId, list, success, error);
-}
-
-function populateDMChannelsWithProfiles(userIds) {
- const currentUserId = UserStore.getCurrentId();
-
- for (let i = 0; i < userIds.length; i++) {
- const channelName = getDirectChannelName(currentUserId, userIds[i]);
- const channel = ChannelStore.getByName(channelName);
- const profilesInChannel = Selectors.getUserIdsInChannels(getState())[channel.id] || new Set();
- if (channel && !profilesInChannel.has(userIds[i])) {
- UserStore.saveUserIdInChannel(channel.id, userIds[i]);
- }
- }
-}
-
-function populateChannelWithProfiles(channelId, users) {
- for (let i = 0; i < users.length; i++) {
- UserStore.saveUserIdInChannel(channelId, users[i].id);
- }
- UserStore.emitInChannelChange();
-}
-
-export function loadNewDMIfNeeded(channelId) {
- function checkPreference(channel) {
- const userId = getUserIdFromChannelName(channel);
-
- if (!userId) {
- return;
- }
-
- const pref = PreferenceStore.getBool(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, false);
- if (pref === false) {
- PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'true');
- const currentUserId = UserStore.getCurrentId();
- savePreferencesRedux(currentUserId, [{user_id: currentUserId, category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, name: userId, value: 'true'}])(dispatch, getState);
- loadProfilesForDM();
- }
- }
-
- const channel = ChannelStore.get(channelId);
- if (channel) {
- checkPreference(channel);
- } else {
- getChannelAndMyMember(channelId)(dispatch, getState).then(
- (data) => {
- if (data) {
- checkPreference(data.channel);
- }
- }
- );
- }
-}
-
-export function loadNewGMIfNeeded(channelId) {
- function checkPreference() {
- const pref = PreferenceStore.getBool(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, channelId, false);
- if (pref === false) {
- PreferenceStore.setPreference(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, channelId, 'true');
- const currentUserId = UserStore.getCurrentId();
- savePreferencesRedux(currentUserId, [{user_id: currentUserId, category: Preferences.CATEGORY_GROUP_CHANNEL_SHOW, name: channelId, value: 'true'}])(dispatch, getState);
- loadProfilesForGM();
- }
- }
-
- const channel = ChannelStore.get(channelId);
- if (channel) {
- checkPreference();
- } else {
- getChannelAndMyMember(channelId)(dispatch, getState).then(
- () => {
- checkPreference();
- }
- );
- }
-}
-
-export function loadProfilesForSidebar() {
- loadProfilesForDM();
- loadProfilesForGM();
-}
-
-export function loadProfilesForGM() {
- const channels = ChannelStore.getChannels();
- const newPreferences = [];
-
- for (let i = 0; i < channels.length; i++) {
- const channel = channels[i];
- if (channel.type !== Constants.GM_CHANNEL) {
- continue;
- }
-
- if (UserStore.getProfileListInChannel(channel.id).length >= Constants.MIN_USERS_IN_GM) {
- continue;
- }
-
- const isVisible = PreferenceStore.getBool(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, channel.id);
-
- if (!isVisible) {
- const member = ChannelStore.getMyMember(channel.id);
- if (!member || (member.mention_count === 0 && member.msg_count >= channel.total_msg_count)) {
- continue;
- }
-
- newPreferences.push({
- user_id: UserStore.getCurrentId(),
- category: Preferences.CATEGORY_GROUP_CHANNEL_SHOW,
- name: channel.id,
- value: 'true'
- });
- }
-
- UserActions.getProfilesInChannel(channel.id, 0, Constants.MAX_USERS_IN_GM)(dispatch, getState).then(
- (data) => {
- populateChannelWithProfiles(channel.id, data);
- }
- );
- }
-
- if (newPreferences.length > 0) {
- const currentUserId = UserStore.getCurrentId();
- savePreferencesRedux(currentUserId, newPreferences)(dispatch, getState);
- }
-}
-
-export function loadProfilesForDM() {
- const channels = ChannelStore.getChannels();
- const newPreferences = [];
- const profilesToLoad = [];
- const profileIds = [];
-
- for (let i = 0; i < channels.length; i++) {
- const channel = channels[i];
- if (channel.type !== Constants.DM_CHANNEL) {
- continue;
- }
-
- const teammateId = channel.name.replace(UserStore.getCurrentId(), '').replace('__', '');
- const isVisible = PreferenceStore.getBool(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, teammateId);
-
- if (!isVisible) {
- const member = ChannelStore.getMyMember(channel.id);
- if (!member || member.mention_count === 0) {
- continue;
- }
-
- newPreferences.push({
- user_id: UserStore.getCurrentId(),
- category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW,
- name: teammateId,
- value: 'true'
- });
- }
-
- if (!UserStore.hasProfile(teammateId)) {
- profilesToLoad.push(teammateId);
- }
- profileIds.push(teammateId);
- }
-
- if (newPreferences.length > 0) {
- const currentUserId = UserStore.getCurrentId();
- savePreferencesRedux(currentUserId, newPreferences)(dispatch, getState);
- }
-
- if (profilesToLoad.length > 0) {
- UserActions.getProfilesByIds(profilesToLoad)(dispatch, getState).then(
- () => {
- populateDMChannelsWithProfiles(profileIds);
- },
- );
- } else {
- populateDMChannelsWithProfiles(profileIds);
- }
-}
-
-export function saveTheme(teamId, theme, cb) {
- const currentUserId = UserStore.getCurrentId();
- const preference = [{
- user_id: currentUserId,
- category: Preferences.CATEGORY_THEME,
- name: teamId,
- value: JSON.stringify(theme)
- }];
-
- savePreferencesRedux(currentUserId, preference)(dispatch, getState).then(
- () => {
- onThemeSaved(teamId, theme, cb);
- }
- );
-}
-
-function onThemeSaved(teamId, theme, onSuccess) {
- const themePreferences = PreferenceStore.getCategory(Preferences.CATEGORY_THEME);
-
- if (teamId !== '' && themePreferences.size > 1) {
- // no extra handling to be done to delete team-specific themes
- onSuccess();
- return;
- }
-
- const toDelete = [];
-
- for (const [name] of themePreferences) {
- if (name === '' || name === teamId) {
- continue;
- }
-
- toDelete.push({
- user_id: UserStore.getCurrentId(),
- category: Preferences.CATEGORY_THEME,
- name
- });
- }
-
- if (toDelete.length > 0) {
- // we're saving a new global theme so delete any team-specific ones
- const currentUserId = UserStore.getCurrentId();
- deletePreferences(currentUserId, toDelete)(dispatch, getState);
- }
-
- onSuccess();
-}
-
-export function searchUsers(term, teamId = TeamStore.getCurrentId(), options = {}, success) {
- UserActions.searchProfiles(term, {team_id: teamId, ...options})(dispatch, getState).then(
- (data) => {
- loadStatusesForProfilesList(data);
-
- if (success) {
- success(data);
- }
- }
- );
-}
-
-export function searchUsersNotInTeam(term, teamId = TeamStore.getCurrentId(), options = {}, success) {
- UserActions.searchProfiles(term, {not_in_team_id: teamId, ...options})(dispatch, getState).then(
- (data) => {
- loadStatusesForProfilesList(data);
-
- if (success) {
- success(data);
- }
- }
- );
-}
-
-export function autocompleteUsersInChannel(username, channelId, success) {
- const channel = ChannelStore.get(channelId);
- const teamId = channel ? channel.team_id : TeamStore.getCurrentId();
- UserActions.autocompleteUsers(username, teamId, channelId)(dispatch, getState).then(
- (data) => {
- if (success) {
- success(data);
- }
- }
- );
-}
-
-export function autocompleteUsersInTeam(username, success) {
- UserActions.autocompleteUsers(username, TeamStore.getCurrentId())(dispatch, getState).then(
- (data) => {
- if (success) {
- success(data);
- }
- }
- );
-}
-
-export function autocompleteUsers(username, success) {
- UserActions.autocompleteUsers(username)(dispatch, getState).then(
- (data) => {
- if (success) {
- success(data);
- }
- }
- );
-}
-
-export function updateUser(user, type, success, error) {
- UserActions.updateMe(user)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.updateMe.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function generateMfaSecret(success, error) {
- UserActions.generateMfaSecret(UserStore.getCurrentId())(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.generateMfaSecret.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function updateUserNotifyProps(props, success, error) {
- UserActions.updateMe({notify_props: props})(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.updateMe.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function updateUserRoles(userId, newRoles, success, error) {
- UserActions.updateUserRoles(userId, newRoles)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.updateUser.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function activateMfa(code, success, error) {
- UserActions.updateUserMfa(UserStore.getCurrentId(), true, code)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.updateUser.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- },
- );
-}
-
-export function deactivateMfa(success, error) {
- UserActions.updateUserMfa(UserStore.getCurrentId(), false)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.updateUser.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- },
- );
-}
-
-export function checkMfa(loginId, success, error) {
- if (global.window.mm_config.EnableMultifactorAuthentication !== 'true') {
- success(false);
- return;
- }
-
- UserActions.checkMfa(loginId)(dispatch, getState).then(
- (data) => {
- if (data != null && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.checkMfa.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function updateActive(userId, active, success, error) {
- UserActions.updateUserActive(userId, active)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.updateUser.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function updatePassword(userId, currentPassword, newPassword, success, error) {
- UserActions.updateUserPassword(userId, currentPassword, newPassword)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.updateUser.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function verifyEmail(token, success, error) {
- UserActions.verifyUserEmail(token)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.verifyEmail.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function resetPassword(token, password, success, error) {
- UserActions.resetUserPassword(token, password)(dispatch, getState).then(
- (data) => {
- if (data) {
- browserHistory.push('/login?extra=' + ActionTypes.PASSWORD_CHANGE);
- if (success) {
- success(data);
- }
- } else if (data == null && error) {
- const serverError = getState().requests.users.passwordReset.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function resendVerification(email, success, error) {
- UserActions.sendVerificationEmail(email)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.verifyEmail.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function loginById(userId, password, mfaToken, success, error) {
- UserActions.loginById(userId, password, mfaToken)(dispatch, getState).then(
- (ok) => {
- if (ok && success) {
- success();
- } else if (!ok && error) {
- const serverError = getState().requests.users.login.error;
- if (serverError.server_error_id === 'api.context.mfa_required.app_error') {
- if (success) {
- success();
- }
- return;
- }
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function createUserWithInvite(user, data, emailHash, inviteId, success, error) {
- UserActions.createUser(user, data, emailHash, inviteId)(dispatch, getState).then(
- (resp) => {
- if (resp && success) {
- success(resp);
- } else if (resp == null && error) {
- const serverError = getState().requests.users.create.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function webLogin(loginId, password, token, success, error) {
- UserActions.login(loginId, password, token)(dispatch, getState).then(
- (ok) => {
- if (ok && success) {
- success();
- } else if (!ok && error) {
- const serverError = getState().requests.users.login.error;
- if (serverError.server_error_id === 'api.context.mfa_required.app_error') {
- if (success) {
- success();
- }
- return;
- }
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function webLoginByLdap(loginId, password, token, success, error) {
- UserActions.login(loginId, password, token, true)(dispatch, getState).then(
- (ok) => {
- if (ok && success) {
- success();
- } else if (!ok && error) {
- const serverError = getState().requests.users.login.error;
- if (serverError.server_error_id === 'api.context.mfa_required.app_error') {
- if (success) {
- success();
- }
- return;
- }
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function getAuthorizedApps(success, error) {
- Client4.getAuthorizedOAuthApps(getState().entities.users.currentUserId).then(
- (authorizedApps) => {
- if (success) {
- success(authorizedApps);
- }
- }
- ).catch(
- (err) => {
- if (error) {
- error(err);
- }
- }
- );
-}
-
-export function deauthorizeOAuthApp(appId, success, error) {
- Client4.deauthorizeOAuthApp(appId).then(
- () => {
- if (success) {
- success();
- }
- }
- ).catch(
- (err) => {
- if (error) {
- error(err);
- }
- }
- );
-}
-
-export function uploadProfileImage(userPicture, success, error) {
- UserActions.uploadProfileImage(Selectors.getCurrentUserId(getState()), userPicture)(dispatch, getState).then(
- (data) => {
- if (data && success) {
- success(data);
- } else if (data == null && error) {
- const serverError = getState().requests.users.updateUser.error;
- error({id: serverError.server_error_id, ...serverError});
- }
- }
- );
-}
-
-export function loadProfiles(page, perPage, success) {
- UserActions.getProfiles(page, perPage)(dispatch, getState).then(
- (data) => {
- if (success) {
- success(data);
- }
- }
- );
-}
-
-export function getMissingProfiles(ids) {
- const missingIds = ids.filter((id) => !UserStore.hasProfile(id));
-
- if (missingIds.length === 0) {
- return;
- }
-
- UserActions.getProfilesByIds(missingIds)(dispatch, getState);
-}
-
-export function loadMyTeamMembers() {
- getMyTeamMembers()(dispatch, getState).then(
- () => {
- getMyTeamUnreads()(dispatch, getState);
- }
- );
-}
-
-export function savePreferences(prefs, callback) {
- const currentUserId = UserStore.getCurrentId();
- savePreferencesRedux(currentUserId, prefs)(dispatch, getState).then(
- () => callback()
- );
-}
-
-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;
- const userStatus = await UserActions.getStatus(currentUserId)(doDispatch, doGetState);
-
- if (!userStatus.manual) {
- return userStatus;
- }
-
- const autoReset = getBool(getState(), PreferencesRedux.CATEGORY_AUTO_RESET_MANUAL_STATUS, currentUserId, false);
-
- if (autoReset) {
- UserActions.setStatus({user_id: currentUserId, status: 'online'})(doDispatch, doGetState);
- return userStatus;
- }
-
- 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
deleted file mode 100644
index 244de289b..000000000
--- a/webapp/actions/webrtc_actions.jsx
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
-import {WebrtcActionTypes} from 'utils/constants.jsx';
-
-import {Client4} from 'mattermost-redux/client';
-
-export function initWebrtc(userId, isCalling) {
- AppDispatcher.handleServerAction({
- type: WebrtcActionTypes.INITIALIZE,
- user_id: userId,
- is_calling: isCalling
- });
-}
-
-export function handle(message) {
- AppDispatcher.handleServerAction({
- type: message.action,
- message
- });
-}
-
-export function webrtcToken(success, error) {
- 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
deleted file mode 100644
index 1e75b1758..000000000
--- a/webapp/actions/websocket_actions.jsx
+++ /dev/null
@@ -1,473 +0,0 @@
-// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import $ from 'jquery';
-import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
-
-import UserStore from 'stores/user_store.jsx';
-import TeamStore from 'stores/team_store.jsx';
-import PreferenceStore from 'stores/preference_store.jsx';
-import ChannelStore from 'stores/channel_store.jsx';
-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 WebSocketClient from 'client/web_websocket_client.jsx';
-import * as WebrtcActions from './webrtc_actions.jsx';
-
-import * as GlobalActions from 'actions/global_actions.jsx';
-import {handleNewPost} from 'actions/post_actions.jsx';
-import {loadProfilesForSidebar} from 'actions/user_actions.jsx';
-import {loadChannelsForCurrentUser} from 'actions/channel_actions.jsx';
-import * as StatusActions from 'actions/status_actions.jsx';
-
-import {Constants, Preferences, SocketEvents, UserStatuses, ErrorBarTypes} from 'utils/constants.jsx';
-
-import {browserHistory} from 'react-router/es6';
-
-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 {getSiteURL} from 'utils/url.jsx';
-
-import * as TeamActions from 'mattermost-redux/actions/teams';
-import {viewChannel, getChannelAndMyMember, getChannelStats} from 'mattermost-redux/actions/channels';
-import {getPosts, getProfilesAndStatusesForPosts} from 'mattermost-redux/actions/posts';
-import {setServerVersion} from 'mattermost-redux/actions/general';
-import {ChannelTypes, TeamTypes, UserTypes, PostTypes, EmojiTypes} from 'mattermost-redux/action_types';
-
-const MAX_WEBSOCKET_FAILS = 7;
-
-export function initialize() {
- if (!window.WebSocket) {
- console.log('Browser does not support websocket'); //eslint-disable-line no-console
- return;
- }
-
- let connUrl = getSiteURL();
-
- // replace the protocol with a websocket one
- if (connUrl.startsWith('https:')) {
- connUrl = connUrl.replace(/^https:/, 'wss:');
- } else {
- connUrl = connUrl.replace(/^http:/, 'ws:');
- }
-
- // append a port number if one isn't already specified
- if (!(/:\d+$/).test(connUrl)) {
- if (connUrl.startsWith('wss:')) {
- connUrl += ':' + global.window.mm_config.WebsocketSecurePort;
- } else {
- connUrl += ':' + global.window.mm_config.WebsocketPort;
- }
- }
-
- connUrl += Client4.getUrlVersion() + '/websocket';
-
- WebSocketClient.setEventCallback(handleEvent);
- WebSocketClient.setFirstConnectCallback(handleFirstConnect);
- WebSocketClient.setReconnectCallback(() => reconnect(false));
- WebSocketClient.setMissedEventCallback(() => reconnect(false));
- WebSocketClient.setCloseCallback(handleClose);
- WebSocketClient.initialize(connUrl);
-}
-
-export function close() {
- WebSocketClient.close();
-}
-
-function reconnectWebSocket() {
- close();
- initialize();
-}
-
-export function reconnect(includeWebSocket = true) {
- if (includeWebSocket) {
- reconnectWebSocket();
- }
-
- loadChannelsForCurrentUser();
- getPosts(ChannelStore.getCurrentId())(dispatch, getState);
- StatusActions.loadStatusesForChannelAndSidebar();
-
- ErrorStore.clearLastError();
- ErrorStore.emitChange();
-}
-
-let intervalId = '';
-const SYNC_INTERVAL_MILLISECONDS = 1000 * 60 * 15; // 15 minutes
-
-export function startPeriodicSync() {
- clearInterval(intervalId);
-
- intervalId = setInterval(
- () => {
- if (UserStore.getCurrentUser() != null) {
- reconnect(false);
- }
- },
- SYNC_INTERVAL_MILLISECONDS
- );
-}
-
-export function stopPeriodicSync() {
- clearInterval(intervalId);
-}
-
-function handleFirstConnect() {
- ErrorStore.clearLastError();
- ErrorStore.emitChange();
-}
-
-function handleClose(failCount) {
- if (failCount > MAX_WEBSOCKET_FAILS) {
- ErrorStore.storeLastError({message: ErrorBarTypes.WEBSOCKET_PORT_ERROR});
- }
-
- ErrorStore.setConnectionErrorCount(failCount);
- ErrorStore.emitChange();
-}
-
-function handleEvent(msg) {
- switch (msg.event) {
- case SocketEvents.POSTED:
- case SocketEvents.EPHEMERAL_MESSAGE:
- handleNewPostEvent(msg);
- break;
-
- case SocketEvents.POST_EDITED:
- handlePostEditEvent(msg);
- break;
-
- case SocketEvents.POST_DELETED:
- handlePostDeleteEvent(msg);
- break;
-
- case SocketEvents.LEAVE_TEAM:
- handleLeaveTeamEvent(msg);
- break;
-
- case SocketEvents.UPDATE_TEAM:
- handleUpdateTeamEvent(msg);
- break;
-
- case SocketEvents.ADDED_TO_TEAM:
- handleTeamAddedEvent(msg);
- break;
-
- case SocketEvents.USER_ADDED:
- handleUserAddedEvent(msg);
- break;
-
- case SocketEvents.USER_REMOVED:
- handleUserRemovedEvent(msg);
- break;
-
- case SocketEvents.USER_UPDATED:
- handleUserUpdatedEvent(msg);
- break;
-
- case SocketEvents.MEMBERROLE_UPDATED:
- handleUpdateMemberRoleEvent(msg);
- break;
-
- case SocketEvents.CHANNEL_CREATED:
- handleChannelCreatedEvent(msg);
- break;
-
- case SocketEvents.CHANNEL_DELETED:
- handleChannelDeletedEvent(msg);
- break;
-
- case SocketEvents.CHANNEL_UPDATED:
- handleChannelUpdatedEvent(msg);
- break;
-
- case SocketEvents.DIRECT_ADDED:
- handleDirectAddedEvent(msg);
- break;
-
- case SocketEvents.PREFERENCE_CHANGED:
- handlePreferenceChangedEvent(msg);
- break;
-
- case SocketEvents.PREFERENCES_CHANGED:
- handlePreferencesChangedEvent(msg);
- break;
-
- case SocketEvents.PREFERENCES_DELETED:
- handlePreferencesDeletedEvent(msg);
- break;
-
- case SocketEvents.TYPING:
- handleUserTypingEvent(msg);
- break;
-
- case SocketEvents.STATUS_CHANGED:
- handleStatusChangedEvent(msg);
- break;
-
- case SocketEvents.HELLO:
- handleHelloEvent(msg);
- break;
-
- case SocketEvents.WEBRTC:
- handleWebrtc(msg);
- break;
-
- case SocketEvents.REACTION_ADDED:
- handleReactionAddedEvent(msg);
- break;
-
- case SocketEvents.REACTION_REMOVED:
- handleReactionRemovedEvent(msg);
- break;
-
- case SocketEvents.EMOJI_ADDED:
- handleAddEmoji(msg);
- break;
-
- case SocketEvents.CHANNEL_VIEWED:
- handleChannelViewedEvent(msg);
- break;
-
- default:
- }
-}
-
-function handleChannelUpdatedEvent(msg) {
- const channel = JSON.parse(msg.data.channel);
- dispatch({type: ChannelTypes.RECEIVED_CHANNEL, data: channel});
-}
-
-function handleNewPostEvent(msg) {
- const post = JSON.parse(msg.data.post);
- handleNewPost(post, msg);
-
- getProfilesAndStatusesForPosts([post], dispatch, getState);
-
- if (post.user_id !== UserStore.getCurrentId()) {
- UserStore.setStatus(post.user_id, UserStatuses.ONLINE);
- }
-}
-
-function handlePostEditEvent(msg) {
- // Store post
- const post = JSON.parse(msg.data.post);
- dispatch({type: PostTypes.RECEIVED_POST, data: post});
-
- // Update channel state
- if (ChannelStore.getCurrentId() === msg.broadcast.channel_id) {
- if (window.isActive) {
- viewChannel(ChannelStore.getCurrentId())(dispatch, getState);
- }
- }
-
- // Needed for search store
- AppDispatcher.handleViewAction({
- type: Constants.ActionTypes.POST_UPDATED,
- post
- });
-}
-
-function handlePostDeleteEvent(msg) {
- const post = JSON.parse(msg.data.post);
- dispatch({type: PostTypes.POST_DELETED, data: post});
-
- // Needed for search store
- AppDispatcher.handleViewAction({
- type: Constants.ActionTypes.POST_DELETED,
- post
- });
-}
-
-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) {
- if (UserStore.getCurrentId() === msg.data.user_id) {
- TeamStore.removeMyTeamMember(msg.data.team_id);
-
- // if they are on the team being removed redirect them to default team
- if (TeamStore.getCurrentId() === msg.data.team_id) {
- BrowserStore.removeGlobalItem('team');
- BrowserStore.removeGlobalItem(msg.data.team_id);
-
- if (!global.location.pathname.startsWith('/admin_console')) {
- GlobalActions.redirectUserToDefaultTeam();
- }
- }
-
- dispatch(batchActions([
- {
- type: UserTypes.RECEIVED_PROFILE_NOT_IN_TEAM,
- data: {user_id: msg.data.user_id},
- id: msg.data.team_id
- },
- {
- type: TeamTypes.REMOVE_MEMBER_FROM_TEAM,
- data: {team_id: msg.data.team_id, user_id: msg.data.user_id}
- }
- ]));
- } else {
- UserStore.removeProfileFromTeam(msg.data.team_id, msg.data.user_id);
- TeamStore.removeMemberInTeam(msg.data.team_id, msg.data.user_id);
- }
-}
-
-function handleUpdateTeamEvent(msg) {
- TeamStore.updateTeam(msg.data.team);
-}
-
-function handleUpdateMemberRoleEvent(msg) {
- const member = JSON.parse(msg.data.member);
- TeamStore.updateMyRoles(member);
-}
-
-function handleDirectAddedEvent(msg) {
- getChannelAndMyMember(msg.broadcast.channel_id)(dispatch, getState);
- PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, msg.data.teammate_id, 'true');
- loadProfilesForSidebar();
-}
-
-function handleUserAddedEvent(msg) {
- if (ChannelStore.getCurrentId() === msg.broadcast.channel_id) {
- getChannelStats(ChannelStore.getCurrentId())(dispatch, getState);
- }
-
- if (TeamStore.getCurrentId() === msg.data.team_id && UserStore.getCurrentId() === msg.data.user_id) {
- getChannelAndMyMember(msg.broadcast.channel_id)(dispatch, getState);
- }
-}
-
-function handleUserRemovedEvent(msg) {
- if (UserStore.getCurrentId() === msg.broadcast.user_id) {
- loadChannelsForCurrentUser();
-
- if (msg.data.remover_id !== msg.broadcast.user_id &&
- msg.data.channel_id === ChannelStore.getCurrentId() &&
- $('#removed_from_channel').length > 0) {
- var sentState = {};
- sentState.channelName = ChannelStore.getCurrent().display_name;
- sentState.remover = UserStore.getProfile(msg.data.remover_id).username;
-
- BrowserStore.setItem('channel-removed-state', sentState);
- $('#removed_from_channel').modal('show');
- }
-
- GlobalActions.toggleSideBarAction(false);
-
- const townsquare = ChannelStore.getByName('town-square');
- browserHistory.push(TeamStore.getCurrentTeamRelativeUrl() + '/channels/' + townsquare.name);
-
- dispatch({
- type: ChannelTypes.LEAVE_CHANNEL,
- data: {id: msg.data.channel_id, user_id: msg.broadcast.user_id}
- });
- } else if (ChannelStore.getCurrentId() === msg.broadcast.channel_id) {
- getChannelStats(ChannelStore.getCurrentId())(dispatch, getState);
- }
-}
-
-function handleUserUpdatedEvent(msg) {
- const user = msg.data.user;
- if (UserStore.getCurrentId() !== user.id) {
- UserStore.saveProfile(user);
- }
-}
-
-function handleChannelCreatedEvent(msg) {
- const channelId = msg.data.channel_id;
- const teamId = msg.data.team_id;
-
- if (TeamStore.getCurrentId() === teamId && !ChannelStore.getChannelById(channelId)) {
- getChannelAndMyMember(channelId)(dispatch, getState);
- }
-}
-
-function handleChannelDeletedEvent(msg) {
- if (ChannelStore.getCurrentId() === msg.data.channel_id) {
- const teamUrl = TeamStore.getCurrentTeamRelativeUrl();
- browserHistory.push(teamUrl + '/channels/' + Constants.DEFAULT_CHANNEL);
- }
- dispatch({type: ChannelTypes.RECEIVED_CHANNEL_DELETED, data: {id: msg.data.channel_id, team_id: msg.broadcast.team_id}}, getState);
- loadChannelsForCurrentUser();
-}
-
-function handlePreferenceChangedEvent(msg) {
- const preference = JSON.parse(msg.data.preference);
- GlobalActions.emitPreferenceChangedEvent(preference);
-}
-
-function handlePreferencesChangedEvent(msg) {
- const preferences = JSON.parse(msg.data.preferences);
- GlobalActions.emitPreferencesChangedEvent(preferences);
-}
-
-function handlePreferencesDeletedEvent(msg) {
- const preferences = JSON.parse(msg.data.preferences);
- GlobalActions.emitPreferencesDeletedEvent(preferences);
-}
-
-function handleUserTypingEvent(msg) {
- GlobalActions.emitRemoteUserTypingEvent(msg.broadcast.channel_id, msg.data.user_id, msg.data.parent_id);
-
- if (msg.data.user_id !== UserStore.getCurrentId()) {
- UserStore.setStatus(msg.data.user_id, UserStatuses.ONLINE);
- }
-}
-
-function handleStatusChangedEvent(msg) {
- UserStore.setStatus(msg.data.user_id, msg.data.status);
-}
-
-function handleHelloEvent(msg) {
- setServerVersion(msg.data.server_version)(dispatch, getState);
-}
-
-function handleWebrtc(msg) {
- const data = msg.data;
- return WebrtcActions.handle(data);
-}
-
-function handleReactionAddedEvent(msg) {
- const reaction = JSON.parse(msg.data.reaction);
-
- dispatch({
- type: PostTypes.RECEIVED_REACTION,
- data: reaction
- });
-}
-
-function handleAddEmoji(msg) {
- const data = JSON.parse(msg.data.emoji);
-
- dispatch({
- type: EmojiTypes.RECEIVED_CUSTOM_EMOJI,
- data
- });
-}
-
-function handleReactionRemovedEvent(msg) {
- const reaction = JSON.parse(msg.data.reaction);
-
- dispatch({
- type: PostTypes.REACTION_DELETED,
- data: reaction
- });
-}
-
-function handleChannelViewedEvent(msg) {
-// Useful for when multiple devices have the app open to different channels
- if (ChannelStore.getCurrentId() !== msg.data.channel_id &&
- UserStore.getCurrentId() === msg.broadcast.user_id) {
- // Mark previous and next channel as read
- ChannelStore.resetCounts([msg.data.channel_id]);
- }
-}