git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: e0439586cabe63fc84e88ff400edb18470cdec52

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

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