git ssb

1+

punkmonk.termux / mvd



forked from ev / mvd

Tree: ef33ab337c848fb05b567cdab92bd9a21bedfab5

Files: ef33ab337c848fb05b567cdab92bd9a21bedfab5 / render.js

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

Built with git-ssb-web