Skip to content

Commit

Permalink
Move remaining actions over to use redux and v4 endpoints (mattermost…
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilander committed Jun 26, 2017
1 parent a092e45 commit 8ab44b3
Show file tree
Hide file tree
Showing 67 changed files with 528 additions and 6,923 deletions.
51 changes: 30 additions & 21 deletions actions/admin_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import {clientLogout} from 'actions/global_actions.jsx';

import Client from 'client/web_client.jsx';

import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
Expand Down Expand Up @@ -267,31 +265,26 @@ export function uploadBrandImage(brandImage, success, error) {
}

export function uploadLicenseFile(file, success, error) {
Client.uploadLicenseFile(
file,
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
AdminActions.uploadLicense(file)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
} else if (data == null && error) {
const serverError = getState().requests.admin.uploadLicense.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
}

export function removeLicenseFile(success, error) {
Client.removeLicenseFile(
() => {
if (success) {
success();
}
},
(err) => {
if (error) {
error(err);
AdminActions.removeLicense()(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
} else if (data == null && error) {
const serverError = getState().requests.admin.removeLicense.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
Expand Down Expand Up @@ -374,3 +367,19 @@ export function removeIdpSamlCertificate(success, error) {
}
);
}

export function getStandardAnalytics(teamId) {
AdminActions.getStandardAnalytics(teamId)(dispatch, getState);
}

export function getAdvancedAnalytics(teamId) {
AdminActions.getAdvancedAnalytics(teamId)(dispatch, getState);
}

export function getPostsPerDayAnalytics(teamId) {
AdminActions.getPostsPerDayAnalytics(teamId)(dispatch, getState);
}

export function getUsersPerDayAnalytics(teamId) {
AdminActions.getUsersPerDayAnalytics(teamId)(dispatch, getState);
}
121 changes: 39 additions & 82 deletions actions/channel_actions.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import AppDispatcher from 'dispatcher/app_dispatcher.jsx';

import TeamStore from 'stores/team_store.jsx';
import UserStore from 'stores/user_store.jsx';
import ChannelStore from 'stores/channel_store.jsx';
Expand All @@ -14,36 +12,19 @@ import * as GlobalActions from 'actions/global_actions.jsx';
import {loadProfilesForSidebar, loadNewDMIfNeeded, loadNewGMIfNeeded} from 'actions/user_actions.jsx';
import {trackEvent} from 'actions/diagnostics_actions.jsx';

import Client from 'client/web_client.jsx';
import * as AsyncClient from 'utils/async_client.jsx';
import * as UserAgent from 'utils/user_agent.jsx';
import * as Utils from 'utils/utils.jsx';
import {Constants, Preferences, ActionTypes} from 'utils/constants.jsx';
import {Constants, Preferences} from 'utils/constants.jsx';

import {browserHistory} from 'react-router/es6';

// Redux actions
import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;

import {
viewChannel,
addChannelMember,
removeChannelMember,
updateChannelMemberRoles,
createDirectChannel,
fetchMyChannelsAndMembers,
joinChannel as joinChannelRedux,
leaveChannel as leaveChannelRedux,
updateChannel as updateChannelRedux,
searchChannels,
updateChannelNotifyProps as updateChannelNotifyPropsRedux,
createChannel as createChannelRedux,
patchChannel,
getChannelMembersByIds,
deleteChannel as deleteChannelRedux
} from 'mattermost-redux/actions/channels';
import * as ChannelActions from 'mattermost-redux/actions/channels';
import {savePreferences, deletePreferences} from 'mattermost-redux/actions/preferences';
import {Client4} from 'mattermost-redux/client';

import {getMyChannelMemberships} from 'mattermost-redux/selectors/entities/channels';

Expand Down Expand Up @@ -92,10 +73,8 @@ export function executeCommand(message, args, success, error) {
return;
}

Client.executeCommand(msg, args, success,
Client4.executeCommand(msg, args).then(success).catch(
(err) => {
AsyncClient.dispatchError(err, 'executeCommand');

if (error) {
error(err);
}
Expand All @@ -105,7 +84,7 @@ export function executeCommand(message, args, success, error) {

export function setChannelAsRead(channelIdParam) {
const channelId = channelIdParam || ChannelStore.getCurrentId();
viewChannel(channelId)(dispatch, getState);
ChannelActions.viewChannel(channelId)(dispatch, getState);
ChannelStore.resetCounts([channelId]);
ChannelStore.emitChange();
if (channelId === ChannelStore.getCurrentId()) {
Expand All @@ -114,7 +93,7 @@ export function setChannelAsRead(channelIdParam) {
}

export function addUserToChannel(channelId, userId, success, error) {
addChannelMember(channelId, userId)(dispatch, getState).then(
ChannelActions.addChannelMember(channelId, userId)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand All @@ -127,7 +106,7 @@ export function addUserToChannel(channelId, userId, success, error) {
}

export function removeUserFromChannel(channelId, userId, success, error) {
removeChannelMember(channelId, userId)(dispatch, getState).then(
ChannelActions.removeChannelMember(channelId, userId)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand All @@ -140,7 +119,7 @@ export function removeUserFromChannel(channelId, userId, success, error) {
}

export function makeUserChannelAdmin(channelId, userId, success, error) {
updateChannelMemberRoles(channelId, userId, 'channel_user channel_admin')(dispatch, getState).then(
ChannelActions.updateChannelMemberRoles(channelId, userId, 'channel_user channel_admin')(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand All @@ -153,7 +132,7 @@ export function makeUserChannelAdmin(channelId, userId, success, error) {
}

export function makeUserChannelMember(channelId, userId, success, error) {
updateChannelMemberRoles(channelId, userId, 'channel_user')(dispatch, getState).then(
ChannelActions.updateChannelMemberRoles(channelId, userId, 'channel_user')(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand All @@ -174,11 +153,8 @@ export function openDirectChannelToUser(userId, success, error) {
PreferenceStore.setPreference(Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, 'true');
loadProfilesForSidebar();

AsyncClient.savePreference(
Preferences.CATEGORY_DIRECT_CHANNEL_SHOW,
userId,
'true'
);
const currentUserId = UserStore.getCurrentId();
savePreferences(currentUserId, [{user_id: currentUserId, category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, name: userId, value: 'true'}])(dispatch, getState);

if (success) {
success(channel, true);
Expand All @@ -187,7 +163,7 @@ export function openDirectChannelToUser(userId, success, error) {
return;
}

createDirectChannel(UserStore.getCurrentId(), userId)(dispatch, getState).then(
ChannelActions.createDirectChannel(UserStore.getCurrentId(), userId)(dispatch, getState).then(
(data) => {
loadProfilesForSidebar();
if (data && success) {
Expand All @@ -202,60 +178,41 @@ export function openDirectChannelToUser(userId, success, error) {
}

export function openGroupChannelToUsers(userIds, success, error) {
Client.createGroupChannel(
userIds,
ChannelActions.createGroupChannel(userIds)(dispatch, getState).then(
(data) => {
Client.getChannelMember(
data.id,
UserStore.getCurrentId(),
(data2) => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_CHANNEL,
channel: data,
member: data2
});

PreferenceStore.setPreference(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, data.id, 'true');
loadProfilesForSidebar();

AsyncClient.savePreference(
Preferences.CATEGORY_GROUP_CHANNEL_SHOW,
data.id,
'true'
);

if (success) {
success(data);
}
}
);
},
() => {
if (error) {
error();
loadProfilesForSidebar();
if (data && success) {
success(data, false);
} else if (data == null && error) {
browserHistory.push(TeamStore.getCurrentTeamUrl());
const serverError = getState().requests.channels.createChannel.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
}

export function markFavorite(channelId) {
trackEvent('api', 'api_channels_favorited');
AsyncClient.savePreference(Preferences.CATEGORY_FAVORITE_CHANNEL, channelId, 'true');
const currentUserId = UserStore.getCurrentId();
savePreferences(currentUserId, [{user_id: currentUserId, category: Preferences.CATEGORY_FAVORITE_CHANNEL, name: channelId, value: 'true'}])(dispatch, getState);
}

export function unmarkFavorite(channelId) {
trackEvent('api', 'api_channels_unfavorited');
const currentUserId = UserStore.getCurrentId();

const pref = {
user_id: UserStore.getCurrentId(),
user_id: currentUserId,
category: Preferences.CATEGORY_FAVORITE_CHANNEL,
name: channelId
};

AsyncClient.deletePreferences([pref]);
deletePreferences(currentUserId, [pref])(dispatch, getState);
}

export function loadChannelsForCurrentUser() {
fetchMyChannelsAndMembers(TeamStore.getCurrentId())(dispatch, getState).then(
ChannelActions.fetchMyChannelsAndMembers(TeamStore.getCurrentId())(dispatch, getState).then(
() => {
loadDMsAndGMsForUnreads();
}
Expand All @@ -281,7 +238,7 @@ export function loadDMsAndGMsForUnreads() {
}

export function joinChannel(channel, success, error) {
joinChannelRedux(UserStore.getCurrentId(), null, channel.id)(dispatch, getState).then(
ChannelActions.joinChannel(UserStore.getCurrentId(), null, channel.id)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand All @@ -294,7 +251,7 @@ export function joinChannel(channel, success, error) {
}

export function updateChannel(channel, success, error) {
updateChannelRedux(channel)(dispatch, getState).then(
ChannelActions.updateChannel(channel)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand All @@ -307,7 +264,7 @@ export function updateChannel(channel, success, error) {
}

export function searchMoreChannels(term, success, error) {
searchChannels(TeamStore.getCurrentId(), term)(dispatch, getState).then(
ChannelActions.searchChannels(TeamStore.getCurrentId(), term)(dispatch, getState).then(
(data) => {
if (data && success) {
const myMembers = getMyChannelMemberships(getState());
Expand All @@ -322,7 +279,7 @@ export function searchMoreChannels(term, success, error) {
}

export function autocompleteChannels(term, success, error) {
searchChannels(TeamStore.getCurrentId(), term)(dispatch, getState).then(
ChannelActions.searchChannels(TeamStore.getCurrentId(), term)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand All @@ -335,7 +292,7 @@ export function autocompleteChannels(term, success, error) {
}

export function updateChannelNotifyProps(data, options, success, error) {
updateChannelNotifyPropsRedux(data.user_id, data.channel_id, Object.assign({}, data, options))(dispatch, getState).then(
ChannelActions.updateChannelNotifyProps(data.user_id, data.channel_id, Object.assign({}, data, options))(dispatch, getState).then(
(result) => {
if (result && success) {
success(result);
Expand All @@ -348,7 +305,7 @@ export function updateChannelNotifyProps(data, options, success, error) {
}

export function createChannel(channel, success, error) {
createChannelRedux(channel)(dispatch, getState).then(
ChannelActions.createChannel(channel)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand All @@ -361,7 +318,7 @@ export function createChannel(channel, success, error) {
}

export function updateChannelPurpose(channelId, purpose, success, error) {
patchChannel(channelId, {purpose})(dispatch, getState).then(
ChannelActions.patchChannel(channelId, {purpose})(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand All @@ -374,7 +331,7 @@ export function updateChannelPurpose(channelId, purpose, success, error) {
}

export function updateChannelHeader(channelId, header, success, error) {
patchChannel(channelId, {header})(dispatch, getState).then(
ChannelActions.patchChannel(channelId, {header})(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand All @@ -387,7 +344,7 @@ export function updateChannelHeader(channelId, header, success, error) {
}

export function getChannelMembersForUserIds(channelId, userIds, success, error) {
getChannelMembersByIds(channelId, userIds)(dispatch, getState).then(
ChannelActions.getChannelMembersByIds(channelId, userIds)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand All @@ -400,7 +357,7 @@ export function getChannelMembersForUserIds(channelId, userIds, success, error)
}

export function leaveChannel(channelId, success) {
leaveChannelRedux(channelId)(dispatch, getState).then(
ChannelActions.leaveChannel(channelId)(dispatch, getState).then(
() => {
if (ChannelUtils.isFavoriteChannelId(channelId)) {
unmarkFavorite(channelId);
Expand All @@ -417,7 +374,7 @@ export function leaveChannel(channelId, success) {
}

export function deleteChannel(channelId, success, error) {
deleteChannelRedux(channelId)(dispatch, getState).then(
ChannelActions.deleteChannel(channelId)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
Expand Down
Loading

0 comments on commit 8ab44b3

Please sign in to comment.