PLT-4431 Add post queuing to the webapp (#4800)

* Add post queuing to the webapp

* Add more abstraction
Этот коммит содержится в:
Joram Wilander
2016-12-21 16:41:05 -05:00
коммит произвёл Christopher Speller
родитель ba6e370ca7
Коммит 25d40bc98c
5 изменённых файлов: 56 добавлений и 14 удалений

Просмотреть файл

@@ -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) => {