1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
var pull = require('pull-stream')
// var defer = require('pull-defer')
// var many = require('pull-many')
var multicb = require('multicb')
var u = require('./util')
module.exports = About
function About(sbot) {
if (!(this instanceof About)) return new About(sbot)
this.sbot = sbot
}
About.prototype.createAboutOpStream = function (id) {
return pull(
this.sbot.links({dest: id, rel: 'about', values: true, reverse: true}),
pull.map(function (msg) {
var c = msg.value.content || {}
return Object.keys(c).filter(function (key) {
return key !== 'about'
&& key !== 'type'
&& key !== 'recps'
}).map(function (key) {
var value = c[key]
if (u.isRef(value)) value = {link: value}
return {
id: msg.key,
author: msg.value.author,
timestamp: msg.value.timestamp,
prop: key,
value: value,
remove: value && typeof value === 'object' && value.remove,
}
})
}),
pull.flatten()
)
}
About.prototype.createAboutStreams = function (id) {
var ops = this.createAboutOpStream(id)
var scalars = {/* author: {prop: value} */}
var sets = {/* author: {prop: {link}} */}
var setsDone = multicb({pluck: 1, spread: true})
setsDone()(null, pull.values([]))
return {
scalars: pull(
ops,
pull.unique(function (op) {
return op.author + '-' + op.prop + '-' + (op.value ? op.value.link : '')
}),
pull.filter(function (op) {
return !op.remove
})
),
sets: u.readNext(setsDone)
}
}
|