summaryrefslogtreecommitdiffstats
path: root/webapp
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-12-21 16:41:05 -0500
committerChristopher Speller <crspeller@gmail.com>2016-12-21 16:41:05 -0500
commit25d40bc98c71f526c256076f0c21c04bbb4e99e7 (patch)
treea674c237a41598854e44bc7fef986f71229d69ba /webapp
parentba6e370ca71abacaa30234cb164427d27c86df13 (diff)
downloadchat-25d40bc98c71f526c256076f0c21c04bbb4e99e7.tar.gz
chat-25d40bc98c71f526c256076f0c21c04bbb4e99e7.tar.bz2
chat-25d40bc98c71f526c256076f0c21c04bbb4e99e7.zip
PLT-4431 Add post queuing to the webapp (#4800)
* Add post queuing to the webapp * Add more abstraction
Diffstat (limited to 'webapp')
-rw-r--r--webapp/actions/post_actions.jsx49
-rw-r--r--webapp/components/create_comment.jsx5
-rw-r--r--webapp/components/create_post.jsx5
-rw-r--r--webapp/components/post_view/components/pending_post_options.jsx7
-rw-r--r--webapp/components/rhs_thread.jsx4
5 files changed, 56 insertions, 14 deletions
diff --git a/webapp/actions/post_actions.jsx b/webapp/actions/post_actions.jsx
index 71b9e826e..207f0143d 100644
--- a/webapp/actions/post_actions.jsx
+++ b/webapp/actions/post_actions.jsx
@@ -280,6 +280,55 @@ export function removeReaction(channelId, postId, emojiName) {
AsyncClient.deleteReaction(channelId, reaction);
}
+const postQueue = [];
+
+export function queuePost(post, doLoadPost, success, error) {
+ postQueue.push(
+ createPost.bind(
+ this,
+ post,
+ doLoadPost,
+ (data) => {
+ if (success) {
+ success(data);
+ }
+
+ postSendComplete();
+ },
+ (err) => {
+ if (error) {
+ error(err);
+ }
+
+ postSendComplete();
+ }
+ )
+ );
+
+ sendFirstPostInQueue();
+}
+
+// Remove the completed post from the queue and send the next one
+function postSendComplete() {
+ postQueue.shift();
+ sendNextPostInQueue();
+}
+
+// Start sending posts if a new queue has started
+function sendFirstPostInQueue() {
+ if (postQueue.length === 1) {
+ sendNextPostInQueue();
+ }
+}
+
+// Send the next post in the queue if there is one
+function sendNextPostInQueue() {
+ const nextPostAction = postQueue[0];
+ if (nextPostAction) {
+ nextPostAction();
+ }
+}
+
export function createPost(post, doLoadPost, success, error) {
Client.createPost(post,
(data) => {
diff --git a/webapp/components/create_comment.jsx b/webapp/components/create_comment.jsx
index 3bd8d5d1c..8ecda6777 100644
--- a/webapp/components/create_comment.jsx
+++ b/webapp/components/create_comment.jsx
@@ -196,10 +196,7 @@ export default class CreateComment extends React.Component {
GlobalActions.emitUserCommentedEvent(post);
- PostActions.createPost(post, false,
- () => {
- // DO nothing.
- },
+ PostActions.queuePost(post, false, null,
(err) => {
if (err.id === 'api.post.create_post.root_id.app_error') {
this.showPostDeletedModal();
diff --git a/webapp/components/create_post.jsx b/webapp/components/create_post.jsx
index 4ec2bec38..75ff5a822 100644
--- a/webapp/components/create_post.jsx
+++ b/webapp/components/create_post.jsx
@@ -161,10 +161,7 @@ export default class CreatePost extends React.Component {
GlobalActions.emitUserPostedEvent(post);
- PostActions.createPost(post, false,
- () => {
- // DO nothing.
- },
+ PostActions.queuePost(post, false, null,
(err) => {
if (err.id === 'api.post.create_post.root_id.app_error') {
// this should never actually happen since you can't reply from this textbox
diff --git a/webapp/components/post_view/components/pending_post_options.jsx b/webapp/components/post_view/components/pending_post_options.jsx
index d9f98e958..3c78b8b9b 100644
--- a/webapp/components/post_view/components/pending_post_options.jsx
+++ b/webapp/components/post_view/components/pending_post_options.jsx
@@ -3,7 +3,7 @@
import PostStore from 'stores/post_store.jsx';
-import {createPost} from 'actions/post_actions.jsx';
+import {queuePost} from 'actions/post_actions.jsx';
import Constants from 'utils/constants.jsx';
@@ -22,10 +22,7 @@ export default class PendingPostOptions extends React.Component {
e.preventDefault();
var post = this.props.post;
- createPost(post, true,
- () => {
- // DO nothing.
- },
+ queuePost(post, true, null,
(err) => {
if (err.id === 'api.post.create_post.root_id.app_error') {
this.showPostDeletedModal();
diff --git a/webapp/components/rhs_thread.jsx b/webapp/components/rhs_thread.jsx
index 658cba288..8fd49dd25 100644
--- a/webapp/components/rhs_thread.jsx
+++ b/webapp/components/rhs_thread.jsx
@@ -332,10 +332,12 @@ export default class RhsThread extends React.Component {
status = this.state.statuses[p.id] || 'offline';
}
+ const keyPrefix = comPost.id ? comPost.id : comPost.pending_post_id;
+
return (
<Comment
ref={comPost.id}
- key={comPost.id + 'commentKey'}
+ key={keyPrefix + 'commentKey'}
post={comPost}
user={p}
currentUser={this.props.currentUser}