Files: 3738a10330418ba685af21142b05c622732f4eec / modules / message / html / backlinks.js
1449 bytesRaw
1 | var nest = require('depnest') |
2 | var { h, map, computed } = require('mutant') |
3 | |
4 | exports.needs = nest({ |
5 | 'message.obs': { |
6 | backlinks: 'first', |
7 | forks: 'first', |
8 | name: 'first', |
9 | author: 'first' |
10 | }, |
11 | 'profile.html.person': 'first' |
12 | }) |
13 | |
14 | exports.gives = nest('message.html.backlinks') |
15 | |
16 | exports.create = function (api) { |
17 | return nest('message.html.backlinks', function (msg, {includeReferences = true, includeForks = true} = {}) { |
18 | var references = includeReferences ? api.message.obs.backlinks(msg.key) : [] |
19 | var forks = (includeForks && msg.value.content.root) ? api.message.obs.forks(msg.key) : [] |
20 | return [ |
21 | map(forks, msgId => { |
22 | return h('a.backlink', { |
23 | href: msgId, |
24 | title: msgId |
25 | }, [ |
26 | h('strong', [ |
27 | authorLink(msgId), ' forked this discussion:' |
28 | ]), ' ', |
29 | api.message.obs.name(msgId) |
30 | ]) |
31 | }), |
32 | map(references, msgId => { |
33 | return h('a.backlink', { |
34 | href: msgId, |
35 | title: msgId |
36 | }, [ |
37 | h('strong', [ |
38 | authorLink(msgId), ' referenced this message:' |
39 | ]), ' ', |
40 | api.message.obs.name(msgId) |
41 | ]) |
42 | }) |
43 | ] |
44 | }) |
45 | |
46 | function authorLink (msgId) { |
47 | var author = api.message.obs.author(msgId) |
48 | return computed(author, author => { |
49 | if (author) { |
50 | return api.profile.html.person(author) |
51 | } else { |
52 | return 'Someone' |
53 | } |
54 | }) |
55 | } |
56 | } |
57 |
Built with git-ssb-web