Files: 3451510316992d414ec76ba5b29681fe359b7428 / lib / depject / message / html / link.js
1008 bytesRaw
1 | const h = require('mutant/h') |
2 | const ref = require('ssb-ref') |
3 | const nest = require('depnest') |
4 | |
5 | exports.needs = nest({ |
6 | 'message.async.name': 'first', |
7 | 'sbot.async.get': 'first' |
8 | }) |
9 | |
10 | exports.gives = nest('message.html.link') |
11 | |
12 | exports.create = function (api) { |
13 | return nest('message.html.link', function (id, { inContext = false } = {}) { |
14 | if (typeof id !== 'string') { throw new Error('link must be to message id') } |
15 | |
16 | const link = h('a', { href: id }, id.substring(0, 10) + '...') |
17 | |
18 | if (ref.isMsg(id)) { |
19 | api.message.async.name(id, function (err, name) { |
20 | if (err) console.error(err) |
21 | else link.textContent = name |
22 | if (inContext) { |
23 | api.sbot.async.get({ id, private: true }, (err, value) => { |
24 | if (err) return |
25 | if (value && value.content && ref.isMsg(value.content.root)) { |
26 | link.setAttribute('href', value.content.root) |
27 | link.anchor = id |
28 | } |
29 | }) |
30 | } |
31 | }) |
32 | } |
33 | |
34 | return link |
35 | }) |
36 | } |
37 |
Built with git-ssb-web