feat: sync checked read state to Dufflepud for cross-device badges #288
Reference in New Issue
Block a user
Delete Branch "userAdityaa/flotilla:fix/252-sync-checked-dufflepud"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
This change syncs the local checked map (read/badge timestamps per route) to Dufflepud via GET/POST /kv/checked with NIP-98 auth for #252. On login it pulls the remote map, merges with local using the later timestamp per path, then pushes the result. Local updates push the full map every 3 seconds. Failures are silent; without KV or network, behavior stays local-only.
closes #252
@@ -76,6 +78,107 @@ export const syncChecked = () => {})}const HTTP_AUTH = 27235Import this from welshman
@@ -79,0 +98,4 @@}return `Nostr ${btoa(JSON.stringify(nip98Auth))}`}Use the utils in welshman/lib
@@ -79,0 +116,4 @@if (!res.ok) {return}These two checks are redundant, just check res.ok
@@ -79,0 +118,4 @@return}const remote = JSON.parse(await res.text()) as Record<string, number>Use
parseJsonto avoid errors@@ -79,0 +122,4 @@checked.update($checked => {for (const [path, ts] of Object.entries(remote)) {if (ts > ($checked[path] || 0)) {Use
gtfrom welshman/lib to avoid nan/undefined related errors@@ -79,0 +131,4 @@})} catch {// pass}Don't wrap large blocks of code in a big try catch unless it's likely to fail. Scope this down to wrap the json parse or whatever is likely to actually fail.
@@ -79,0 +165,4 @@pushCheckedRemote()})}})Use
oncefrom welshman/libSorry, I wrote this before I realized what
readydoes, you should not actually use once here.a2b7b13b71to236e94652e236e94652eto37979582703797958270toed12e96403