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