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
Refresh timestamps on visibility
Everett Bogue
2 months ago
2a89d306
6a70dc8a
+43
-2
1 changed file
expand all
collapse all
unified
split
render.js
+43
-2
render.js
···
11
11
const EDIT_CACHE_TTL_MS = 5000
12
12
13
13
const editState = new Map()
14
14
+
const timestampRefreshMs = 60000
15
15
+
const visibleTimestamps = new Map()
16
16
+
let timestampObserver = null
14
17
15
18
const getEditState = (hash) => {
16
19
if (!editState.has(hash)) {
17
20
editState.set(hash, { currentIndex: null, userNavigated: false })
18
21
}
19
22
return editState.get(hash)
23
23
+
}
24
24
+
25
25
+
const refreshTimestamp = async (element, timestamp) => {
26
26
+
if (!document.body.contains(element)) {
27
27
+
const stored = visibleTimestamps.get(element)
28
28
+
if (stored) { clearInterval(stored.intervalId) }
29
29
+
visibleTimestamps.delete(element)
30
30
+
return
31
31
+
}
32
32
+
element.textContent = await apds.human(timestamp)
33
33
+
}
34
34
+
35
35
+
const observeTimestamp = (element, timestamp) => {
36
36
+
if (!element) { return }
37
37
+
element.dataset.timestamp = timestamp
38
38
+
if (!timestampObserver) {
39
39
+
timestampObserver = new IntersectionObserver((entries) => {
40
40
+
entries.forEach(entry => {
41
41
+
const target = entry.target
42
42
+
const ts = target.dataset.timestamp
43
43
+
if (!ts) { return }
44
44
+
if (entry.isIntersecting) {
45
45
+
refreshTimestamp(target, ts)
46
46
+
if (!visibleTimestamps.has(target)) {
47
47
+
const intervalId = setInterval(() => {
48
48
+
refreshTimestamp(target, ts)
49
49
+
}, timestampRefreshMs)
50
50
+
visibleTimestamps.set(target, { intervalId })
51
51
+
}
52
52
+
} else {
53
53
+
const stored = visibleTimestamps.get(target)
54
54
+
if (stored) { clearInterval(stored.intervalId) }
55
55
+
visibleTimestamps.delete(target)
56
56
+
}
57
57
+
})
58
58
+
})
59
59
+
}
60
60
+
timestampObserver.observe(element)
20
61
}
21
62
22
63
const renderBody = async (body, replyHash) => {
···
363
404
syncPrevious(yaml)
364
405
365
406
const ts = h('a', {href: '#' + hash}, [humanTime])
366
366
-
setInterval(async () => {ts.textContent = await apds.human(timestamp)}, 1000)
407
407
+
observeTimestamp(ts, timestamp)
367
408
368
409
const qrTarget = h('div', {id: 'qr-target' + hash, classList: 'qr-target', style: 'margin: 8px auto 0 auto; text-align: center; max-width: 400px;'})
369
410
const { raw, rawDiv } = buildRawControls(blob, opened, contentBlob)
···
399
440
}
400
441
401
442
const ts = h('a', {href: '#' + hash}, [humanTime])
402
402
-
setInterval(async () => {ts.textContent = await apds.human(timestamp)}, 1000)
443
443
+
observeTimestamp(ts, timestamp)
403
444
404
445
const pubkey = await apds.pubkey()
405
446
const canEdit = pubkey && pubkey === author