Files: 82f4a4d549b76d66cb7abd2e9ea9246b4bac0db1 / plugs / message / html / render / vote.js
1160 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 | }, |
10 | 'intl.sync.i18n': 'first' |
11 | }) |
12 | |
13 | exports.gives = nest('message.html', { |
14 | canRender: true, |
15 | render: true |
16 | }) |
17 | |
18 | exports.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