Initial commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
var pull = require('pull-stream')
|
||||
var sort = require('ssb-sort')
|
||||
|
||||
function linkDest(val) {
|
||||
return typeof val === 'string' ? val : val && val.link
|
||||
}
|
||||
|
||||
function reduceAbout(about, msg) {
|
||||
var c = msg.value.content
|
||||
if (!c) return about
|
||||
if (c.name) about.name = c.name.replace(/^@?/, '@')
|
||||
if (c.image) about.image = linkDest(c.image)
|
||||
return about
|
||||
}
|
||||
|
||||
module.exports = function (sbot, id, cb) {
|
||||
var about = {}
|
||||
pull(
|
||||
sbot.links({
|
||||
rel: 'about',
|
||||
dest: id,
|
||||
values: true,
|
||||
}),
|
||||
pull.collect(function (err, msgs) {
|
||||
if (err) return cb(err)
|
||||
cb(null, sort(msgs).reduce(reduceAbout, {
|
||||
name: String(id).substr(0, 10) + '…',
|
||||
}))
|
||||
})
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user