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 /lib/serve.js | |
parent | 552d2797bbc61a5a2397d43b03e358f7a9004590 (diff) | |
download | patchfoo-66a1c44a08391be6697a378db3c0b953d2fb766d.tar.gz patchfoo-66a1c44a08391be6697a378db3c0b953d2fb766d.zip |
Publish votes more like other messages
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 68 |
1 files changed, 22 insertions, 46 deletions
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 |