aboutsummaryrefslogtreecommitdiff
path: root/lib/render-msg.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/render-msg.js')
-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)
+ })
+}