git ssb

9+

cel / ssb-viewer



Tree: 5c13d7dc8dd9c1117f5e31633ddb3e5858ee474c

Files: 5c13d7dc8dd9c1117f5e31633ddb3e5858ee474c / lib / about.js

692 bytesRaw
1var pull = require('pull-stream')
2var sort = require('ssb-sort')
3
4function linkDest(val) {
5 return typeof val === 'string' ? val : val && val.link
6}
7
8function 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
16module.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