modules/message/html/backlinks.jsView |
---|
2 | 2 | var ref = require('ssb-ref') |
3 | 3 | var { h, map, computed } = require('mutant') |
4 | 4 | |
5 | 5 | exports.needs = nest({ |
| 6 | + 'message.sync.root': 'first', |
6 | 7 | 'message.obs': { |
7 | 8 | backlinks: 'first', |
8 | 9 | name: 'first', |
9 | 10 | author: 'first' |
17 | 18 | exports.create = function (api) { |
18 | 19 | const i18n = api.intl.sync.i18n |
19 | 20 | return nest('message.html.backlinks', function (msg, {includeReferences = true, includeForks = true} = {}) { |
20 | 21 | if (!ref.type(msg.key)) return [] |
| 22 | + |
| 23 | + var rootId = api.message.sync.root(msg) |
21 | 24 | var backlinks = api.message.obs.backlinks(msg.key) |
22 | 25 | var references = includeReferences ? computed([backlinks, msg], onlyReferences) : [] |
23 | | - var forks = (includeForks && msg.value.content.root) ? computed([backlinks, msg], onlyForks) : [] |
| 26 | + var forks = (includeForks && rootId) ? computed([backlinks, msg], onlyForks) : [] |
| 27 | + |
24 | 28 | return [ |
25 | 29 | map(forks, link => { |
26 | 30 | return h('a.backlink', { |
27 | 31 | href: msg.key, anchor: link.id |
43 | 47 | ]) |
44 | 48 | }) |
45 | 49 | ] |
46 | 50 | }) |
47 | | -} |
48 | 51 | |
49 | | -function onlyReferences (backlinks, msg) { |
50 | | - return backlinks.filter(link => link.root !== msg.key && !includeOrEqual(link.branch, msg.key)) |
51 | | -} |
| 52 | + function onlyReferences (backlinks, msg) { |
| 53 | + return backlinks.filter(link => link.root !== msg.key && !includeOrEqual(link.branch, msg.key)) |
| 54 | + } |
52 | 55 | |
53 | | -function onlyForks (backlinks, msg) { |
54 | | - return backlinks.filter(link => link.root === msg.key && includeOrEqual(link.branch, msg.key) && msg.value.content && msg.value.content.root) |
| 56 | + function onlyForks (backlinks, msg) { |
| 57 | + return backlinks.filter(link => link.root === msg.key && includeOrEqual(link.branch, msg.key) && api.message.sync.root(msg)) |
| 58 | + } |
55 | 59 | } |
56 | 60 | |
57 | 61 | function includeOrEqual (valueOrArray, item) { |
58 | 62 | if (Array.isArray(valueOrArray)) { |