-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomposer.js
75 lines (63 loc) · 2.47 KB
/
composer.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { bogbot } from 'bogbot'
import { render } from './render.js'
import { blast } from './gossip.js'
import { h } from 'h'
import { avatarSpan, nameSpan } from './profile.js'
import { ntfy } from './ntfy.js'
export const composer = async (sig) => {
const obj = {}
if (sig) {
const hash = await bogbot.hash(sig)
obj.replyHash = hash
obj.replyAuthor = sig.substring(0, 44)
const opened = await bogbot.open(sig)
const msg = await bogbot.parseYaml(await bogbot.get(opened.substring(13)))
if (msg.name) { obj.replyName = msg.name }
if (msg.body) {obj.replyBody = msg.body}
}
const replyDiv = h('div')
if (obj.replyHash) {
const replySymbol = h('span', {classList: 'material-symbols-outlined'}, ['Subdirectory_Arrow_left'])
const author = h('a', {href: '#' + obj.replyAuthor}, [obj.replyAuthor.substring(0, 10)])
const replyContent = h('a', {href: '#' + obj.replyHash}, [obj.replyHash.substring(0, 10)])
replyDiv.appendChild(author)
if (obj.replyName) { author.textContent = obj.replyName}
if (obj.replyBody) { replyContent.textContent = obj.replyBody.substring(0, 10) + '...'}
replyDiv.appendChild(replySymbol)
replyDiv.appendChild(replyContent)
}
const textarea = h('textarea', {placeholder: 'Write a message'})
const cancel = h('a', {classList: 'material-symbols-outlined', onclick: () => {
div.parentNode.removeChild(div)
}
}, ['Cancel'])
const replyObj = {}
if (sig) {
replyObj.reply = await bogbot.hash(sig)
replyObj.replyto = sig.substring(0, 44)
}
const button = h('button', {classList: 'material-symbols-outlined', style: 'margin-left: auto; margin-right: 0px; display: block;', onclick: async () => {
const published = await bogbot.compose(textarea.value, replyObj)
textarea.value = ''
const scroller = document.getElementById('scroller')
const signed = await bogbot.get(published)
await blast(signed)
await ntfy(signed)
const hashDiv = await render.hash(published)
div.parentNode.appendChild(hashDiv)
div.remove()
}}, ['Send'])
const pubkey = await bogbot.pubkey()
const textareaDiv = h('div', {style: 'margin-left: 57px;'}, [
textarea,
button
])
const div = h('div', {classList: 'message'}, [
h('span', {style: 'float: right;'}, [h('code', {classList: 'pubkey'}, [pubkey.substring(0, 10)]), ' ', cancel]),
h('span', {style: 'float: left;'}, [await avatarSpan()]),
await nameSpan(),
replyDiv,
textareaDiv,
])
return div
}