aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-04-29 20:52:20 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-04-29 20:59:37 -1000
commit0cd677474be505a645696c9364d74c8662aeea2b (patch)
tree170d0f88e48b53d0ef3772fdb4e387e05c2c2203 /lib
parenta448b261d6bffa420d1f0c4d57ebe852146001bf (diff)
downloadpatchfoo-0cd677474be505a645696c9364d74c8662aeea2b.tar.gz
patchfoo-0cd677474be505a645696c9364d74c8662aeea2b.zip
Render poll messages
Reference message: %N32nKJ79k1G14lfdtr+4o+c1ftjfW22QChiQmR0oP18=.sha256 &2QHE6nnsg2i9JnFmCLq5fExlPwljCyYQYbfxQMXhONs=.sha256
Diffstat (limited to 'lib')
-rw-r--r--lib/render-msg.js23
-rw-r--r--lib/serve.js20
2 files changed, 43 insertions, 0 deletions
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',