git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: b0af4a5b196f6a3c00d7b9e44537ccdf1248230e

Files: b0af4a5b196f6a3c00d7b9e44537ccdf1248230e / render.js

3639 bytesRaw
1var h = require('hyperscript')
2var pull = require('pull-stream')
3var human = require('human-time')
4
5var sbot = require('./scuttlebot')
6var composer = require('./compose')
7var tools = require('./tools')
8
9var config = require('./config')()
10var id = require('./keys').id
11
12
13module.exports = function (msg) {
14 console.log(msg)
15 var message = h('div.message#' + msg.key.substring(0, 44))
16 if (msg.value.content.type == 'post') {
17 var opts = {
18 type: 'post',
19 branch: msg.key
20 }
21 var fallback = {}
22
23
24 if (msg.value.content.root)
25 opts.root = msg.value.content.root
26 else
27 opts.root = msg.key
28
29 message.appendChild(tools.header(msg))
30
31 if (msg.value.content.root)
32 message.appendChild(h('span', 're: ', tools.messageLink(msg.value.content.root)))
33
34 message.appendChild(h('div.message__body', tools.markdown(msg.value.content.text)))
35
36
37 pull(
38 sbot.query({query: [{$filter: {value: {content: {type: 'edit', original: msg.key}}}}]}),
39 pull.drain(function (update) {
40 var newMessage = h('div', tools.markdown(update.value.content.text))
41 var latest = h('div.message__body',
42 tools.timestamp(update, {edited: true}),
43 newMessage
44 )
45 message.replaceChild(latest, message.childNodes[message.childNodes.length - 2])
46 fallback.messageText = update.value.content.text
47 opts.updated = update.key
48 opts.original = msg.key
49 })
50 )
51
52 var buttons = h('div.buttons')
53 buttons.appendChild(h('button.btn', 'Reply', {
54 onclick: function () {
55 var r = message.childNodes.length - 1
56 delete opts.updated
57 delete opts.original
58 delete fallback.messageText
59 fallback.buttons = message.childNodes[r]
60 var compose = h('div.message#re:' + msg.key.substring(0, 44), composer(opts, fallback))
61 message.parentNode.insertBefore(compose, message.nextSibling)
62 }
63 }))
64
65 if (msg.value.author == id)
66 buttons.appendChild(h('button.btn', 'Edit', {
67 onclick: function () {
68 opts.type = 'edit'
69 if (!fallback.messageText)
70 fallback.messageText = msg.value.content.text
71
72 if (!opts.updated)
73 opts.updated = msg.key
74 opts.original = msg.key
75
76 var r = message.childNodes.length - 1
77 fallback.buttons = message.childNodes[r]
78 message.removeChild(message.childNodes[r])
79 var compose = h('div#edit:' + msg.key.substring(0, 44), composer(opts, fallback))
80 message.replaceChild(compose, message.lastElementChild)
81 }
82 }))
83
84 message.appendChild(buttons)
85 return message
86
87 } else if (msg.value.content.type == 'vote') {
88 message.appendChild(tools.header(msg))
89 message.appendChild(h('span', 'Starred:'))
90 var embed = msg.value.content.vote.link
91
92 var embedded = h('div.embedded')
93 sbot.get(embed, function (err, msg) {
94 if (err) {console.log('could not find message locally, try ooo?') }
95 msg.value = msg
96 msg.key = embed
97 if (msg.value.content.text) {
98 message.appendChild(embedded)
99 embedded.appendChild(tools.header(msg))
100 embedded.appendChild(
101 h('div.message__body',
102 tools.markdown(msg.value.content.text.substring(0, 256) + '...'),
103 h('span', '[', h('a', {href: '#' + msg.key}, 'Full Post'), ']')
104 )
105 )
106 }
107 })
108 return message
109 } else {
110 //message.appendChild(tools.header(msg))
111 //message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
112 //return message
113 return h('div.invisibleMessage')
114 }
115}
116

Built with git-ssb-web