git ssb

10+

Matt McKegg / patchwork



Tree: 9bb4dd6572b0113dd462049c31d372b6062f9ac5

Files: 9bb4dd6572b0113dd462049c31d372b6062f9ac5 / modules / page / html / render / message.js

2106 bytesRaw
1var { h, when, map, Proxy, Struct, Value, computed } = require('mutant')
2var nest = require('depnest')
3var ref = require('ssb-ref')
4
5exports.needs = nest({
6 'keys.sync.id': 'first',
7 'feed.obs.thread': 'first',
8 'message.sync.unbox': 'first',
9 'message.html': {
10 render: 'first',
11 compose: 'first'
12 },
13 'sbot.async.get': 'first'
14})
15
16exports.gives = nest('page.html.render')
17
18exports.create = function (api) {
19 return nest('page.html.render', function channel (id) {
20 if (!ref.isMsg(id)) return
21 var loader = h('div', {className: 'Loading -large'})
22
23 var result = Proxy(loader)
24
25 var meta = Struct({
26 type: 'post',
27 root: Proxy(id),
28 branch: Proxy(id),
29 channel: Value(undefined),
30 recps: Value(undefined)
31 })
32
33 var compose = api.message.html.compose({
34 meta,
35 shrink: false,
36 placeholder: when(meta.recps, 'Write a private reply', 'Write a public reply')
37 })
38
39 api.sbot.async.get(id, (err, value) => {
40 if (err) return result.set(h('div', {className: 'Error'}, ['Cannot load thead']))
41
42 if (typeof value.content === 'string') {
43 value = api.message.sync.unbox(value)
44 }
45
46 // what happens in private stays in private!
47 meta.recps.set(value.content.recps)
48
49 var isReply = !!value.content.root
50 var thread = api.feed.obs.thread(id, {branch: isReply})
51
52 meta.channel.set(value.content.channel)
53 meta.root.set(thread.rootId)
54
55 // if root thread, reply to last post
56 meta.branch.set(isReply ? thread.branchId : thread.lastId)
57
58 var container = h('Thread', [
59 when(thread.branchId, h('a.full', {href: thread.rootId}, ['View full thread'])),
60 map(thread.messages, (msg) => {
61 return computed([msg, thread.previousKey(msg)], (msg, previousId) => {
62 return api.message.html.render(msg, {previousId, backlinks: true})
63 })
64 }),
65 compose
66 ])
67 result.set(when(thread.sync, container, loader))
68 })
69
70 return h('div', {className: 'SplitView'}, [
71 h('div.main', [
72 result
73 ])
74 ])
75 })
76}
77

Built with git-ssb-web