summaryrefslogtreecommitdiffstats
path: root/webapp/actions/post_actions.jsx
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2016-12-05 18:59:12 +0100
committerHarrison Healey <harrisonmhealey@gmail.com>2016-12-05 12:59:12 -0500
commitf27aca4b73119078f82cb86ddf6cae3ec5ccdf68 (patch)
tree8045ea8d961716169823de15adc616f5b9d1db70 /webapp/actions/post_actions.jsx
parentb9b986b7418472812a0391c2e83344553a15b4d9 (diff)
downloadchat-f27aca4b73119078f82cb86ddf6cae3ec5ccdf68.tar.gz
chat-f27aca4b73119078f82cb86ddf6cae3ec5ccdf68.tar.bz2
chat-f27aca4b73119078f82cb86ddf6cae3ec5ccdf68.zip
Move instances of Client.createPost() in components to an action (#4639)
* Move instances of Client.createPost() in components to an action * update per review, waiting for more review and see if this is the right way * update per code review * update code * remove comment per request
Diffstat (limited to 'webapp/actions/post_actions.jsx')
-rw-r--r--webapp/actions/post_actions.jsx34
1 files changed, 34 insertions, 0 deletions
diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
index 4f861c909..736aef033 100644
--- a/webapp/actions/post_actions.jsx
+++ b/webapp/actions/post_actions.jsx
@@ -272,3 +272,37 @@ export function removeReaction(channelId, postId, emojiName) {
AsyncClient.deleteReaction(channelId, reaction);
}
+
+export function createPost(post, doLoadPost, success, error) {
+ Client.createPost(post,
+ (data) => {
+ if (doLoadPost) {
+ loadPosts(post.channel_id);
+ } else {
+ PostStore.removePendingPost(post.pending_post_id);
+ }
+
+ AppDispatcher.handleServerAction({
+ type: ActionTypes.RECEIVED_POST,
+ post: data
+ });
+
+ if (success) {
+ success(data);
+ }
+ },
+
+ (err) => {
+ if (err.id === 'api.post.create_post.root_id.app_error') {
+ PostStore.removePendingPost(post.pending_post_id);
+ } else {
+ post.state = Constants.POST_FAILED;
+ PostStore.updatePendingPost(post);
+ }
+
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}