diff options
| author | Adam Soltys <[email protected]> | 2026-09-24 08:16:17 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-09-24 08:16:17 -0700 |
| commit | cdca3fa061c856f9063aadfabf1c1e713f512123 (patch) | |
| tree | 79f398e0d9570d7fc9f9947ce8e7de3e4e5024f8 /src/thread-cache.js | |
| parent | 7fae8198ef36396e4c65e66597d8e6e6f74ab1d1 (diff) | |
| download | coinosv3-cdca3fa061c856f9063aadfabf1c1e713f512123.tar.gz coinosv3-cdca3fa061c856f9063aadfabf1c1e713f512123.zip | |
Paint cached thread counts and header hat on refresh
Diffstat (limited to 'src/thread-cache.js')
| -rw-r--r-- | src/thread-cache.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/thread-cache.js b/src/thread-cache.js index f255e3a..e11660e 100644 --- a/src/thread-cache.js +++ b/src/thread-cache.js @@ -23,6 +23,11 @@ const savedProfile = (p) => { } return out; }; +const savedCounts = (c) => { + if (!c || typeof c !== 'object') return null; + const count = (n) => Number.isSafeInteger(n) && n >= 0 && n <= 1_000_000_000 ? n : 0; + return { likes: count(c.likes), boosts: count(c.boosts), sats: count(c.sats) }; +}; export function createThreadStore(storage) { if (storage === undefined) { try { storage = globalThis.localStorage; } catch {} } @@ -41,7 +46,7 @@ export function createThreadStore(storage) { find(id) { return read().find((c) => c.rootId === id || c.replies.some((e) => e.id === id)) || null; }, - save(thread, focusId, profiles = {}) { + save(thread, focusId, profiles = {}, counts = {}) { if (!validNote(thread.root)) return; const events = new Map([thread.root, ...thread.replies.filter(validNote)].map((e) => [e.id, e])); const keep = new Map([[thread.root.id, thread.root]]); @@ -71,8 +76,13 @@ export function createThreadStore(storage) { } if (face) faces[pk] = face; } + const tallies = {}; + for (const id of keep.keys()) { + const tally = savedCounts(counts[id] || previous?.counts?.[id]); + if (tally) tallies[id] = tally; + } const entry = { rootId: thread.root.id, root: savedNote(thread.root), - profiles: faces, + profiles: faces, counts: tallies, replies: [...keep.values()].filter((e) => e.id !== thread.root.id).map(savedNote) }; const entries = [entry, ...read().filter((c) => c.rootId !== entry.rootId)].slice(0, MAX_THREADS); let json = JSON.stringify(entries); |
