Files: 0bc52a13a9c729a0b10e7f1bc22d167d5945ce75 / plugs / message / html / meta / likes.js
736 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 | return computed(api.message.obs.likes(msg.key), likeCount) |
12 | }) |
13 | |
14 | function likeCount (likes) { |
15 | if (likes.length) { |
16 | return [' ', h('span.likes', { |
17 | title: names(likes) |
18 | }, ['+', h('strong', `${likes.length}`)])] |
19 | } |
20 | } |
21 | |
22 | function names (ids) { |
23 | var items = map(ids, api.about.obs.name) |
24 | return computed([items], (names) => { |
25 | return 'Liked by\n' + names.map((n) => `- ${n}`).join('\n') |
26 | }) |
27 | } |
28 | } |
29 |
Built with git-ssb-web