From ba3093c15812305dc6749eec4cdfc37ce69f402e Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 14 Apr 2017 00:22:47 -0700 Subject: Add channels page --- lib/serve.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'lib') 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 } -- cgit v1.2.3