git ssb

10+

Matt McKegg / patchwork



Tree: c2d8083ad55e777a6e7b82aaa57f2aaa27f5a607

Files: c2d8083ad55e777a6e7b82aaa57f2aaa27f5a607 / modules / page / html / render / message.js

2183 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 (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(value.content.root || 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 h('div.messages', [
60 when(thread.branchId, h('a.full', {href: thread.rootId}, ['View full thread'])),
61 map(thread.messages, (msg) => {
62 return computed([msg, thread.previousKey(msg)], (msg, previousId) => {
63 return api.message.html.render(msg, {pageId: id, previousId, backlinks: true})
64 })
65 })
66 ]),
67 compose
68 ])
69 result.set(when(thread.sync, container, loader))
70 })
71
72 return h('div', {className: 'SplitView'}, [
73 h('div.main', [
74 result
75 ])
76 ])
77 })
78}
79

Built with git-ssb-web