summaryrefslogtreecommitdiffstats
path: root/webapp/actions
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/actions
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/actions')
-rw-r--r--webapp/actions/post_actions.jsx49
1 files changed, 49 insertions, 0 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) => {