diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-15 13:06:39 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-05-15 13:06:39 -1000 |
commit | 58b40d18c7d49ef071ece70af5e6d9e1d12301e2 (patch) | |
tree | 9522535c9e1db5785461608762faf3998a732ce1 /lib/app.js | |
parent | 7570f001cc8ddeff88ebdab640e06a0b1b03974c (diff) | |
parent | f826bdf13d9bbdfd31a38bfdff382106b8edfd52 (diff) | |
download | patchfoo-58b40d18c7d49ef071ece70af5e6d9e1d12301e2.tar.gz patchfoo-58b40d18c7d49ef071ece70af5e6d9e1d12301e2.zip |
Merge branch 'master' into about
Diffstat (limited to 'lib/app.js')
-rw-r--r-- | lib/app.js | 53 |
1 files changed, 46 insertions, 7 deletions
@@ -250,15 +250,17 @@ App.prototype.streamPeers = function (opts) { App.prototype.getFollow = function (source, dest, cb) { var self = this pull( - self.sbot.links({source: source, dest: dest, rel: 'contact', values: true}), - pull.filter(function (msg) { - var c = msg && msg.value && msg.value.content + self.sbot.links({source: source, dest: dest, rel: 'contact', reverse: true, + values: true, meta: false, keys: false}), + pull.filter(function (value) { + var c = value && value.content return c && c.type === 'contact' }), - pull.reduce(function (doesFollow, msg) { - var c = msg.value.content - return !!c.following - }, false, cb) + pull.take(1), + pull.collect(function (err, msgs) { + if (err) return cb(err) + cb(null, msgs[0] && !!msgs[0].content.following) + }) ) } @@ -270,6 +272,43 @@ App.prototype.streamChannels = function (opts) { return pull( this.sbot.messagesByType({type: 'channel', reverse: true}), this.unboxMessages(), + pull.filter(function (msg) { + return msg.value.content.subscribed + }), + pull.map(function (msg) { + return msg.value.content.channel + }), + pull.unique() + ) +} + +App.prototype.streamMyChannels = function (id, opts) { + // use ssb-query plugin if it is available, since it has an index for + // author + type + if (this.sbot.query) return pull( + this.sbot.query.read({ + reverse: true, + query: [ + {$filter: { + value: { + author: id, + content: {type: 'channel', subscribed: true} + } + }}, + {$map: ['value', 'content', 'channel']} + ] + }), + pull.unique() + ) + + return pull( + this.sbot.createUserStream({id: id, reverse: true}), + this.unboxMessages(), + pull.filter(function (msg) { + if (msg.value.content.type == 'channel') { + return msg.value.content.subscribed + } + }), pull.map(function (msg) { return msg.value.content.channel }), |