git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: c909de36e0325388afbaa5b1d6050b073e2fd3f8

Files: c909de36e0325388afbaa5b1d6050b073e2fd3f8 / render.js

3895 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}}}}], limit: 100, live: true}),
39 pull.drain(function (update) {
40 console.log(update)
41 if (update.sync) {
42 console.log('Waiting for new edits.')
43 } else {
44 var newMessage = h('div', tools.markdown(update.value.content.text))
45 var latest = h('div.message__body',
46 tools.timestamp(update, {edited: true}),
47 newMessage
48 )
49 message.replaceChild(latest, message.childNodes[message.childNodes.length - 2])
50 fallback.messageText = update.value.content.text
51 opts.updated = update.key
52 opts.original = msg.key
53 }
54 })
55 )
56
57 var buttons = h('div.buttons')
58 buttons.appendChild(h('button.btn', 'Reply', {
59 onclick: function () {
60 opts.type = 'post'
61 var r = message.childNodes.length - 1
62 delete opts.updated
63 delete opts.original
64 delete fallback.messageText
65 fallback.buttons = message.childNodes[r]
66 var compose = h('div.message#re:' + msg.key.substring(0, 44), composer(opts, fallback))
67 message.removeChild(message.childNodes[r])
68 message.parentNode.insertBefore(compose, message.nextSibling)
69 }
70 }))
71
72 if (msg.value.author == id)
73 buttons.appendChild(h('button.btn', 'Edit', {
74 onclick: function () {
75 opts.type = 'edit'
76 if (!fallback.messageText)
77 fallback.messageText = msg.value.content.text
78
79 if (!opts.updated)
80 opts.updated = msg.key
81 opts.original = msg.key
82
83 var r = message.childNodes.length - 1
84 fallback.buttons = message.childNodes[r]
85 message.removeChild(message.childNodes[r])
86 var compose = h('div#edit:' + msg.key.substring(0, 44), composer(opts, fallback))
87 message.replaceChild(compose, message.lastElementChild)
88 }
89 }))
90
91 message.appendChild(buttons)
92 return message
93
94 } else if (msg.value.content.type == 'vote') {
95 message.appendChild(tools.header(msg))
96 message.appendChild(h('span', 'Starred:'))
97 var embed = msg.value.content.vote.link
98
99 var embedded = h('div.embedded')
100 sbot.get(embed, function (err, msg) {
101 if (err) {console.log('could not find message locally, try ooo?') }
102 msg.value = msg
103 msg.key = embed
104 if (msg.value.content.text) {
105 message.appendChild(embedded)
106 embedded.appendChild(tools.header(msg))
107 embedded.appendChild(
108 h('div.message__body',
109 tools.markdown(msg.value.content.text.substring(0, 256) + '...'),
110 h('span', '[', h('a', {href: '#' + msg.key}, 'Full Post'), ']')
111 )
112 )
113 }
114 })
115 return message
116 } else {
117 //message.appendChild(tools.header(msg))
118 //message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
119 //return message
120 return h('div.invisibleMessage')
121 }
122}
123

Built with git-ssb-web