From fd6f3e7f073beb648ee25e08263ea9b1e6149947 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 11 Dec 2018 08:48:24 +0300 Subject: syncModified: request counters once after all xhr promises resolve --- js/Headlines.js | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/js/Headlines.js b/js/Headlines.js index 0c0a7f56a..1db858bb7 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -99,31 +99,30 @@ define(["dojo/_base/declare"], function (declare) { cb.attr('checked', false); }); + const promises = []; + if (ops.tmark.length != 0) - xhrPost("backend.php", - { op: "rpc", method: "markSelected", ids: ops.tmark.toString(), cmode: 2}, (transport) => { - App.handleRpcJson(transport); - }); + promises.push(xhrPost("backend.php", + { op: "rpc", method: "markSelected", ids: ops.tmark.toString(), cmode: 2})); if (ops.tpub.length != 0) - xhrPost("backend.php", - { op: "rpc", method: "publishSelected", ids: ops.tpub.toString(), cmode: 2}, (transport) => { - App.handleRpcJson(transport); - }); + promises.push(xhrPost("backend.php", + { op: "rpc", method: "publishSelected", ids: ops.tpub.toString(), cmode: 2})); if (ops.read.length != 0) - xhrPost("backend.php", - { op: "rpc", method: "catchupSelected", ids: ops.read.toString(), cmode: 0}, (transport) => { - App.handleRpcJson(transport); - }); + promises.push(xhrPost("backend.php", + { op: "rpc", method: "catchupSelected", ids: ops.read.toString(), cmode: 0})); if (ops.unread.length != 0) - xhrPost("backend.php", - { op: "rpc", method: "catchupSelected", ids: ops.unread.toString(), cmode: 1}, (transport) => { - App.handleRpcJson(transport); - }); + promises.push(xhrPost("backend.php", + { op: "rpc", method: "catchupSelected", ids: ops.unread.toString(), cmode: 1})); + + if (promises.length > 0) + Promise.all([promises]).then(() => { + Feeds.requestCounters(true); + }); - }, + }, click: function (event, id, in_body) { in_body = in_body || false; -- cgit v1.2.3