diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-04-14 00:22:47 -0700 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-04-14 00:36:54 -0700 |
commit | ba3093c15812305dc6749eec4cdfc37ce69f402e (patch) | |
tree | 45f5458fb59966d6f8fd578dff25fccd958663c6 | |
parent | 89ffc2a6abb2aff80e786513e0580eb49cf73eea (diff) | |
download | patchfoo-ba3093c15812305dc6749eec4cdfc37ce69f402e.tar.gz patchfoo-ba3093c15812305dc6749eec4cdfc37ce69f402e.zip |
Add channels page
-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 } |