git ssb

2+

mixmix / ticktack



Tree: 4a58e38afe8d7cd5659d286607457aeb91ee7638

Files: 4a58e38afe8d7cd5659d286607457aeb91ee7638 / message / html / likes.js

1293 bytesRaw
1var { h, computed, when } = require('mutant')
2var nest = require('depnest')
3
4exports.needs = nest({
5 'keys.sync.id': 'first',
6 'message.obs.likes': 'first',
7 'sbot.async.publish': 'first'
8})
9
10exports.gives = nest('message.html.likes')
11
12exports.create = (api) => {
13 return nest('message.html.likes', function likes (msg) {
14 var id = api.keys.sync.id()
15 var likes = api.message.obs.likes(msg.key)
16 var iLike = computed(likes, likes => likes.includes(id))
17 var count = computed(likes, likes => likes.length ? likes.length : '')
18
19 return h('Likes', {'ev-click': () => publishLike(msg, !iLike())}, [
20 h('i.fa', { className: when(iLike, 'fa-heart', 'fa-heart-o') }),
21 h('div.count', count)
22 ])
23 })
24
25 function publishLike (msg, status = true) {
26 var like = status ? {
27 type: 'vote',
28 channel: msg.value.content.channel,
29 vote: { link: msg.key, value: 1, expression: 'Like' }
30 } : {
31 type: 'vote',
32 channel: msg.value.content.channel,
33 vote: { link: msg.key, value: 0, expression: 'Unlike' }
34 }
35 if (msg.value.content.recps) {
36 like.recps = msg.value.content.recps.map(function (e) {
37 return e && typeof e !== 'string' ? e.link : e
38 })
39 like.private = true
40 }
41 api.sbot.async.publish(like)
42 }
43}
44
45

Built with git-ssb-web