Commit 0430c665098f7b2a92757dea85dd7cab154e63ac
clean up
Ev Bogue committed on 5/21/2018, 5:22:02 PMParent: 4b3e8a3282de8771e2c1f60fca76dadc1d39d38b
Files changed
render.js | changed |
render.js | ||
---|---|---|
@@ -1,28 +1,37 @@ | ||
1 | 1 | var h = require('hyperscript') |
2 | -var config = require('./config')() | |
3 | - | |
4 | 2 | var pull = require('pull-stream') |
5 | - | |
6 | 3 | var human = require('human-time') |
7 | 4 | |
8 | 5 | var sbot = require('./scuttlebot') |
9 | 6 | var composer = require('./compose') |
10 | - | |
11 | 7 | var tools = require('./tools') |
12 | 8 | |
9 | +var config = require('./config')() | |
13 | 10 | var id = require('./keys').id |
14 | 11 | |
15 | 12 | module.exports = function (msg) { |
16 | - var opts = {} | |
17 | - opts.root = null | |
13 | + var edit = {} | |
14 | + var reply = {} | |
15 | + | |
18 | 16 | var message = h('div.message') |
19 | 17 | |
20 | - | |
21 | 18 | if (msg.value.content.type == 'post') { |
22 | - opts.type = 'post' | |
23 | - opts.branch = msg.key | |
24 | 19 | |
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 | + | |
25 | 34 | message.appendChild(tools.header(msg)) |
26 | 35 | |
27 | 36 | if (msg.value.content.root) { |
28 | 37 | message.appendChild(h('span', 're: ', tools.messageLink(msg.value.content.root))) |
@@ -31,70 +40,41 @@ | ||
31 | 40 | message.appendChild( |
32 | 41 | h('div.message__body', tools.markdown(msg.value.content.text)) |
33 | 42 | ) |
34 | 43 | |
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 | |
47 | 55 | 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 | + ) | |
54 | 61 | |
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) | |
60 | 69 | message.appendChild(h('button.btn', 'Edit', { |
61 | 70 | onclick: function () { |
62 | - var compose = h('div.message', composer(opts)) | |
71 | + var compose = h('div.message', composer(edit)) | |
63 | 72 | message.parentNode.replaceChild(compose, message) |
64 | 73 | } |
65 | 74 | })) |
66 | - } else { | |
67 | - opts.type = 'post' | |
68 | - opts.branch = msg.key | |
75 | + return message | |
69 | 76 | |
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 | |
97 | 77 | } else if (msg.value.content.type == 'vote') { |
98 | 78 | message.appendChild(tools.header(msg)) |
99 | 79 | var embed = msg.value.content.vote.link |
100 | 80 |
Built with git-ssb-web