Files: 17236ac5e18acf335d5de82f03996bd6558a3d84 / plugs / message / html / meta / likes.js
763 bytesRaw
1 | var nest = require('depnest') |
2 | var { h, computed, map } = require('mutant') |
3 | exports.gives = nest('message.html.meta') |
4 | exports.needs = nest({ |
5 | 'message.obs.likes': 'first', |
6 | 'about.obs.name': 'first' |
7 | }) |
8 | |
9 | exports.create = function (api) { |
10 | return nest('message.html.meta', function likes (msg) { |
11 | if (msg.key) { |
12 | return computed(api.message.obs.likes(msg.key), likeCount) |
13 | } |
14 | }) |
15 | |
16 | function likeCount (likes) { |
17 | if (likes.length) { |
18 | return [' ', h('span.likes', { |
19 | title: names(likes) |
20 | }, ['+', h('strong', `${likes.length}`)])] |
21 | } |
22 | } |
23 | |
24 | function names (ids) { |
25 | var items = map(ids, api.about.obs.name) |
26 | return computed([items], (names) => { |
27 | return 'Liked by\n' + names.map((n) => `- ${n}`).join('\n') |
28 | }) |
29 | } |
30 | } |
31 |
Built with git-ssb-web