git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: 0eb4374b336f60d5f9befb4eb57507275cd4f86c

Files: 0eb4374b336f60d5f9befb4eb57507275cd4f86c / render.js

3530 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 newMessage = h('div', tools.markdown(update.value.content.text))
47 var latest = h('div.message__body',
48 tools.timestamp(msg, {edited: true}),
49 newMessage
50 )
51 var r = message.childNodes.length - 2
52 message.replaceChild(latest, message.childNodes[r])
53 edit.messageText = update.value.content.text
54 edit.original = msg.value.content.original
55 })
56 )
57 var buttons = h('div.buttons')
58 buttons.appendChild(h('button.btn', 'Reply', {
59 onclick: function () {
60 var r = message.childNodes.length - 1
61 buttons = message.childNodes[r]
62 //fallback = message.lastElementChild
63 //console.log(fallback)
64 var compose = h('div.message#' + reply.branch.substring(0, 10), composer(reply, buttons))
65 message.parentNode.appendChild(compose)
66 //message.replaceChild(compose, message.lastElementChild)
67 }
68 }))
69 if (msg.value.author == id)
70 buttons.appendChild(h('button.btn', 'Edit', {
71 onclick: function () {
72 var r = message.childNodes.length - 1
73 buttons = message.childNodes[r]
74 message.removeChild(message.childNodes[r])
75 var compose = h('div#' + edit.updated.substring(0, 10), composer(edit, buttons))
76 message.replaceChild(compose, message.lastElementChild)
77 }
78 }))
79
80 message.appendChild(buttons)
81 return message
82
83 } else if (msg.value.content.type == 'vote') {
84 message.appendChild(tools.header(msg))
85 message.appendChild(h('span', 'Starred:'))
86 var embed = msg.value.content.vote.link
87
88 var embedded = h('div.embedded')
89 sbot.get(embed, function (err, msg) {
90 if (err) {console.log('could not find message locally, try ooo?') }
91 msg.value = msg
92 msg.key = embed
93 if (msg.value.content.text) {
94 message.appendChild(embedded)
95 embedded.appendChild(tools.header(msg))
96 embedded.appendChild(
97 h('div.message__body',
98 tools.markdown(msg.value.content.text.substring(0, 256) + '...'),
99 h('span', '[', h('a', {href: '#' + msg.key}, 'Full Post'), ']')
100 )
101 )
102 }
103 })
104 return message
105 } else {
106 //message.appendChild(tools.header(msg))
107 //message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
108 //return message
109 return
110 }
111}
112

Built with git-ssb-web