feat: sync checked read state to Dufflepud for cross-device badges #288

Merged
hodlbod merged 1 commits from userAdityaa/flotilla:fix/252-sync-checked-dufflepud into dev 2026-05-29 21:15:57 +00:00
Collaborator

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

### 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
hodlbod reviewed 2026-05-29 15:39:20 +00:00
@@ -76,6 +78,107 @@ export const syncChecked = () => {
})
}
const HTTP_AUTH = 27235
Owner

Import this from welshman

Import this from welshman
@@ -79,0 +98,4 @@
}
return `Nostr ${btoa(JSON.stringify(nip98Auth))}`
}
Owner

Use the utils in welshman/lib

Use the utils in welshman/lib
hodlbod marked this conversation as resolved
@@ -79,0 +116,4 @@
if (!res.ok) {
return
}
Owner

These two checks are redundant, just check res.ok

These two checks are redundant, just check res.ok
hodlbod marked this conversation as resolved
@@ -79,0 +118,4 @@
return
}
const remote = JSON.parse(await res.text()) as Record<string, number>
Owner

Use parseJson to avoid errors

Use `parseJson` to avoid errors
hodlbod marked this conversation as resolved
@@ -79,0 +122,4 @@
checked.update($checked => {
for (const [path, ts] of Object.entries(remote)) {
if (ts > ($checked[path] || 0)) {
Owner

Use gt from welshman/lib to avoid nan/undefined related errors

Use `gt` from welshman/lib to avoid nan/undefined related errors
hodlbod marked this conversation as resolved
@@ -79,0 +131,4 @@
})
} catch {
// pass
}
Owner

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.

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.
hodlbod marked this conversation as resolved
@@ -79,0 +165,4 @@
pushCheckedRemote()
})
}
})
Owner

Use once from welshman/lib

Use `once` from welshman/lib
Owner

Sorry, I wrote this before I realized what ready does, you should not actually use once here.

Sorry, I wrote this before I realized what `ready` does, you should not actually use once here.
hodlbod marked this conversation as resolved
userAdityaa force-pushed fix/252-sync-checked-dufflepud from a2b7b13b71 to 236e94652e 2026-05-29 18:27:04 +00:00 Compare
userAdityaa force-pushed fix/252-sync-checked-dufflepud from 236e94652e to 3797958270 2026-05-29 19:25:15 +00:00 Compare
hodlbod added 1 commit 2026-05-29 21:15:51 +00:00
hodlbod force-pushed fix/252-sync-checked-dufflepud from 3797958270 to ed12e96403 2026-05-29 21:15:51 +00:00 Compare
hodlbod merged commit 77256462c5 into dev 2026-05-29 21:15:57 +00:00
hodlbod deleted branch fix/252-sync-checked-dufflepud 2026-05-29 21:15:57 +00:00
Sign in to join this conversation.