Files: dffd43f062a271d3a9be609e1129bf5ad153a4ff / lib / about.js
780 bytesRaw
1 | var pull = require('pull-stream') |
2 | var sort = require('ssb-sort') |
3 | |
4 | function linkDest(val) { |
5 | return typeof val === 'string' ? val : val && val.link |
6 | } |
7 | |
8 | function reduceAbout(about, msg) { |
9 | var c = msg.value.content |
10 | if (!c) return about |
11 | if (c.name) about.name = c.name.replace(/^@?/, '@') |
12 | if (c.image) about.image = linkDest(c.image) |
13 | if (c.description) about.description = c.description |
14 | return about |
15 | } |
16 | |
17 | module.exports = function (sbot, id, cb) { |
18 | var about = {} |
19 | pull( |
20 | sbot.links({ |
21 | rel: 'about', |
22 | source: id, |
23 | dest: id, |
24 | values: true, |
25 | }), |
26 | pull.collect(function (err, msgs) { |
27 | if (err) return cb(err) |
28 | cb(null, sort(msgs).reduce(reduceAbout, { |
29 | name: String(id).substr(0, 10) + '…', |
30 | })) |
31 | }) |
32 | ) |
33 | } |
34 |
Built with git-ssb-web