aboutsummaryrefslogtreecommitdiff
path: root/lib/about.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-04 11:03:16 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-05-04 12:21:14 -1000
commit7570f001cc8ddeff88ebdab640e06a0b1b03974c (patch)
treec8394624a998ea5823dec79656ccc2e4f8c3c8c9 /lib/about.js
parent49d72723ed74ac04099a46e2aae2ef68432ba210 (diff)
downloadpatchfoo-7570f001cc8ddeff88ebdab640e06a0b1b03974c.tar.gz
patchfoo-7570f001cc8ddeff88ebdab640e06a0b1b03974c.zip
wip: about
Diffstat (limited to 'lib/about.js')
-rw-r--r--lib/about.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/about.js b/lib/about.js
new file mode 100644
index 0000000..4f1d582
--- /dev/null
+++ b/lib/about.js
@@ -0,0 +1,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)
+ }
+}