diff options
-rw-r--r-- | lib/serve.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/serve.js b/lib/serve.js index fe2ab39..5c73d46 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -225,6 +225,7 @@ Serve.prototype.path = function (url) { case '/search': return this.search(m[2]) case '/vote': return this.vote(m[2]) case '/peers': return this.peers(m[2]) + case '/channels': return this.channels(m[2]) } m = /^(\/?[^\/]*)(\/.*)?$/.exec(url) switch (m[1]) { @@ -406,6 +407,40 @@ Serve.prototype.peers = function (ext) { ) } +Serve.prototype.channels = function (ext) { + var self = this + + pull( + self.app.sbot.messagesByType({type: 'channel', reverse: true}), + paramap(self.app.unboxMsg, 16), + pull.map(function (msg) { + var c = msg.value.content + return c && c.channel + }), + pull.unique(), + paramap(function (channel, cb) { + var subscribed = false + cb(null, h('form', {method: 'post', action: ''}, + h('a', {href: self.app.render.toUrl('#' + channel)}, '#' + channel) + /* + ' ', + h('input', {type: 'hidden', name: 'action', value: 'channel'}), + h('input', {type: 'hidden', name: 'channel', value: channel}), + h('input', {type: 'hidden', name: 'subscribed', value: !subscribed}), + h('input', {type: 'submit', value: subscribed + ? 'unsubscribe' : 'subscribe'}) + */ + )) + }, 8), + pull.map(u.toHTML), + self.wrapChannels(), + self.wrapPage('channels'), + self.respondSink(200, { + 'Content-Type': ctype(ext) + }) + ) +} + Serve.prototype.type = function (path) { var q = this.query @@ -793,6 +828,7 @@ Serve.prototype.wrapPage = function (title, searchQ) { h('a', {href: render.toUrl('/public')}, 'public'), ' ', h('a', {href: render.toUrl('/private')}, 'private') , ' ', h('a', {href: render.toUrl('/peers')}, 'peers') , ' ', + h('a', {href: render.toUrl('/channels')}, 'channels') , ' ', render.idLink(self.app.sbot.id, done()), ' ', h('input.search-input', {name: 'q', value: searchQ, placeholder: 'search'}) @@ -1047,6 +1083,20 @@ Serve.prototype.wrapPeers = function (opts) { }) } +Serve.prototype.wrapChannels = function (opts) { + var self = this + return u.hyperwrap(function (channels, cb) { + cb(null, [ + h('section', + h('h3', 'Channels') + ), + h('section', + channels + ) + ]) + }) +} + function rows(str) { return String(str).split(/[^\n]{150}|\n/).length } |