git ssb

2+

ev / mvd



Commit 4d502238fb284fe259d0fd41f1f3fda185b674f8

render votes as shared messages

Ev Bogue committed on 4/25/2018, 5:06:30 PM
Parent: 1245ae4906c27c7046c345c5183022b5e4df1928

Files changed

render.jschanged
views.jschanged
render.jsView
@@ -6,8 +6,10 @@
66
77 var markdown = require('ssb-markdown')
88 var config = require('./config')()
99
10 +var render = require('./render')
11 +
1012 function rawJSON (obj) {
1113 return JSON.stringify(obj, null, 2)
1214 .split(/([%@&][a-zA-Z0-9\/\+]{43}=*\.[\w]+)/)
1315 .map(function (e) {
@@ -19,9 +21,9 @@
1921 }
2022
2123 module.exports = function (msg) {
2224 if (msg.value.content.type == 'post') {
23- return h('div.message__content',
25 + return h('div.message',
2426 h('span.avatar',
2527 h('a', {href: '#' + msg.value.author},
2628 h('span.avatar--small', avatar.image(msg.value.author)),
2729 avatar.name(msg.value.author)
@@ -29,16 +31,61 @@
2931 ),
3032 h('span.timestamp', h('a', {href: '#' + msg.key}, human(new Date(msg.value.timestamp)))),
3133 h('div.message__body',
3234 {innerHTML: markdown.block(msg.value.content.text, {toUrl: function (url, image) {
35 + if(url[0] == '@') return '#' + url
36 + if(url[0] == '%') return '#' + url
3337 if(!image) return url
3438 if(url[0] !== '&') return url
3539 return config.blobsurl + url
3640 }})}
3741 )
3842 )
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 + )
3986 } else {
40- return h('div.message__content',
87 + return h('div.message',
4188 h('span.avatar',
4289 h('a', {href: '#' + msg.value.author},
4390 h('span.avatar--small', avatar.image(msg.value.author)),
4491 avatar.name(msg.value.author)
views.jsView
@@ -17,9 +17,9 @@
1717 function createStream (opts) {
1818 return pull(
1919 More(sbot.createLogStream, opts),
2020 pull.map(function (msg) {
21- return h('div.message', render(msg))
21 + return h('div', render(msg))
2222 })
2323 )
2424 }
2525
@@ -78,9 +78,9 @@
7878 function createStream (opts) {
7979 return pull(
8080 More(sbot.userStream, opts, ['value', 'sequence']),
8181 pull.map(function (msg) {
82- return h('div.message', render(msg))
82 + return h('div', render(msg))
8383 })
8484 )
8585 }
8686
@@ -114,15 +114,15 @@
114114 sbot.get(root, function (err, data) {
115115 if (err) { console.log('could not find root')}
116116 data.value = data
117117 data.key = root
118- content.appendChild(h('div.message', render(data)))
118 + content.appendChild(h('div', render(data)))
119119 pull(
120120 sbot.links({rel: 'root', dest: root, values: true, keys: true, live: true}),
121121 pull.drain(function (msg) {
122122 console.log(msg)
123123 if (msg.value)
124- content.appendChild(h('div.message', render(msg)))
124 + content.appendChild(h('div', render(msg)))
125125 })
126126 )
127127 })
128128 })

Built with git-ssb-web