git ssb

2+

mixmix / ticktack



Tree: 69fecb32f29fb953037e1e0b67db4d89bb1cab8b

Files: 69fecb32f29fb953037e1e0b67db4d89bb1cab8b / app / html / comments.js

2060 bytesRaw
1const nest = require('depnest')
2const { h, map, Struct, computed, throttle } = require('mutant')
3const get = require('lodash/get')
4
5exports.gives = nest('app.html.comments')
6
7exports.needs = nest({
8 'message.html.comment': 'first',
9 'message.html.compose': 'first',
10 'translations.sync.strings': 'first'
11})
12
13exports.create = (api) => {
14 return nest('app.html.comments', comments)
15
16 function comments (thread) {
17 const strings = api.translations.sync.strings()
18 const { messages, channel, lastId: branch } = thread
19
20 // TODO - move this up into Patchcore
21 const messagesTree = computed(throttle(messages, 200), msgs => {
22 return msgs
23 .filter(msg => forkOf(msg) === undefined) // exclude nested replies / forks
24 .filter(msg => msg.value.content.root) // exclude root message / blog
25 .map(comment => {
26 return Struct({
27 comment,
28 replies: msgs.filter(msg => forkOf(msg) === comment.key)
29 })
30 })
31 })
32
33 const root = computed(messages, ary => ary[0].key)
34
35 const meta = {
36 type: 'post',
37 root,
38 branch,
39 channel
40 }
41 // const twoComposers = computed(messages, messages => {
42 // return messages.length > 5
43 // })
44 const { compose } = api.message.html
45
46 const feedIdsInThread = computed(thread.messages, msgs => {
47 return msgs.map(m => m.value.author)
48 })
49
50 return h('Comments', [
51 // when(twoComposers, compose({ meta, shrink: true, canAttach: false })),
52 map(
53 messagesTree,
54 msg => api.message.html.comment({ comment: msg.comment, replies: msg.replies, branch }),
55 {
56 comparer: (a, b) => {
57 if (a === undefined || b === undefined) return false
58
59 return a.comment().key === b.comment().key && a.replies().length === b.replies().length
60 }
61 }
62 ),
63 compose({ meta, feedIdsInThread, shrink: false, canAttach: true, placeholder: strings.writeComment })
64 ])
65 }
66}
67
68function forkOf (msg) {
69 return get(msg, 'value.content.fork')
70}
71

Built with git-ssb-web