mirror of
https://github.com/wekan/wekan.git
synced 2026-11-07 11:02:33 -05:00
Keep FerretDB's bounded card window as a fetched snapshot, but observe the unrestricted indexed selector and diff a fresh window whenever a matching card changes. Publish added, changed and removed DDP messages so remote edits and cross-list moves render without a browser reload. Cover additions, edits, removals, unchanged cards, cleared fields and a forced-lazy browser scenario. Thanks to hmeunier95 and xet7 ! Fixes #6645,
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
function changedFields(previous, current) {
|
|
const changed = {};
|
|
const keys = new Set([...Object.keys(previous), ...Object.keys(current)]);
|
|
|
|
keys.delete('_id');
|
|
for (const key of keys) {
|
|
if (!EJSON.equals(previous[key], current[key])) {
|
|
changed[key] = Object.prototype.hasOwnProperty.call(current, key)
|
|
? current[key]
|
|
: undefined;
|
|
}
|
|
}
|
|
|
|
return changed;
|
|
}
|
|
|
|
function diffCardWindow(previousCards, currentCards) {
|
|
const previous = new Map(previousCards.map(card => [card._id, card]));
|
|
const current = new Map(currentCards.map(card => [card._id, card]));
|
|
const added = [];
|
|
const changed = [];
|
|
const removed = [];
|
|
|
|
for (const card of currentCards) {
|
|
const oldCard = previous.get(card._id);
|
|
if (!oldCard) {
|
|
added.push(card);
|
|
continue;
|
|
}
|
|
|
|
const fields = changedFields(oldCard, card);
|
|
if (Object.keys(fields).length > 0) changed.push({ _id: card._id, fields });
|
|
}
|
|
|
|
for (const card of previousCards) {
|
|
if (!current.has(card._id)) removed.push(card._id);
|
|
}
|
|
|
|
return { added, changed, removed };
|
|
}
|
|
|
|
module.exports = { diffCardWindow };
|