git ssb

2+

ev / mvd



Commit 0430c665098f7b2a92757dea85dd7cab154e63ac

clean up

Ev Bogue committed on 5/21/2018, 5:22:02 PM
Parent: 4b3e8a3282de8771e2c1f60fca76dadc1d39d38b

Files changed

render.jschanged
render.jsView
@@ -1,28 +1,37 @@
11 var h = require('hyperscript')
2-var config = require('./config')()
3-
42 var pull = require('pull-stream')
5-
63 var human = require('human-time')
74
85 var sbot = require('./scuttlebot')
96 var composer = require('./compose')
10-
117 var tools = require('./tools')
128
9 +var config = require('./config')()
1310 var id = require('./keys').id
1411
1512 module.exports = function (msg) {
16- var opts = {}
17- opts.root = null
13 + var edit = {}
14 + var reply = {}
15 +
1816 var message = h('div.message')
1917
20-
2118 if (msg.value.content.type == 'post') {
22- opts.type = 'post'
23- opts.branch = msg.key
2419
20 + reply.type = 'post'
21 + reply.branch = msg.key
22 +
23 + if (msg.value.content.root)
24 + reply.root = msg.value.content.root
25 + else
26 + reply.root = msg.key
27 +
28 + if (msg.value.author == id)
29 + edit.original = msg.key
30 + edit.type = 'update'
31 + edit.updated = msg.key
32 + edit.messageText = msg.value.content.text
33 +
2534 message.appendChild(tools.header(msg))
2635
2736 if (msg.value.content.root) {
2837 message.appendChild(h('span', 're: ', tools.messageLink(msg.value.content.root)))
@@ -31,70 +40,41 @@
3140 message.appendChild(
3241 h('div.message__body', tools.markdown(msg.value.content.text))
3342 )
3443
35- if (msg.value.author == id) {
36- opts.type = 'update'
37- opts.updated = msg.key
38- opts.messageText = msg.value.content.text
39- pull(
40- sbot.query({query: [{$filter: {value: {content: {type: 'update', updated: msg.key}}}}]}),
41- pull.drain(function (update) {
42- var latest = h('div.message__body',
43- tools.markdown(update.value.content.text),
44- h('span.timestamp', 'Edited: ', h('a', {href: '#' + update.key}, human(new Date(update.value.timestamp))))
45- )
46- var num = message.childNodes.length
44 + pull(
45 + sbot.query({query: [{$filter: {value: {content: {type: 'update', updated: msg.key}}}}]}),
46 + pull.drain(function (update) {
47 + var latest = h('div.message__body',
48 + tools.markdown(update.value.content.text),
49 + h('span.timestamp', 'Edited: ', h('a', {href: '#' + update.key}, human(new Date(update.value.timestamp))))
50 + )
51 + var num = message.childNodes.length
52 + if (msg.value.author == id)
53 + var act = num - 3
54 + else
4755 var act = num - 2
48- console.log(act)
49- message.replaceChild(latest, message.childNodes[act])
50- opts.messageText = update.value.content.text
51- })
52-
53- )
56 + message.replaceChild(latest, message.childNodes[act])
57 + edit.messageText = update.value.content.text
58 + edit.original = msg.value.content.original
59 + })
60 + )
5461
55-
56- if (msg.value.content.original)
57- opts.original = msg.value.content.original
58- else
59- opts.original = msg.key
62 + message.appendChild(h('button.btn', 'Reply', {
63 + onclick: function () {
64 + var compose = composer(reply)
65 + message.replaceChild(compose, message.lastElementChild)
66 + }
67 + }))
68 + if (msg.value.author == id)
6069 message.appendChild(h('button.btn', 'Edit', {
6170 onclick: function () {
62- var compose = h('div.message', composer(opts))
71 + var compose = h('div.message', composer(edit))
6372 message.parentNode.replaceChild(compose, message)
6473 }
6574 }))
66- } else {
67- opts.type = 'post'
68- opts.branch = msg.key
75 + return message
6976
70- if (msg.value.content.root) {
71- opts.root = msg.value.content.root
72- } else { opts.root = msg.key }
73-
74-
75- pull(
76- sbot.query({query: [{$filter: {value: {content: {type: 'update', updated: msg.key}}}}]}),
77- pull.drain(function (data) {
78- console.log(data)
79- var latest = h('div.message__body', tools.markdown(data.value.content.text), h('span.timestamp', 'Edited: ' + human(new Date(data.value.timestamp))))
80- var num = message.childNodes.length
81- var act = num - 2
82-
83- message.replaceChild(latest, message.childNodes[act])
84- })
85-
86- )
87-
88-
89- message.appendChild(h('button.btn', 'Reply', {
90- onclick: function () {
91- var compose = composer(opts)
92- message.replaceChild(compose, message.lastElementChild)
93- }
94- }))
95- }
96- return message
9777 } else if (msg.value.content.type == 'vote') {
9878 message.appendChild(tools.header(msg))
9979 var embed = msg.value.content.vote.link
10080

Built with git-ssb-web