Files: 905df22ab68b63477bb10099aff3b6d0c8ef9f09 / message / html / meta / likes.js
799 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, computed, map } = require('mutant') |
3 | const ref = require('ssb-ref') |
4 | |
5 | exports.gives = nest('message.html.meta') |
6 | |
7 | exports.needs = nest({ |
8 | 'about.obs.name': 'first', |
9 | 'message.obs.likes': 'first' |
10 | }) |
11 | |
12 | exports.create = (api) => { |
13 | return nest('message.html.meta', likes) |
14 | |
15 | function likes (msg) { |
16 | if (!ref.isMsgId(msg.key)) return |
17 | |
18 | const symbol = '\u2713' // tick 🗸 |
19 | |
20 | var likes = api.message.obs.likes(msg.key) |
21 | |
22 | var body = computed(likes, likes => likes.length > 4 |
23 | ? likes.length + ' ' + symbol |
24 | : Array(likes.length).fill(symbol).join('') |
25 | ) |
26 | |
27 | var names = map(likes, id => api.about.obs.name(id)) |
28 | var title = computed(names, names => names.map(n => '@' + n).join('\n')) |
29 | |
30 | return h('a.likes', { title }, body) |
31 | } |
32 | } |
33 |
Built with git-ssb-web