git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: 45e59d3471f3beeee49304361c2c16c9fc3c819f

Files: 45e59d3471f3beeee49304361c2c16c9fc3c819f / render.js

5997 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
12var avatar = require('./avatar')
13
14module.exports = function (msg) {
15 var message = h('div.message#' + msg.key.substring(0, 44))
16
17 if (!localStorage[msg.value.author])
18 var cache = {mute: false}
19 else
20 var cache = JSON.parse(localStorage[msg.value.author])
21
22 if (cache.mute == true) {
23 var muted = h('span', ' muted')
24 message.appendChild(tools.mini(msg, muted))
25 return message
26 }
27
28 /*if (msg.value.private == true) {
29 var privateMsg = h('span', ' ', h('img.emoji', {src: config.emojiUrl + 'lock.png'}), ' ', h('button.btn', 'Open'))
30 message.appendChild(tools.mini(msg, privateMsg))
31 return message
32 }*/
33 else if (msg.value.content.type == 'git-update') {
34
35 message.appendChild(tools.header(msg))
36
37 var reponame = h('p', 'pushed to ', h('a', {href: '#' + msg.value.content.repo}, msg.value.content.repo))
38
39 var cloneurl = h('pre', 'git clone ssb://' + msg.value.content.repo)
40
41 message.appendChild(reponame)
42
43 pull(
44 sbot.get(msg.value.content.repo, function (err, data) {
45 if (err) throw err
46 if (data.content.name) {
47 actualname = h('p', 'pushed to ', h('a', {href: '#' + msg.value.content.repo}, '%' + data.content.name))
48 reponame.parentNode.replaceChild(actualname, reponame)
49 }
50 })
51 )
52 message.appendChild(cloneurl)
53 //message.appendChild(h('pre', tools.rawJSON(msg.value)))
54 return message
55
56 }
57 else if (msg.value.content.type == 'git-repo') {
58 message.appendChild(tools.header(msg))
59 if (msg.value.content.name) {
60 message.appendChild(h('p', h('a', {href: msg.link}, '%' + msg.value.content.name)))
61 } else {
62 message.appendChild(h('p', h('a', {href: msg.link}, msg.link)))
63 }
64 var cloneurl = h('pre', 'git clone ssb://' + msg.key)
65 message.appendChild(cloneurl)
66 //message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
67 return message
68 }
69
70 else if (msg.value.content.type == 'post') {
71 var opts = {
72 type: 'post',
73 branch: msg.key
74 }
75 var fallback = {}
76
77
78 if (msg.value.content.root)
79 opts.root = msg.value.content.root
80 else
81 opts.root = msg.key
82
83 message.appendChild(tools.header(msg))
84
85 if (msg.value.content.root)
86 message.appendChild(h('span', 're: ', tools.messageLink(msg.value.content.root)))
87
88 message.appendChild(h('div.message__body', tools.markdown(msg.value.content.text)))
89
90 pull(
91 sbot.query({query: [{$filter: {value: {content: {type: 'edit', original: msg.key}}}}], limit: 100, live: true}),
92 pull.drain(function (update) {
93 if (update.sync) {
94 } else {
95 var newMessage = h('div', tools.markdown(update.value.content.text))
96 var latest = h('div.message__body',
97 tools.timestamp(update, {edited: true}),
98 newMessage
99 )
100 message.replaceChild(latest, message.childNodes[message.childNodes.length - 2])
101 fallback.messageText = update.value.content.text
102 opts.updated = update.key
103 opts.original = msg.key
104 }
105 })
106 )
107
108 var buttons = h('div.buttons')
109 buttons.appendChild(h('button.btn', 'Reply', {
110 onclick: function () {
111 opts.type = 'post'
112 opts.mentions = '[' + avatar.name(msg.value.author).textContent + '](' + msg.value.author + ')'
113 if (msg.value.content.recps) {
114 opts.recps = msg.value.content.recps
115 }
116 var r = message.childNodes.length - 1
117 delete opts.updated
118 delete opts.original
119 delete fallback.messageText
120 fallback.buttons = message.childNodes[r]
121 var compose = h('div.message#re:' + msg.key.substring(0, 44), composer(opts, fallback))
122 message.removeChild(message.childNodes[r])
123 message.parentNode.insertBefore(compose, message.nextSibling)
124 }
125 }))
126
127 if (msg.value.author == id)
128 buttons.appendChild(h('button.btn', 'Edit', {
129 onclick: function () {
130 opts.type = 'edit'
131 if (!fallback.messageText)
132 fallback.messageText = msg.value.content.text
133
134 if (!opts.updated)
135 opts.updated = msg.key
136 opts.original = msg.key
137
138 var r = message.childNodes.length - 1
139 fallback.buttons = message.childNodes[r]
140 message.removeChild(message.childNodes[r])
141 var compose = h('div#edit:' + msg.key.substring(0, 44), composer(opts, fallback))
142 message.replaceChild(compose, message.lastElementChild)
143 }
144 }))
145
146 buttons.appendChild(tools.star(msg))
147 message.appendChild(buttons)
148 return message
149
150 } else if (msg.value.content.type == 'vote') {
151 if (msg.value.content.vote.value == 1)
152 var link = h('span', ' ', h('img.emoji', {src: config.emojiUrl + 'star.png'}), ' ', h('a', {href: '#' + msg.value.content.vote.link}, tools.messageLink(msg.value.content.vote.link)))
153 else if (msg.value.content.vote.value == -1)
154 var link = h('span', ' ', h('img.emoji', {src: config.emojiUrl + 'stars.png'}), ' ', h('a', {href: '#' + msg.value.content.vote.link}, tools.messageLink(msg.value.content.vote.link)))
155 message.appendChild(tools.mini(msg, link))
156 return message
157 } else if (typeof msg.value.content === 'string') {
158 var privateMsg = h('span', ' ', h('img.emoji', {src: config.emojiUrl + 'lock.png'}))
159 message.appendChild(tools.mini(msg, privateMsg))
160 return message
161 } else {
162
163 //FULL FALLBACK
164 message.appendChild(tools.header(msg))
165 message.appendChild(h('pre', tools.rawJSON(msg.value.content)))
166
167 //MINI FALLBACK
168 //var fallback = h('span', ' ' + msg.value.content.type)
169 //message.appendChild(tools.mini(msg, fallback))
170 return message
171 }
172}
173

Built with git-ssb-web