tangled
alpha
login
or
join now
evbogue.com
/
wiredove
1
fork
atom
a demonstration replicated social networking web app built with anproto
wiredove.net/
social
ed25519
protocols
1
fork
atom
overview
issues
pulls
pipelines
Send recent latest signatures on websocket connect
Everett Bogue
1 month ago
c78ece40
e682f381
+13
-17
1 changed file
expand all
collapse all
unified
split
websocket.js
+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
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
30
+
const parseOpenedTimestamp = (opened) => {
31
31
+
if (typeof opened !== 'string' || opened.length < 13) { return 0 }
32
32
+
const ts = Number.parseInt(opened.substring(0, 13), 10)
33
33
+
return Number.isFinite(ts) ? ts : 0
34
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
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
186
-
let selfPub = null
187
187
-
try {
188
188
-
selfPub = await apds.pubkey()
189
189
-
} catch (err) {
190
190
-
console.warn('pubkey failed', err)
191
191
-
selfPub = null
192
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
198
-
if (selfPub && pub === selfPub) {
199
199
-
const latest = await apds.getLatest(pub)
200
200
-
if (!latest) { continue }
201
201
-
if (latest.hash) {
202
202
-
ws.send(latest.hash)
203
203
-
} else if (latest.sig) {
204
204
-
const sigHash = await apds.hash(latest.sig)
205
205
-
ws.send(sigHash)
206
206
-
}
207
207
-
}
198
198
+
const latest = await apds.getLatest(pub)
199
199
+
if (!latest) { continue }
200
200
+
const openedTs = parseOpenedTimestamp(latest.opened)
201
201
+
if (!openedTs || now - openedTs > RECENT_LATEST_WINDOW_MS) { continue }
202
202
+
if (!latest.sig) { continue }
203
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()