git ssb

16+

Dominic / patchbay



Tree: eedc2fe6825e871a92ed902f67846829bc6e7509

Files: eedc2fe6825e871a92ed902f67846829bc6e7509 / modules / like.js

1405 bytesRaw
1
2var h = require('hyperscript')
3var u = require('../util')
4var pull = require('pull-stream')
5
6var plugs = require('../plugs')
7
8var message_confirm = plugs.first(exports.message_confirm = [])
9var message_link = plugs.first(exports.message_link = [])
10var sbot_links = plugs.first(exports.sbot_links = [])
11
12exports.message_content = function (msg, sbot) {
13 if(msg.value.content.type !== 'vote') return
14 var link = msg.value.content.vote.link
15 return h('div',
16 msg.value.content.vote.value > 0 ? 'yup' : 'nah',
17 ' ', message_link(link)
18 )
19}
20
21exports.message_meta = function (msg, sbot) {
22
23 var yupps = h('a')
24
25 pull(
26 sbot_links({dest: msg.key, rel: 'vote'}),
27 pull.collect(function (err, votes) {
28 if(votes.length === 1)
29 yupps.textContent = ' 1 yup'
30 if(votes.length)
31 yupps.textContent = ' ' + votes.length + ' yupps'
32 })
33 )
34
35 return yupps
36}
37
38exports.message_action = function (msg, sbot) {
39 if(msg.value.content.type !== 'vote')
40 return h('a', {href: '#', onclick: function () {
41 var yup = {
42 type: 'vote',
43 vote: { link: msg.key, value: 1, expression: 'yup' }
44 }
45 if(msg.value.content.recps) {
46 yup.recps = msg.value.content.recps.map(function (e) {
47 return e.link || e
48 })
49 yup.private = true
50 }
51 //TODO: actually publish...
52
53 message_confirm(yup)
54 }}, 'yup')
55
56}
57
58
59
60
61
62
63

Built with git-ssb-web