git ssb

16+

cel / patchfoo



Commit 66a1c44a08391be6697a378db3c0b953d2fb766d

Publish votes more like other messages

cel committed on 3/10/2017, 3:40:25 PM
Parent: 552d2797bbc61a5a2397d43b03e358f7a9004590

Files changed

lib/render-msg.jschanged
lib/serve.jschanged
lib/render-msg.jsView
@@ -107,9 +107,9 @@
107107 h('code', h('a.ssb-id',
108108 {href: this.toUrl(this.msg.key)}, this.msg.key)),
109109 channel ? [' ', h('a', {href: this.toUrl(channel)}, channel)] : '')),
110110 h('td.msg-right', this.msg.key ?
111- h('form', {method: 'post', action: '/vote'},
111 + h('form', {method: 'post', action: ''},
112112 this.msg.rel ? [this.msg.rel, ' '] : '',
113113 h('a', {href: this.toUrl(this.msg.key) + '?raw'}, 'raw'), ' ',
114114 this.voteFormInner('dig')
115115 ) : [
@@ -141,9 +141,9 @@
141141 }, htime(date)), ' ',
142142 this.issues(done()),
143143 content),
144144 h('td.msg-right', this.msg.key ?
145- h('form', {method: 'post', action: '/vote'},
145 + h('form', {method: 'post', action: ''},
146146 this.msg.rel ? [this.msg.rel, ' '] : '',
147147 h('a', {href: this.toUrl(this.msg.key) + '?raw'}, 'raw'), ' ',
148148 this.voteFormInner('dig')
149149 ) : [
@@ -169,8 +169,9 @@
169169 }
170170
171171 RenderMsg.prototype.voteFormInner = function (expression) {
172172 return [
173 + h('input', {type: 'hidden', name: 'action', value: 'vote'}),
173174 h('input', {type: 'hidden', name: 'recps',
174175 value: this.recpsIds().join(',')}),
175176 h('input', {type: 'hidden', name: 'link', value: this.msg.key}),
176177 h('input', {type: 'hidden', name: 'value', value: 1}),
lib/serve.jsView
@@ -106,9 +106,10 @@
106106
107107 function gotData(err, data) {
108108 self.data = data
109109 if (err) next(err)
110- else if (data.action === 'publish') self.publish(next)
110 + else if (data.action === 'publish') self.publishJSON(next)
111 + else if (data.action === 'vote') self.publishVote(next)
111112 else next()
112113 }
113114
114115 function next(err) {
@@ -120,16 +121,33 @@
120121 }
121122 }
122123 }
123124
124-Serve.prototype.publish = function (cb) {
125- var self = this
125 +Serve.prototype.publishJSON = function (cb) {
126126 var content
127127 try {
128- content = JSON.parse(self.data.content)
128 + content = JSON.parse(this.data.content)
129129 } catch(e) {
130130 return cb(e)
131131 }
132 + this.publish(content, cb)
133 +}
134 +
135 +Serve.prototype.publishVote = function (cb) {
136 + var content = {
137 + type: 'vote',
138 + vote: {
139 + link: this.data.link,
140 + value: Number(this.data.value),
141 + expression: this.data.expression,
142 + }
143 + }
144 + if (this.data.recps) content.recps = this.data.recps.split(',')
145 + this.publish(content, cb)
146 +}
147 +
148 +Serve.prototype.publish = function (content, cb) {
149 + var self = this
132150 var done = multicb({pluck: 1, spread: true})
133151 u.toArray(content && content.mentions).forEach(function (mention) {
134152 if (mention.link && mention.link[0] === '&' && !isNaN(mention.size))
135153 self.app.pushBlob(mention.link, done())
@@ -326,50 +344,8 @@
326344 })
327345 )
328346 }
329347
330-Serve.prototype.vote = function (ext) {
331- var self = this
332-
333- var content = {
334- type: 'vote',
335- vote: {
336- link: self.data.link,
337- value: self.data.value,
338- expression: self.data.expression,
339- }
340- }
341- if (self.data.recps) content.recps = self.data.recps.split(',')
342- self.app.publish(content, function (err, msg) {
343- if (err) return pull(
344- pull.once(u.renderError(err).outerHTML),
345- self.wrapPage(content.vote.expression),
346- self.respondSink(500, {
347- 'Content-Type': ctype(ext)
348- })
349- )
350-
351- pull(
352- pull.once(msg),
353- pull.asyncMap(self.app.unboxMsg),
354- self.app.render.renderFeeds(false),
355- pull.map(u.toHTML),
356- self.wrapMessages(),
357- u.hyperwrap(function (content, cb) {
358- cb(null, h('div',
359- 'published:',
360- content
361- ))
362- }),
363- self.wrapPage('published'),
364- self.respondSink(302, {
365- 'Content-Type': ctype(ext),
366- 'Location': self.app.render.toUrl(msg.key)
367- })
368- )
369- })
370-}
371-
372348 Serve.prototype.rawId = function (id) {
373349 var self = this
374350
375351 self.app.getMsgDecrypted(id, function (err, msg) {

Built with git-ssb-web