From c7dfaf189024963ea674bf0a191b7d6d956e8e36 Mon Sep 17 00:00:00 2001 From: cel Date: Tue, 8 May 2018 22:03:08 -0400 Subject: Render poll positions --- lib/render-msg.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lib/render-msg.js') 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) + }) +} -- cgit v1.2.3