diff options
Diffstat (limited to 'webapp/actions')
-rw-r--r-- | webapp/actions/post_actions.jsx | 49 |
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) => { |