git ssb

2+

mixmix / ticktack



Tree: c26a377b747816479b1dc93f160726ef84bf6205

Files: c26a377b747816479b1dc93f160726ef84bf6205 / app / html / comments.js

2572 bytesRaw
1const nest = require('depnest')
2const { h, Array: MutantArray, map, computed, when, resolve } = require('mutant')
3const get = require('lodash/get')
4
5exports.gives = nest('app.html.comments')
6
7exports.needs = nest({
8 'about.html.avatar': 'first',
9 'about.obs.name': 'first',
10 'backlinks.obs.for': 'first',
11 'feed.obs.thread': 'first',
12 'message.html.markdown': 'first',
13 'message.html.timeago': 'first',
14 'message.html.likes': 'first',
15 'unread.sync.markRead': 'first',
16 'unread.sync.isUnread': 'first',
17})
18
19exports.create = (api) => {
20 return nest('app.html.comments', comments)
21
22 function comments (root) {
23 const thread = api.feed.obs.thread(root)
24
25 return h('Comments',
26 map(thread.messages, Comment)
27 )
28
29 }
30
31 function Comment (msgObs) {
32 const msg = resolve(msgObs)
33
34 const raw = get(msg, 'value.content.text')
35 var className = api.unread.sync.isUnread(msg) ? ' -unread' : ' -read'
36 api.unread.sync.markRead(msg)
37
38 if (!get(msg, 'value.content.root')) return
39
40 const { author } = msg.value
41
42 // TODO - move this upstream into patchcore:feed.obs.thread ??
43 // OR change strategy to use forks
44 const backlinks = api.backlinks.obs.for(msg.key)
45 const nestedReplies = computed(backlinks, backlinks => {
46 return backlinks.filter(backlinker => {
47 const { type, root } = backlinker.value.content
48 return type === 'post' && root === msg.key
49 })
50 })
51
52 return h('Comment', { className }, [
53 h('div.left', api.about.html.avatar(author, 'tiny')),
54 h('div.right', [
55 h('section.context', [
56 h('div.name', api.about.obs.name(author)),
57 api.message.html.timeago(msg)
58 ]),
59 h('section.content', api.message.html.markdown(raw)),
60 when(nestedReplies,
61 h('section.replies',
62 map(nestedReplies, NestedComment)
63 )
64 ),
65 h('section.actions', [
66 h('div.reply', [
67 h('i.fa.fa-commenting-o'),
68 ]),
69 api.message.html.likes(msg)
70 ]),
71 ])
72 ])
73 }
74
75 function NestedComment (msgObs) {
76 const msg = resolve(msgObs)
77 const raw = get(msg, 'value.content.text')
78 if (!raw) return
79
80 const { author } = msg.value
81
82 return h('Comment -nested', [
83 h('div.left'),
84 h('div.right', [
85 h('section.context', [
86 h('div.name', api.about.obs.name(author)),
87 api.message.html.timeago(msg)
88 ]),
89 h('section.content', api.message.html.markdown(raw)),
90 ])
91 ])
92
93 api.message.html.markdown(raw)
94 }
95}
96
97

Built with git-ssb-web