summaryrefslogtreecommitdiff
path: root/js/Headlines.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-12-11 10:30:32 +0300
committerAndrew Dolgov <[email protected]>2018-12-11 10:30:32 +0300
commitf3c04fc5d85d1e411e731af95074e604e60abafb (patch)
tree5290f99e07312caba8fc4f3aacaed07168ab453d /js/Headlines.js
parent25ca144bb775f29dfc152a87c975f1fcdb367174 (diff)
sync modified scores via mutation observer
Diffstat (limited to 'js/Headlines.js')
-rwxr-xr-xjs/Headlines.js21
1 files changed, 20 insertions, 1 deletions
diff --git a/js/Headlines.js b/js/Headlines.js
index 64b3bd69d..2f056aef6 100755
--- a/js/Headlines.js
+++ b/js/Headlines.js
@@ -10,7 +10,7 @@ define(["dojo/_base/declare"], function (declare) {
const modified = [];
mutations.each((m) => {
- if (m.type == 'attributes' && m.attributeName == 'class') {
+ if (m.type == 'attributes' && ['class', 'data-score'].indexOf(m.attributeName) != -1) {
const row = m.target;
const id = row.getAttribute("data-article-id");
@@ -29,6 +29,8 @@ define(["dojo/_base/declare"], function (declare) {
hl.selected = row.hasClassName("Selected");
hl.active = row.hasClassName("active");
+ hl.score = row.getAttribute("data-score");
+
modified.push({id: hl.id, new: hl, old: hl_old, row: row});
}
}
@@ -52,6 +54,7 @@ define(["dojo/_base/declare"], function (declare) {
deselect: [],
activate: [],
deactivate: [],
+ rescore: {},
};
modified.each(function(m) {
@@ -69,6 +72,13 @@ define(["dojo/_base/declare"], function (declare) {
if (m.old.active != m.new.active)
m.new.active ? ops.activate.push(m.row) : ops.deactivate.push(m.row);
+
+ if (m.old.score != m.new.score) {
+ const score = m.new.score;
+
+ ops.rescore[score] = ops.rescore[score] || [];
+ ops.rescore[score].push(m.id);
+ }
});
ops.select.each((row) => {
@@ -117,6 +127,15 @@ define(["dojo/_base/declare"], function (declare) {
promises.push(xhrPost("backend.php",
{ op: "rpc", method: "catchupSelected", ids: ops.unread.toString(), cmode: 1}));
+ const scores = Object.keys(ops.rescore);
+
+ if (scores.length != 0) {
+ scores.each((score) => {
+ promises.push(xhrPost("backend.php",
+ { op: "article", method: "setScore", id: ops.rescore[score].toString(), score: score }));
+ });
+ }
+
if (promises.length > 0)
Promise.all([promises]).then(() => {
Feeds.requestCounters(true);