Files: 3451510316992d414ec76ba5b29681fe359b7428 / lib / depject / message / html / references.js
1009 bytesRaw
1 | const nest = require('depnest') |
2 | const ref = require('ssb-ref') |
3 | const { h, map } = require('mutant') |
4 | |
5 | exports.needs = nest({ |
6 | 'backlinks.obs.references': 'first', |
7 | 'message.obs': { |
8 | name: 'first' |
9 | }, |
10 | 'profile.html.person': 'first', |
11 | 'intl.sync.i18n': 'first' |
12 | }) |
13 | |
14 | exports.gives = nest('message.html.references') |
15 | |
16 | exports.create = function (api) { |
17 | const i18n = api.intl.sync.i18n |
18 | return nest('message.html.references', function (msg) { |
19 | if (!ref.type(msg.key)) return [] |
20 | |
21 | const references = api.backlinks.obs.references(msg) |
22 | |
23 | return [ |
24 | map(references, link => { |
25 | return h('a.backlink', { |
26 | href: link.id, title: link.id |
27 | }, [ |
28 | h('strong', [ |
29 | api.profile.html.person(link.author), i18n(' referenced this message:') |
30 | ]), ' ', |
31 | api.message.obs.name(link.id) |
32 | ]) |
33 | }, { |
34 | // treat all items as immutable (mutant cannot detect this as they are objects) |
35 | comparer: (a, b) => a === b |
36 | }) |
37 | ] |
38 | }) |
39 | } |
40 |
Built with git-ssb-web