aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-05-08 22:03:08 -0400
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-05-08 22:03:08 -0400
commitc7dfaf189024963ea674bf0a191b7d6d956e8e36 (patch)
tree12036cad3365e01ce04f86b5e9b84a971162d82d
parentb0584f97074489bdd1f5f5a742014874325f4e95 (diff)
downloadpatchfoo-c7dfaf189024963ea674bf0a191b7d6d956e8e36.tar.gz
patchfoo-c7dfaf189024963ea674bf0a191b7d6d956e8e36.zip
Render poll positions
-rw-r--r--lib/render-msg.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 506ccea..98f86e0 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -296,6 +296,7 @@ RenderMsg.prototype.message = function (cb) {
case 'web-init': return this.webInit(cb)
case 'web-root': return this.webRoot(cb)
case 'poll': return this.poll(cb)
+ case 'position': if (this.c.version === 'v1') return this.pollPosition(cb)
default: return this.object(cb)
}
}
@@ -1751,3 +1752,35 @@ RenderMsg.prototype.poll = function (cb) {
}, closeDate.toString()))
), cb)
}
+
+RenderMsg.prototype.pollPosition = function (cb) {
+ var self = this
+ var details = self.c.pollDetails || self.c.details || {}
+ var reason = self.c.reason || ''
+ var done = multicb({pluck: 1, spread: true})
+ self.link(self.c.root, done())
+ self.links(self.c.branch, done())
+ var msgCb = done()
+ self.app.getMsg(self.c.root, function (err, msg) {
+ // ignore error getting root message... it's not that important
+ msgCb(null, msg)
+ })
+ done(function (err, rootLink, branchLinks, rootMsg) {
+ if (err) return cb(err)
+ var rootContent = rootMsg && rootMsg.value.content || {}
+ var rootDetails = rootContent.pollDetails || rootContent.details || {}
+ var choices = u.toArray(rootDetails.choices)
+ var choice = details.choice && choices && choices[details.choice]
+ return self.wrap(h('div',
+ rootLink ? h('div', h('small', h('span.symbol', '→'), ' ', rootLink)) : '',
+ branchLinks.map(function (a, i) {
+ return h('div', h('small', h('span.symbol', '  ↳'), ' ', a))
+ }),
+ h('p',
+ 'picked ',
+ choice ? h('q', choice) : ['choice ', details.choice || '?']
+ ),
+ reason ? h('div', {innerHTML: self.render.markdown(reason, self.c.mentions)}) : ''
+ ), cb)
+ })
+}