git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: 288090456f797459713cd94143110c26816cf1a3

Files: 288090456f797459713cd94143110c26816cf1a3 / render.js

3710 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
12
13module.exports = function (msg) {
14 var message = h('div.message#' + msg.key.substring(0, 44))
15 if (msg.value.content.type == 'post') {
16 var opts = {
17 type: 'post',
18 branch: msg.key
19 }
20 var fallback = {}
21
22
23 if (msg.value.content.root)
24 opts.root = msg.value.content.root
25 else
26 opts.root = msg.key
27
28 message.appendChild(tools.header(msg))
29
30 if (msg.value.content.root)
31 message.appendChild(h('span', 're: ', tools.messageLink(msg.value.content.root)))
32
33 message.appendChild(h('div.message__body', tools.markdown(msg.value.content.text)))
34
35
36 pull(
37 sbot.query({query: [{$filter: {value: {content: {type: 'edit', original: msg.key}}}}], limit: 100, live: true}),
38 pull.drain(function (update) {
39 if (update.sync) {
40 //console.log('Waiting for new edits.')
41 } else {
42 var newMessage = h('div', tools.markdown(update.value.content.text))
43 var latest = h('div.message__body',
44 tools.timestamp(update, {edited: true}),
45 newMessage
46 )
47 message.replaceChild(latest, message.childNodes[message.childNodes.length - 2])
48 fallback.messageText = update.value.content.text
49 opts.updated = update.key
50 opts.original = msg.key
51 }
52 })
53 )
54
55 var buttons = h('div.buttons')
56 buttons.appendChild(h('button.btn', 'Reply', {
57 onclick: function () {
58 opts.type = 'post'
59 var r = message.childNodes.length - 1
60 delete opts.updated
61 delete opts.original
62 delete fallback.messageText
63 fallback.buttons = message.childNodes[r]
64 var compose = h('div.message#re:' + msg.key.substring(0, 44), composer(opts, fallback))
65 message.removeChild(message.childNodes[r])
66 message.parentNode.insertBefore(compose, message.nextSibling)
67 }
68 }))
69
70 if (msg.value.author == id)
71 buttons.appendChild(h('button.btn', 'Edit', {
72 onclick: function () {
73 opts.type = 'edit'
74 if (!fallback.messageText)
75 fallback.messageText = msg.value.content.text
76
77 if (!opts.updated)
78 opts.updated = msg.key
79 opts.original = msg.key
80
81 var r = message.childNodes.length - 1
82 fallback.buttons = message.childNodes[r]
83 message.removeChild(message.childNodes[r])
84 var compose = h('div#edit:' + msg.key.substring(0, 44), composer(opts, fallback))
85 message.replaceChild(compose, message.lastElementChild)
86 }
87 }))
88
89 buttons.appendChild(tools.star(msg))
90 message.appendChild(buttons)
91 return message
92
93 } else if (msg.value.content.type == 'vote') {
94 if (msg.value.content.vote.value == 1)
95 var link = h('span', ' ', h('img.emoji', {src: config.emojiUrl + 'star.png'}), ' ', h('a', {href: '#' + msg.value.content.vote.link}, msg.value.content.vote.link.substring(0,16) + '...'))
96 else if (msg.value.content.vote.value == -1)
97 var link = h('span', ' ', h('img.emoji', {src: config.emojiUrl + 'stars.png'}), ' ', h('a', {href: '#' + msg.value.content.vote.link}, msg.value.content.vote.link.substring(0,16) + '...'))
98 message.appendChild(tools.mini(msg, link))
99 return message
100 } else {
101 //message.appendChild(tools.header(msg))
102 //message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
103 //return message
104 return h('div.invisibleMessage')
105 }
106}
107

Built with git-ssb-web