Files: e0439586cabe63fc84e88ff400edb18470cdec52 / message / html / render / vote.js
978 bytesRaw
1 | var nest = require('depnest') |
2 | var extend = require('xtend') |
3 | |
4 | exports.needs = nest({ |
5 | 'message.html': { |
6 | decorate: 'reduce', |
7 | layout: 'first', |
8 | link: 'first', |
9 | markdown: 'first' |
10 | } |
11 | }) |
12 | |
13 | exports.gives = nest({ |
14 | 'message.html': { |
15 | canRender: true, |
16 | render: true |
17 | } |
18 | }) |
19 | |
20 | exports.create = function (api) { |
21 | return nest('message.html', { |
22 | canRender: isRenderable, |
23 | render: vote |
24 | }) |
25 | |
26 | function vote (msg, opts) { |
27 | if (!isRenderable(msg)) return |
28 | var element = api.message.html.layout(msg, extend({ |
29 | content: renderContent(msg), |
30 | layout: 'mini' |
31 | }, opts)) |
32 | |
33 | return api.message.html.decorate(element, { msg }) |
34 | } |
35 | |
36 | function isRenderable (msg) { |
37 | return (msg.value.content.type === 'vote' ? true : undefined) && msg.value.content.vote |
38 | } |
39 | |
40 | function renderContent (msg) { |
41 | var link = msg.value.content.vote.link |
42 | return [ |
43 | msg.value.content.vote.value > 0 ? 'dug' : 'undug', ' ', api.message.html.link(link) |
44 | ] |
45 | } |
46 | } |
47 |
Built with git-ssb-web