1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-13 09:35:55 +00:00

sync modified scores via mutation observer

This commit is contained in:
Andrew Dolgov
2018-12-11 10:30:32 +03:00
parent 25ca144bb7
commit f3c04fc5d8
3 changed files with 51 additions and 42 deletions

View File

@@ -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);