git ssb

10+

Matt McKegg / patchwork



Tree: c99630ba531d862b38a3a4e85b19b203f19d47d8

Files: c99630ba531d862b38a3a4e85b19b203f19d47d8 / plugs / message / html / meta / likes.js

786 bytesRaw
1var nest = require('depnest')
2var { h, computed, map } = require('mutant')
3exports.gives = nest('message.html.meta')
4exports.needs = nest({
5 'message.obs.likes': 'first',
6 'about.obs.name': 'first'
7})
8
9exports.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 }, [`${likes.length} ${likes.length === 1 ? 'like' : 'likes'}`])]
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