git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: 8778967887283b1aa5eb60fde4c5aad8431fd2e9

Files: 8778967887283b1aa5eb60fde4c5aad8431fd2e9 / render.js

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

Built with git-ssb-web