git ssb

16+

cel / patchfoo



Commit b72224a7c9065b244eaefb889d1fb27a26087949

Add blanket subscribe button

_ssb committed on 5/14/2017, 2:51:15 PM
Parent: 24417ffb7f896971664053a13101154e40d6adce

Files changed

lib/serve.jschanged
lib/serve.jsView
@@ -128,8 +128,9 @@
128128 if (err) next(err)
129129 else if (data.action === 'publish') self.publishJSON(next)
130130 else if (data.action === 'vote') self.publishVote(next)
131131 else if (data.action === 'contact') self.publishContact(next)
132 + else if (data.action === 'togglesub') self.publishSubscription(next)
132133 else next()
133134 }
134135
135136 function next(err, publishedMsg) {
@@ -172,8 +173,17 @@
172173 if (this.data.recps) content.recps = this.data.recps.split(',')
173174 this.publish(content, cb)
174175 }
175176
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 +
176186 Serve.prototype.publishContact = function (cb) {
177187 var content = {
178188 type: 'contact',
179189 contact: this.data.contact,
@@ -548,9 +558,8 @@
548558 function renderMyChannels() {
549559 return pull(
550560 self.app.streamMyChannels(id),
551561 paramap(function (channel, cb) {
552- // var subscribed = false
553562 cb(null, [
554563 h('a', {href: self.app.render.toUrl('/channel/' + channel)}, '#' + channel),
555564 ' '
556565 ])
@@ -563,9 +572,8 @@
563572 function renderNetworkChannels() {
564573 return pull(
565574 self.app.streamChannels(),
566575 paramap(function (channel, cb) {
567- // var subscribed = false
568576 cb(null, [
569577 h('a', {href: self.app.render.toUrl('/channel/' + channel)}, '#' + channel),
570578 ' '
571579 ])
@@ -725,13 +733,18 @@
725733 this.wrapPage('#' + channel),
726734 this.respondSink(400, {'Content-Type': ctype('html')})
727735 )
728736
737 + //TODO
738 + var subscribed = false
739 + //var id = this.app.sbot.id
740 + //this.app.streamMyChannels(id))
741 +
729742 pull(
730743 this.app.sbot.query.read(opts),
731744 this.renderThreadPaginated(opts, null, q),
732745 this.wrapMessages(),
733- this.wrapChannel(channel),
746 + this.wrapChannel(channel, subscribed),
734747 this.wrapPage('#' + channel),
735748 this.respondSink(200, {
736749 'Content-Type': ctype('html')
737750 })
@@ -1255,9 +1268,9 @@
12551268 })
12561269 })
12571270 }
12581271
1259-Serve.prototype.wrapChannel = function (channel) {
1272 +Serve.prototype.wrapChannel = function (channel, subscribed) {
12601273 var self = this
12611274 return u.hyperwrap(function (thread, cb) {
12621275 self.composer({
12631276 placeholder: 'public message in #' + channel,
@@ -1266,9 +1279,15 @@
12661279 if (err) return cb(err)
12671280 cb(null, [
12681281 h('section',
12691282 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 + )
12711290 )
12721291 ),
12731292 composer,
12741293 thread

Built with git-ssb-web