-
Notifications
You must be signed in to change notification settings - Fork 0
/
avatar.js
47 lines (37 loc) · 1007 Bytes
/
avatar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { h } from './lib/h.js'
import { bogbot } from './bogbot.js'
import { vb } from './lib/vb.js'
import { decode } from './lib/base64.js'
import { gossip} from './gossip.js'
const pubkey = await bogbot.pubkey()
export const avatar = async (id) => {
const img = vb(decode(id), 256)
img.classList = 'avatar image' + id
const link = h('a', {href: '#' + id, classList: 'name' + id}, [id.substring(0, 7) + '...'])
const latest = await bogbot.getInfo(id)
if (latest.name) {
link.textContent = latest.name
}
if (latest.image) {
if (latest.image.length > 44) {
const blob = await bogbot.make(latest.image)
img.src = blob
latest.image = blob
await bogbot.saveInfo(id, latest)
} if (latest.image.length === 44) {
const blob = await bogbot.find(latest.image)
if (blob) {
img.src = blob
}
if (!blob) {
gossip(latest.image)
}
}
}
const span = h('span', [
img,
' ',
link,
])
return span
}