git ssb

2+

ev / mvd



Tree: 7b050a701daa2eec7d77454ac88684a4addac641

Files: 7b050a701daa2eec7d77454ac88684a4addac641 / render.js

2140 bytesRaw
1var h = require('hyperscript')
2var markdown = require('ssb-markdown')
3var config = require('./config')()
4
5var sbot = require('./scuttlebot')
6var composer = require('./compose')
7
8var tools = require('./rendertools')
9
10module.exports = function (msg) {
11
12 var message = h('div.message')
13 if (msg.value.content.type == 'post') {
14 message.appendChild(tools.header(msg))
15 if (msg.value.content.root) {
16 message.appendChild(h('span', 're: ', tools.messageLink(msg.value.content.root)))
17 }
18 message.appendChild(h('div.message__body',
19 {innerHTML: markdown.block(msg.value.content.text, {toUrl: function (url, image) {
20 if(url[0] == '%' || url[0] == '@') return '#' + url
21 if(!image) return url
22 if(url[0] !== '&') return url
23 return config.blobsUrl + url
24 }})}
25 )
26 )
27 message.appendChild(h('button.btn', 'Reply', {
28 onclick: function () {
29 var compose = composer()
30 message.replaceChild(compose, message.lastElementChild)
31 }
32 }))
33 return message
34 } else if (msg.value.content.type == 'vote') {
35 message.appendChild(tools.header(msg))
36 var embed = msg.value.content.vote.link
37
38 var embedded = h('div.embedded')
39 sbot.get(embed, function (err, msg) {
40 if (err) {console.log('could not find message locally, try ooo?') }
41 msg.value = msg
42 msg.key = embed
43 if (msg.value.content.text) {
44 message.appendChild(embedded)
45 embedded.appendChild(tools.header(msg))
46 embedded.appendChild(h('div.message__body',
47 {innerHTML: markdown.block(msg.value.content.text.substring(0, 256) + '... ', {toUrl: function (url, image) {
48 if(url[0] == '@') return '#' + url
49 if(url[0] == '%') return '#' + url
50 if(!image) return url
51 if(url[0] !== '&') return url
52 return config.blobsUrl + url
53 }})}, tools.messageLink(msg.key)
54 ))
55 }
56 })
57 return message
58 } else {
59 //message.appendChild(tools.header(msg))
60 //message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
61 //return message
62 return
63 }
64}
65

Built with git-ssb-web