From 0cd677474be505a645696c9364d74c8662aeea2b Mon Sep 17 00:00:00 2001 From: cel Date: Sun, 29 Apr 2018 20:52:20 -1000 Subject: Render poll messages Reference message: %N32nKJ79k1G14lfdtr+4o+c1ftjfW22QChiQmR0oP18=.sha256 &2QHE6nnsg2i9JnFmCLq5fExlPwljCyYQYbfxQMXhONs=.sha256 --- lib/render-msg.js | 23 +++++++++++++++++++++++ lib/serve.js | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'lib') diff --git a/lib/render-msg.js b/lib/render-msg.js index 68c8147..f749328 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -294,6 +294,7 @@ RenderMsg.prototype.message = function (cb) { case 'line-comment': return this.lineComment(cb) case 'web-init': return this.webInit(cb) case 'web-root': return this.webRoot(cb) + case 'poll': return this.poll(cb) default: return this.object(cb) } } @@ -1712,3 +1713,25 @@ RenderMsg.prototype.webRoot = function (cb) { ] : '' ), cb) } + +RenderMsg.prototype.poll = function (cb) { + var self = this + var closeDate = new Date(self.c.closesAt) + var details = self.c.pollDetails || {} + var choices = u.toArray(details.choices) + return self.wrap(h('div', + h('h3', {innerHTML: unwrapP(self.render.markdown(self.c.title))}), + h('div', {innerHTML: unwrapP(self.render.markdown(self.c.body, self.c.mentions))}), + details.type === 'chooseOne' ? h('form', {method: 'post', action: ''}, + h('input', {type: 'hidden', name: 'action', value: 'poll-position'}), + h('input', {type: 'hidden', name: 'poll_root', value: self.msg.key}), + h('input', {type: 'hidden', name: 'poll_type', value: 'chooseOne'}), + choices.map(function (choice) { + return [h('input', {type: 'submit', name: 'poll_choice', value: choice}), ' '] + }) + ) : h('div', 'unknown poll type'), + h('p', 'closes at: ', h('span', { + title: closeDate.toLocaleString() + }, closeDate.toString())) + ), cb) +} diff --git a/lib/serve.js b/lib/serve.js index e50caa8..7045b30 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -153,6 +153,7 @@ Serve.prototype.go = function () { else if (data.action === 'publish') self.publishJSON(next) else if (data.action === 'contact') self.publishContact(next) else if (data.action === 'want-blobs') self.wantBlobs(next) + else if (data.action === 'poll-position') self.publishPollPosition(next) else if (data.action_vote) self.publishVote(next) else if (data.action_attend) self.publishAttend(next) else next() @@ -225,6 +226,25 @@ Serve.prototype.publishContact = function (next) { } } +Serve.prototype.publishPollPosition = function (cb) { + var content = { + type: 'position', + version: 'v1', + channel: this.data.channel || undefined, + root: this.data.poll_root, + details: { + type: this.data.poll_type, + choice: this.data.poll_choice + } + } + if (this.data.recps) content.recps = this.data.recps.split(',') + var json = JSON.stringify(content, 0, 2) + var q = qs.stringify({text: json, action: 'preview'}) + var url = this.app.render.toUrl('/compose?' + q) + this.redirect(url) + // this.publish(content, cb) +} + Serve.prototype.publishAttend = function (cb) { var content = { type: 'about', -- cgit v1.2.3