a demonstration replicated social networking web app built with anproto wiredove.net/
social ed25519 protocols

Send recent latest signatures on websocket connect

+13 -17
+13 -17
websocket.js
··· 6 6 const pubs = new Set() 7 7 const wsBackoff = new Map() 8 8 const HTTP_POLL_INTERVAL_MS = 5000 9 + const RECENT_LATEST_WINDOW_MS = 24 * 60 * 60 * 1000 9 10 const httpState = { 10 11 baseUrl: null, 11 12 ready: false, ··· 26 27 } 27 28 28 29 const isHash = (msg) => typeof msg === 'string' && msg.length === 44 30 + const parseOpenedTimestamp = (opened) => { 31 + if (typeof opened !== 'string' || opened.length < 13) { return 0 } 32 + const ts = Number.parseInt(opened.substring(0, 13), 10) 33 + return Number.isFinite(ts) ? ts : 0 34 + } 29 35 30 36 const handleIncoming = async (msg) => { 31 37 noteReceived(msg) ··· 176 182 pubs.add(ws) 177 183 resetBackoff() 178 184 wsReadyResolver?.() 185 + const now = Date.now() 179 186 let p = [] 180 187 try { 181 188 p = await apds.getPubkeys() || [] ··· 183 190 console.warn('getPubkeys failed', err) 184 191 p = [] 185 192 } 186 - let selfPub = null 187 - try { 188 - selfPub = await apds.pubkey() 189 - } catch (err) { 190 - console.warn('pubkey failed', err) 191 - selfPub = null 192 - } 193 193 const moderation = await getModerationState() 194 194 const blocked = new Set(moderation.blockedAuthors || []) 195 195 for (const pub of p) { 196 196 if (blocked.has(pub)) { continue } 197 197 ws.send(pub) 198 - if (selfPub && pub === selfPub) { 199 - const latest = await apds.getLatest(pub) 200 - if (!latest) { continue } 201 - if (latest.hash) { 202 - ws.send(latest.hash) 203 - } else if (latest.sig) { 204 - const sigHash = await apds.hash(latest.sig) 205 - ws.send(sigHash) 206 - } 207 - } 198 + const latest = await apds.getLatest(pub) 199 + if (!latest) { continue } 200 + const openedTs = parseOpenedTimestamp(latest.opened) 201 + if (!openedTs || now - openedTs > RECENT_LATEST_WINDOW_MS) { continue } 202 + if (!latest.sig) { continue } 203 + ws.send(latest.sig) 208 204 } 209 205 //below sends everything in the client to a dovepub pds server 210 206 //const log = await apds.query()