git ssb

10+

Matt McKegg / patchwork



Tree: a397d2b2add6be261bf7ddda868de8161e8ae5f3

Files: a397d2b2add6be261bf7ddda868de8161e8ae5f3 / plugs / message / html / render / vote.js

1160 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 },
10 'intl.sync.i18n': 'first'
11})
12
13exports.gives = nest('message.html', {
14 canRender: true,
15 render: true
16})
17
18exports.create = function (api) {
19 const i18n = api.intl.sync.i18n
20 return nest('message.html', {
21 canRender: isRenderable,
22 render: function (msg, opts) {
23 if (!isRenderable(msg)) return
24
25 var element = api.message.html.layout(msg, extend({
26 miniContent: messageContent(msg),
27 layout: 'mini',
28 actions: false
29 }, opts))
30
31 return api.message.html.decorate(element, {
32 msg
33 })
34 }
35 })
36
37 function messageContent (msg) {
38 var liked = msg.value.content.vote.value > 0
39 var link = msg.value.content.vote.link
40
41 if (liked) {
42 return [ i18n('liked'), ' ', api.message.html.link(link) ]
43 } else {
44 return [ i18n('unliked'), ' ', api.message.html.link(link) ]
45 }
46 }
47
48 function isRenderable (msg) {
49 return (msg.value.content.type === 'vote' ? true : undefined) && msg.value.content.vote
50 }
51}
52

Built with git-ssb-web