git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: e901f4d90b0fa34e6b3cfa86b0c8f5f223ba731d

Files: e901f4d90b0fa34e6b3cfa86b0c8f5f223ba731d / message / html / render / vote.js

977 bytesRaw
1var h = require('mutant/h')
2var nest = require('depnest')
3var extend = require('xtend')
4
5exports.needs = nest({
6 'message.html': {
7 decorate: 'reduce',
8 layout: 'first',
9 link: 'first',
10 markdown: 'first'
11 }
12})
13
14exports.gives = nest({
15 'message.html': {
16 canRender: true,
17 render: true
18 }
19})
20
21exports.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