diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-03-10 10:22:35 -0500 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-03-10 10:40:25 -0500 |
commit | 66a1c44a08391be6697a378db3c0b953d2fb766d (patch) | |
tree | 5cfb805499235a5f6ebb415fca071c1071641cf3 | |
parent | 552d2797bbc61a5a2397d43b03e358f7a9004590 (diff) | |
download | patchfoo-66a1c44a08391be6697a378db3c0b953d2fb766d.tar.gz patchfoo-66a1c44a08391be6697a378db3c0b953d2fb766d.zip |
Publish votes more like other messages
-rw-r--r-- | lib/render-msg.js | 5 | ||||
-rw-r--r-- | lib/serve.js | 68 |
2 files changed, 25 insertions, 48 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js index c99b206..fb4b211 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -108,7 +108,7 @@ RenderMsg.prototype.wrap = function (content, cb) { {href: this.toUrl(this.msg.key)}, this.msg.key)), channel ? [' ', h('a', {href: this.toUrl(channel)}, channel)] : '')), h('td.msg-right', this.msg.key ? - h('form', {method: 'post', action: '/vote'}, + h('form', {method: 'post', action: ''}, this.msg.rel ? [this.msg.rel, ' '] : '', h('a', {href: this.toUrl(this.msg.key) + '?raw'}, 'raw'), ' ', this.voteFormInner('dig') @@ -142,7 +142,7 @@ RenderMsg.prototype.wrapMini = function (content, cb) { this.issues(done()), content), h('td.msg-right', this.msg.key ? - h('form', {method: 'post', action: '/vote'}, + h('form', {method: 'post', action: ''}, this.msg.rel ? [this.msg.rel, ' '] : '', h('a', {href: this.toUrl(this.msg.key) + '?raw'}, 'raw'), ' ', this.voteFormInner('dig') @@ -170,6 +170,7 @@ RenderMsg.prototype.recpsIds = function () { RenderMsg.prototype.voteFormInner = function (expression) { return [ + h('input', {type: 'hidden', name: 'action', value: 'vote'}), h('input', {type: 'hidden', name: 'recps', value: this.recpsIds().join(',')}), h('input', {type: 'hidden', name: 'link', value: this.msg.key}), diff --git a/lib/serve.js b/lib/serve.js index dc20141..188b275 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -107,7 +107,8 @@ Serve.prototype.go = function () { function gotData(err, data) { self.data = data if (err) next(err) - else if (data.action === 'publish') self.publish(next) + else if (data.action === 'publish') self.publishJSON(next) + else if (data.action === 'vote') self.publishVote(next) else next() } @@ -121,14 +122,31 @@ Serve.prototype.go = function () { } } -Serve.prototype.publish = function (cb) { - var self = this +Serve.prototype.publishJSON = function (cb) { var content try { - content = JSON.parse(self.data.content) + content = JSON.parse(this.data.content) } catch(e) { return cb(e) } + this.publish(content, cb) +} + +Serve.prototype.publishVote = function (cb) { + var content = { + type: 'vote', + vote: { + link: this.data.link, + value: Number(this.data.value), + expression: this.data.expression, + } + } + if (this.data.recps) content.recps = this.data.recps.split(',') + this.publish(content, cb) +} + +Serve.prototype.publish = function (content, cb) { + var self = this var done = multicb({pluck: 1, spread: true}) u.toArray(content && content.mentions).forEach(function (mention) { if (mention.link && mention.link[0] === '&' && !isNaN(mention.size)) @@ -327,48 +345,6 @@ Serve.prototype.links = function (path) { ) } -Serve.prototype.vote = function (ext) { - var self = this - - var content = { - type: 'vote', - vote: { - link: self.data.link, - value: self.data.value, - expression: self.data.expression, - } - } - if (self.data.recps) content.recps = self.data.recps.split(',') - self.app.publish(content, function (err, msg) { - if (err) return pull( - pull.once(u.renderError(err).outerHTML), - self.wrapPage(content.vote.expression), - self.respondSink(500, { - 'Content-Type': ctype(ext) - }) - ) - - pull( - pull.once(msg), - pull.asyncMap(self.app.unboxMsg), - self.app.render.renderFeeds(false), - pull.map(u.toHTML), - self.wrapMessages(), - u.hyperwrap(function (content, cb) { - cb(null, h('div', - 'published:', - content - )) - }), - self.wrapPage('published'), - self.respondSink(302, { - 'Content-Type': ctype(ext), - 'Location': self.app.render.toUrl(msg.key) - }) - ) - }) -} - Serve.prototype.rawId = function (id) { var self = this |