From 11e894c5c9efbc6ee141f614eea3a328517aee5b Mon Sep 17 00:00:00 2001 From: cel Date: Mon, 8 May 2017 20:54:59 -1000 Subject: Exclude channel from list if all its subscribers unsubscribed --- lib/app.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/app.js') diff --git a/lib/app.js b/lib/app.js index a76687c..8a74dbb 100644 --- a/lib/app.js +++ b/lib/app.js @@ -270,6 +270,9 @@ 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 }), -- cgit v1.2.3 From 29f56c3e49c767f75164f57ccd1ac52b389794c0 Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 9 May 2017 14:49:03 -1000 Subject: Optimize looking up follow --- lib/app.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'lib/app.js') diff --git a/lib/app.js b/lib/app.js index 8a74dbb..b57e5a6 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) + }) ) } -- cgit v1.2.3 From 1e1d32ef170391da41c2c064fc9a557a1ba667d1 Mon Sep 17 00:00:00 2001 From: _ssb <_ssb@trouble.kagu-tsuchi.com> Date: Wed, 10 May 2017 22:06:25 -0500 Subject: First pass at listing subscribed channels --- lib/app.js | 16 +++++++++++++++ lib/serve.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 70 insertions(+), 12 deletions(-) (limited to 'lib/app.js') diff --git a/lib/app.js b/lib/app.js index b57e5a6..f475bd2 100644 --- a/lib/app.js +++ b/lib/app.js @@ -282,6 +282,22 @@ App.prototype.streamChannels = function (opts) { ) } +App.prototype.streamMyChannels = function (id, opts) { + 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 + }), + pull.unique() + ) +} + App.prototype.createContactStreams = function (id) { return new Contacts(this.sbot).createContactStreams(id) } diff --git a/lib/serve.js b/lib/serve.js index defac87..54516e1 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -543,20 +543,48 @@ Serve.prototype.peers = function (ext) { Serve.prototype.channels = function (ext) { var self = this + var id = self.app.sbot.id + + function renderMyChannels() { + return pull( + self.app.streamMyChannels(id), + paramap(function (channel, cb) { + // var subscribed = false + cb(null, [ + h('a', {href: self.app.render.toUrl('/channel/' + channel)}, '#' + channel), + ' ' + ]) + }, 8), + pull.map(u.toHTML), + self.wrapMyChannels() + ) + } + + function renderNetworkChannels() { + return pull( + self.app.streamChannels(), + paramap(function (channel, cb) { + // var subscribed = false + cb(null, [ + h('a', {href: self.app.render.toUrl('/channel/' + channel)}, '#' + channel), + ' ' + ]) + }, 8), + pull.map(u.toHTML), + self.wrapChannels() + ) + } pull( - self.app.streamChannels(), - paramap(function (channel, cb) { - var subscribed = false - cb(null, [ - h('a', {href: self.app.render.toUrl('/channel/' + channel)}, '#' + channel), - ' ' + cat([ + ph('section', {}, [ + ph('h3', {}, 'Channels:'), + renderMyChannels(), + renderNetworkChannels() ]) - }, 8), - pull.map(u.toHTML), - self.wrapChannels(), - self.wrapPage('channels'), - self.respondSink(200, { + ]), + this.wrapPage('channels'), + this.respondSink(200, { 'Content-Type': ctype(ext) }) ) @@ -1294,7 +1322,21 @@ Serve.prototype.wrapChannels = function (opts) { return u.hyperwrap(function (channels, cb) { cb(null, [ h('section', - h('h3', 'Channels') + h('h4', 'Network') + ), + h('section', + channels + ) + ]) + }) +} + +Serve.prototype.wrapMyChannels = function (opts) { + var self = this + return u.hyperwrap(function (channels, cb) { + cb(null, [ + h('section', + h('h4', 'Subscribed') ), h('section', channels -- cgit v1.2.3 From 24417ffb7f896971664053a13101154e40d6adce Mon Sep 17 00:00:00 2001 From: cel Date: Thu, 11 May 2017 20:25:59 -1000 Subject: Optimize streaming my channels --- lib/app.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/app.js') diff --git a/lib/app.js b/lib/app.js index f475bd2..6990aa5 100644 --- a/lib/app.js +++ b/lib/app.js @@ -283,6 +283,24 @@ App.prototype.streamChannels = function (opts) { } 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(), -- cgit v1.2.3