aboutsummaryrefslogtreecommitdiff
path: root/lib/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/app.js')
-rw-r--r--lib/app.js53
1 files changed, 46 insertions, 7 deletions
diff --git a/lib/app.js b/lib/app.js
index a3bfbf6..dfec6bd 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -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
}),