git ssb

2+

ev / mvd



Tree: 4d502238fb284fe259d0fd41f1f3fda185b674f8

Files: 4d502238fb284fe259d0fd41f1f3fda185b674f8 / render.js

3252 bytesRaw
1var h = require('hyperscript')
2
3var human = require('human-time')
4var ref = require('ssb-ref')
5var avatar = require('./avatar')
6
7var markdown = require('ssb-markdown')
8var config = require('./config')()
9
10var render = require('./render')
11
12function rawJSON (obj) {
13 return JSON.stringify(obj, null, 2)
14 .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/)
15 .map(function (e) {
16 if(ref.isMsg(e) || ref.isFeed(e) || ref.isBlob(e)) {
17 return h('a', {href: '#' + e}, e)
18 }
19 return e
20 })
21}
22
23module.exports = function (msg) {
24 if (msg.value.content.type == 'post') {
25 return h('div.message',
26 h('span.avatar',
27 h('a', {href: '#' + msg.value.author},
28 h('span.avatar--small', avatar.image(msg.value.author)),
29 avatar.name(msg.value.author)
30 )
31 ),
32 h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))),
33 h('div.message__body',
34 {innerHTML: markdown.block(msg.value.content.text, {toUrl: function (url, image) {
35 if(url[0] == '@') return '#' + url
36 if(url[0] == '%') return '#' + url
37 if(!image) return url
38 if(url[0] !== '&') return url
39 return config.blobsurl + url
40 }})}
41 )
42 )
43 } else if (msg.value.content.type == 'vote') {
44 var embed = msg.value.content.vote.link
45
46 var embedded = h('div.embedded')
47
48 sbot.get(embed, function (err, msg) {
49 if (err) {console.log('could not find message locally, try ooo?') }
50 console.log(msg)
51 msg.value = msg
52 msg.key = embed
53 if (msg.value.content.text) {
54 embedded.appendChild(
55 h('div.message',
56 h('span.avatar',
57 h('a', {href: '#' + msg.value.author},
58 h('span.avatar--small', avatar.image(msg.value.author)),
59 avatar.name(msg.value.author)
60 )
61 ),
62 h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))),
63 h('div.message__body',
64 {innerHTML: markdown.block(msg.value.content.text, {toUrl: function (url, image) {
65 if(url[0] == '@') return '#' + url
66 if(url[0] == '%') return '#' + url
67 if(!image) return url
68 if(url[0] !== '&') return url
69 return config.blobsUrl + url
70 }})}
71 )
72 )
73 )
74 }
75 })
76 return h('div.message',
77 h('span.avatar',
78 h('a', {href: '#' + msg.value.author},
79 h('span.avatar--small', avatar.image(msg.value.author)),
80 avatar.name(msg.value.author)
81 ), h('img.emoji', {src: config.emojiUrl + 'star.png'})
82 ),
83 h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))),
84 h('div.message__body', embedded)
85 )
86 } else {
87 return h('div.message',
88 h('span.avatar',
89 h('a', {href: '#' + msg.value.author},
90 h('span.avatar--small', avatar.image(msg.value.author)),
91 avatar.name(msg.value.author)
92 )
93 ),
94 h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))),
95 h('pre', rawJSON(msg.value.content))
96 )
97 }
98}
99

Built with git-ssb-web