PLT-4431 Add post queuing to the webapp (#4800)
* Add post queuing to the webapp * Add more abstraction
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
ba6e370ca7
Коммит
25d40bc98c
@@ -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) => {
|
||||
|
||||
Ссылка в новой задаче
Block a user