mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Member Settings / "Mark cards changed since I last opened them", off by default. With it on, a minicard gets a blue edge when anything of the card changed after the member last opened it - its own fields (title, description, dates, labels, members), its checklists and their items, attachments and comments - until they open it. Turning it on records when, so the cards a member never opened are not all marked at once, and closing a card counts as having seen it, so their own edits made while it was open do not mark it. models/lib/unreadChanges.js takes the latest change across those documents and compares it; tests/unreadChanges.test.cjs covers each kind of change, seen since, off, older than the switch and the wiring. The new strings are English placeholders until the next translation pass. Thanks to Lacour20, martinpospech and xet7 ! Fixes #2111, Fixes #1604.
38 lines
1.7 KiB
JavaScript
38 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
// #2111 / #1604: every change to any field of a card - title, description,
|
|
// attachments, checklists, members, dates, labels, comments - marks it unread
|
|
// on the minicard, until the member opens it, when Member Settings / "Mark
|
|
// cards changed since I last opened them" is on (off by default).
|
|
//
|
|
// The card's own fields bump its modifiedAt; checklists, their items,
|
|
// attachments and comments are their own documents, so the latest of all of
|
|
// them is the card's last change. A card is unread when that is after the
|
|
// member last opened it - and after the moment they turned the switch on, so
|
|
// switching it on does not mark every card they never opened.
|
|
// Pure: tests/unreadChanges.test.cjs.
|
|
|
|
function time(value) {
|
|
const t = value ? new Date(value).getTime() : NaN;
|
|
return Number.isNaN(t) ? 0 : t;
|
|
}
|
|
|
|
function latestChangeTime({ card, checklists = [], items = [], attachments = [], comments = [] } = {}) {
|
|
let latest = 0;
|
|
const take = v => { const t = time(v); if (t > latest) latest = t; };
|
|
if (card) { take(card.modifiedAt); take(card.dateLastActivity); take(card.createdAt); }
|
|
for (const c of checklists) if (c) { take(c.modifiedAt); take(c.createdAt); }
|
|
for (const i of items) if (i) { take(i.modifiedAt); take(i.createdAt); }
|
|
for (const a of attachments) if (a) { take(a.uploadedAt); take(a.updatedAt); take(a.createdAt); }
|
|
for (const m of comments) if (m) { take(m.modifiedAt); take(m.createdAt); }
|
|
return latest;
|
|
}
|
|
|
|
function hasUnreadChanges(latest, { lastViewedAt, enabledAt } = {}) {
|
|
if (!enabledAt) return false;
|
|
const since = Math.max(time(lastViewedAt), time(enabledAt));
|
|
return latest > since;
|
|
}
|
|
|
|
module.exports = { latestChangeTime, hasUnreadChanges };
|