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