Files: dd5c82b06c5cfb2c717fd3b9a9598d789092587c / lib / about.js
692 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 | return about |
14 | } |
15 | |
16 | module.exports = function (sbot, id, cb) { |
17 | var about = {} |
18 | pull( |
19 | sbot.links({ |
20 | rel: 'about', |
21 | dest: id, |
22 | values: true, |
23 | }), |
24 | pull.collect(function (err, msgs) { |
25 | if (err) return cb(err) |
26 | cb(null, sort(msgs).reduce(reduceAbout, { |
27 | name: String(id).substr(0, 10) + '…', |
28 | })) |
29 | }) |
30 | ) |
31 | } |
32 |
Built with git-ssb-web