git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: 3bf3c7aca4c5ebf780ce5daee70c769f82f5ca26

Files: 3bf3c7aca4c5ebf780ce5daee70c769f82f5ca26 / render.js

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

Built with git-ssb-web