Commit b72224a7c9065b244eaefb889d1fb27a26087949
Add blanket subscribe button
_ssb committed on 5/14/2017, 2:51:15 PMParent: 24417ffb7f896971664053a13101154e40d6adce
Files changed
lib/serve.js | changed |
lib/serve.js | ||
---|---|---|
@@ -128,8 +128,9 @@ | ||
128 | 128 … | if (err) next(err) |
129 | 129 … | else if (data.action === 'publish') self.publishJSON(next) |
130 | 130 … | else if (data.action === 'vote') self.publishVote(next) |
131 | 131 … | else if (data.action === 'contact') self.publishContact(next) |
132 … | + else if (data.action === 'togglesub') self.publishSubscription(next) | |
132 | 133 … | else next() |
133 | 134 … | } |
134 | 135 … | |
135 | 136 … | function next(err, publishedMsg) { |
@@ -172,8 +173,17 @@ | ||
172 | 173 … | if (this.data.recps) content.recps = this.data.recps.split(',') |
173 | 174 … | this.publish(content, cb) |
174 | 175 … | } |
175 | 176 … | |
177 … | +Serve.prototype.publishSubscription = function (cb) { | |
178 … | + var content = { | |
179 … | + type: 'channel', | |
180 … | + channel: this.data.channel, | |
181 … | + subscribed: this.data.subscription | |
182 … | + } | |
183 … | + this.publish(content, cb) | |
184 … | +} | |
185 … | + | |
176 | 186 … | Serve.prototype.publishContact = function (cb) { |
177 | 187 … | var content = { |
178 | 188 … | type: 'contact', |
179 | 189 … | contact: this.data.contact, |
@@ -548,9 +558,8 @@ | ||
548 | 558 … | function renderMyChannels() { |
549 | 559 … | return pull( |
550 | 560 … | self.app.streamMyChannels(id), |
551 | 561 … | paramap(function (channel, cb) { |
552 | - // var subscribed = false | |
553 | 562 … | cb(null, [ |
554 | 563 … | h('a', {href: self.app.render.toUrl('/channel/' + channel)}, '#' + channel), |
555 | 564 … | ' ' |
556 | 565 … | ]) |
@@ -563,9 +572,8 @@ | ||
563 | 572 … | function renderNetworkChannels() { |
564 | 573 … | return pull( |
565 | 574 … | self.app.streamChannels(), |
566 | 575 … | paramap(function (channel, cb) { |
567 | - // var subscribed = false | |
568 | 576 … | cb(null, [ |
569 | 577 … | h('a', {href: self.app.render.toUrl('/channel/' + channel)}, '#' + channel), |
570 | 578 … | ' ' |
571 | 579 … | ]) |
@@ -725,13 +733,18 @@ | ||
725 | 733 … | this.wrapPage('#' + channel), |
726 | 734 … | this.respondSink(400, {'Content-Type': ctype('html')}) |
727 | 735 … | ) |
728 | 736 … | |
737 … | + //TODO | |
738 … | + var subscribed = false | |
739 … | + //var id = this.app.sbot.id | |
740 … | + //this.app.streamMyChannels(id)) | |
741 … | + | |
729 | 742 … | pull( |
730 | 743 … | this.app.sbot.query.read(opts), |
731 | 744 … | this.renderThreadPaginated(opts, null, q), |
732 | 745 … | this.wrapMessages(), |
733 | - this.wrapChannel(channel), | |
746 … | + this.wrapChannel(channel, subscribed), | |
734 | 747 … | this.wrapPage('#' + channel), |
735 | 748 … | this.respondSink(200, { |
736 | 749 … | 'Content-Type': ctype('html') |
737 | 750 … | }) |
@@ -1255,9 +1268,9 @@ | ||
1255 | 1268 … | }) |
1256 | 1269 … | }) |
1257 | 1270 … | } |
1258 | 1271 … | |
1259 | -Serve.prototype.wrapChannel = function (channel) { | |
1272 … | +Serve.prototype.wrapChannel = function (channel, subscribed) { | |
1260 | 1273 … | var self = this |
1261 | 1274 … | return u.hyperwrap(function (thread, cb) { |
1262 | 1275 … | self.composer({ |
1263 | 1276 … | placeholder: 'public message in #' + channel, |
@@ -1266,9 +1279,15 @@ | ||
1266 | 1279 … | if (err) return cb(err) |
1267 | 1280 … | cb(null, [ |
1268 | 1281 … | h('section', |
1269 | 1282 … | h('h3.feed-name', |
1270 | - h('a', {href: self.app.render.toUrl('/channel/' + channel)}, '#' + channel) | |
1283 … | + h('a', {href: self.app.render.toUrl('/channel/' + channel)}, '#' + channel), | |
1284 … | + h('form', {method: 'post', action: ''}, | |
1285 … | + h('input', {type: 'hidden', name: 'action', value: 'togglesub'}), | |
1286 … | + h('input', {type: 'hidden', name: 'subscription', value: !!subscribed}), | |
1287 … | + h('input', {type: 'hidden', name: 'channel', value: channel}), | |
1288 … | + h('input', {type: 'submit', name: 'togglesub', value: (subscribed ? 'Unsubscribe' : 'Subscribe')}) | |
1289 … | + ) | |
1271 | 1290 … | ) |
1272 | 1291 … | ), |
1273 | 1292 … | composer, |
1274 | 1293 … | thread |
Built with git-ssb-web