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