Commit 05273fc7 authored by Joram Wilander's avatar Joram Wilander Committed by GitHub

PLT-7798 Support new mattermost-redux action returns (#147)

* Support new mattermost-redux action returns

* Some fixes

* Fix open DM/GM

* Fix adding a command
parent b08e8c17
This diff is collapsed.
This diff is collapsed.
......@@ -14,7 +14,7 @@ const dispatch = store.dispatch;
const getState = store.getState;
export async function loadEmoji(getProfiles = true) {
const data = await EmojiActions.getAllCustomEmojis()(dispatch, getState);
const {data} = await EmojiActions.getAllCustomEmojis()(dispatch, getState);
if (data && getProfiles) {
loadProfilesForEmoji(data);
......@@ -38,36 +38,28 @@ function loadProfilesForEmoji(emojiList) {
getProfilesByIds(list)(dispatch, getState);
}
export function addEmoji(emoji, image, success, error) {
EmojiActions.createCustomEmoji(emoji, image)(dispatch, getState).then(
(data) => {
if (data && success) {
success(data);
} else if (data == null && error) {
const serverError = getState().requests.emojis.createCustomEmoji.error;
error({id: serverError.server_error_id, ...serverError});
}
}
);
export async function addEmoji(emoji, image, success, error) {
const {data, error: err} = await EmojiActions.createCustomEmoji(emoji, image)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
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
});
export async function deleteEmoji(emojiId, success, error) {
const {data, error: err} = await EmojiActions.deleteCustomEmoji(emojiId)(dispatch, getState);
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});
}
if (success) {
success(data);
}
);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
......@@ -37,20 +37,15 @@ const dispatch = store.dispatch;
const getState = store.getState;
export function emitChannelClickEvent(channel) {
function userVisitedFakeChannel(chan, success, fail) {
async 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();
}
}
);
const {data: receivedChannel} = await createDirectChannel(currentUserId, otherUserId)(dispatch, getState);
if (receivedChannel) {
success(receivedChannel);
} else {
fail();
}
}
function switchToChannel(chan) {
const channelMember = ChannelStore.getMyMember(chan.id);
......@@ -123,29 +118,27 @@ export async function doFocusPost(channelId, postId, data) {
getChannelStats(channelId)(dispatch, getState);
}
export function emitPostFocusEvent(postId, onSuccess) {
export async 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);
}
const {data} = await getPostThread(postId)(dispatch, getState);
doFocusPost(channelId, postId, data).then(() => {
if (onSuccess) {
onSuccess();
}
});
} else {
browserHistory.push('/error?type=' + ErrorPageTypes.PERMALINK_NOT_FOUND);
}
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() {
......@@ -159,25 +152,23 @@ export function emitCloseRightHandSide() {
});
}
export function emitPostFocusRightHandSideFromSearch(post, isMentionSearch) {
getPostThread(post.id)(dispatch, getState).then(
() => {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_POST_SELECTED,
postId: Utils.getRootId(post),
channelId: post.channel_id,
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 async function emitPostFocusRightHandSideFromSearch(post, isMentionSearch) {
await getPostThread(post.id)(dispatch, getState);
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_POST_SELECTED,
postId: Utils.getRootId(post),
channelId: post.channel_id,
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() {
......@@ -552,7 +543,7 @@ export function emitBrowserFocus(focus) {
});
}
export function redirectUserToDefaultTeam() {
export async function redirectUserToDefaultTeam() {
const teams = TeamStore.getAll();
const teamMembers = TeamStore.getMyTeamMembers();
let teamId = BrowserStore.getGlobalItem('team');
......@@ -582,15 +573,12 @@ export function redirectUserToDefaultTeam() {
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');
}
}
);
const {data} = await getChannelAndMyMember(channelId)(dispatch, getState);
if (data) {
redirect(teams[teamId].name, data.channel.name);
} else {
redirect(teams[teamId].name, 'town-square');
}
} else {
redirect(teams[teamId].name, 'town-square');
}
......
......@@ -18,32 +18,26 @@ import * as UserAgent from 'utils/user_agent.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
export function loadIncomingHooks(complete) {
IntegrationActions.getIncomingHooks('', 0, 10000)(dispatch, getState).then(
(data) => {
if (data) {
loadProfilesForIncomingHooks(data);
}
export async function loadIncomingHooks(complete) {
const {data} = await IntegrationActions.getIncomingHooks('', 0, 10000)(dispatch, getState);
if (data) {
loadProfilesForIncomingHooks(data);
}
if (complete) {
complete(data);
}
}
);
if (complete) {
complete(data);
}
}
export function loadIncomingHooksForTeam(teamId, complete) {
IntegrationActions.getIncomingHooks(teamId, 0, 10000)(dispatch, getState).then(
(data) => {
if (data) {
loadProfilesForIncomingHooks(data);
}
export async function loadIncomingHooksForTeam(teamId, complete) {
const {data} = await IntegrationActions.getIncomingHooks(teamId, 0, 10000)(dispatch, getState);
if (data) {
loadProfilesForIncomingHooks(data);
}
if (complete) {
complete(data);
}
}
);
if (complete) {
complete(data);
}
}
function loadProfilesForIncomingHooks(hooks) {
......@@ -63,32 +57,26 @@ function loadProfilesForIncomingHooks(hooks) {
getProfilesByIds(list)(dispatch, getState);
}
export function loadOutgoingHooks(complete) {
IntegrationActions.getOutgoingHooks('', '', 0, 10000)(dispatch, getState).then(
(data) => {
if (data) {
loadProfilesForOutgoingHooks(data);
}
export async function loadOutgoingHooks(complete) {
const {data} = await IntegrationActions.getOutgoingHooks('', '', 0, 10000)(dispatch, getState);
if (data) {
loadProfilesForOutgoingHooks(data);
}
if (complete) {
complete(data);
}
}
);
if (complete) {
complete(data);
}
}
export function loadOutgoingHooksForTeam(teamId, complete) {
IntegrationActions.getOutgoingHooks('', teamId, 0, 10000)(dispatch, getState).then(
(data) => {
if (data) {
loadProfilesForOutgoingHooks(data);
}
export async function loadOutgoingHooksForTeam(teamId, complete) {
const {data} = await IntegrationActions.getOutgoingHooks('', teamId, 0, 10000)(dispatch, getState);
if (data) {
loadProfilesForOutgoingHooks(data);
}
if (complete) {
complete(data);
}
}
);
if (complete) {
complete(data);
}
}
function loadProfilesForOutgoingHooks(hooks) {
......@@ -108,18 +96,15 @@ function loadProfilesForOutgoingHooks(hooks) {
getProfilesByIds(list)(dispatch, getState);
}
export function loadTeamCommands(complete) {
IntegrationActions.getCustomTeamCommands(TeamStore.getCurrentId())(dispatch, getState).then(
(data) => {
if (data) {
loadProfilesForCommands(data);
}
export async function loadTeamCommands(complete) {
const {data} = await IntegrationActions.getCustomTeamCommands(TeamStore.getCurrentId())(dispatch, getState);
if (data) {
loadProfilesForCommands(data);
}
if (complete) {
complete(data);
}
}
);
if (complete) {
complete(data);
}
}
function loadProfilesForCommands(commands) {
......@@ -139,56 +124,40 @@ function loadProfilesForCommands(commands) {
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 async function addIncomingHook(hook, success, error) {
const {data, error: err} = await IntegrationActions.createIncomingHook(hook)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
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 async function updateIncomingHook(hook, success, error) {
const {data, error: err} = await IntegrationActions.updateIncomingHook(hook)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
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 async function addOutgoingHook(hook, success, error) {
const {data, error: err} = await IntegrationActions.createOutgoingHook(hook)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
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 async function updateOutgoingHook(hook, success, error) {
const {data, error: err} = await IntegrationActions.updateOutgoingHook(hook)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export function deleteIncomingHook(id) {
......@@ -203,30 +172,22 @@ 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 async function addCommand(command, success, error) {
const {data, error: err} = await IntegrationActions.addCommand(command)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
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 async function editCommand(command, success, error) {
const {data, error: err} = await IntegrationActions.editCommand(command)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
export function deleteCommand(id) {
......
......@@ -8,28 +8,20 @@ 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 async function createJob(job, success, error) {
const {data, error: err} = await JobsActions.createJob(job)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
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});
}
}
);
export async function cancelJob(jobId, success, error) {
const {data, error: err} = await JobsActions.cancelJob(jobId)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
......@@ -8,15 +8,11 @@ import store from 'stores/redux_store.jsx';
const dispatch = store.dispatch;
const getState = store.getState;
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});
}
}
);
export async function deleteOAuthApp(id, success, error) {
const {data, error: err} = await IntegrationActions.deleteOAuthApp(id)(dispatch, getState);
if (data && success) {
success(data);
} else if (err && error) {
error({id: err.server_error_id, ...err});
}
}
......@@ -158,7 +158,7 @@ export function removeReaction(channelId, postId, emojiName) {
PostActions.removeReaction(postId, emojiName)(dispatch, getState);
}
export function createPost(post, files, success) {
export async function createPost(post, files, success) {
// parse message and emit emoji event
const emojis = post.message.match(EMOJI_PATTERN);
if (emojis) {
......@@ -168,34 +168,29 @@ export function createPost(post, files, success) {
}
}
PostActions.createPost(post, files)(dispatch, getState).then(() => {
if (post.root_id) {
PostStore.storeCommentDraft(post.root_id, null);
} else {
PostStore.storeDraft(post.channel_id, null);
}
await PostActions.createPost(post, files)(dispatch, getState);
if (post.root_id) {
PostStore.storeCommentDraft(post.root_id, null);
} else {
PostStore.storeDraft(post.channel_id, null);
}
if (success) {
success();
}
});
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 async function updatePost(post, success) {
const {data, error: err} = await PostActions.editPost(post)(dispatch, getState);
if (data && success) {
success();
} else if (err) {
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_ERROR,
err: {id: err.server_error_id, ...err},
method: 'editPost'
});
}
}
export function emitEmojiPosted(emoji) {
......@@ -205,7 +200,7 @@ export function emitEmojiPosted(emoji) {
});
}
export function deletePost(channelId, post, success) {
export async function deletePost(channelId, post, success) {
const {currentUserId} = getState().entities.users;
let hardDelete = false;
......@@ -213,38 +208,36 @@ export function deletePost(channelId, post, success) {
hardDelete = true;
}
PostActions.deletePost(post, hardDelete)(dispatch, getState).then(
() => {
if (post.id === getState().views.rhs.selectedPostId) {
dispatch({
type: ActionTypes.SELECT_POST,
postId: '',
channelId: ''
});
}
await PostActions.deletePost(post, hardDelete)(dispatch, getState);
dispatch({
type: PostTypes.REMOVE_POST,
data: post
});
if (post.id === getState().views.rhs.selectedPostId) {
dispatch({
type: ActionTypes.SELECT_POST,
postId: '',
channelId: ''
});
}
// Needed for search store
AppDispatcher.handleViewAction({
type: Constants.ActionTypes.REMOVE_POST,
post
});
dispatch({
type: PostTypes.REMOVE_POST,
data: 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);
}
// Needed for search store
AppDispatcher.handleViewAction({
type: Constants.ActionTypes.REMOVE_POST,
post
});
if (success) {
success();
}
}
);
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) {
......@@ -301,12 +294,13 @@ export function increasePostVisibility(channelId, focusedPostId) {
const page = Math.floor(currentPostVisibility / POST_INCREASE_AMOUNT);
let posts;
let result;
if (focusedPostId) {
posts = await PostActions.getPostsBefore(channelId, focusedPostId, page, POST_INCREASE_AMOUNT)(dispatch, getState);
result = await PostActions.getPostsBefore(channelId, focusedPostId, page, POST_INCREASE_AMOUNT)(dispatch, getState);
} else {
posts = await PostActions.getPosts(channelId, page, POST_INCREASE_AMOUNT)(doDispatch, doGetState);
result = await PostActions.getPosts(channelId, page, POST_INCREASE_AMOUNT)(doDispatch, doGetState);
}
const posts = result.data;
doDispatch({
type: ActionTypes.LOADING_POSTS,
......
This diff is collapsed.
This diff is collapsed.
......@@ -84,7 +84,7 @@ export default class ComplianceReports extends React.PureComponent {
job.end_at = Date.parse(this.refs.to.value);
this.props.actions.createComplianceReport(job).then(
(data) => {
({data}) => {
if (data) {
this.refs.emails.value = '';
this.refs.<