Files: 9ae49c99c4e15aee20a0b51e586caccd37d33d1e / modules / like.js
1288 bytesRaw
1 | |
2 | var h = require('hyperscript') |
3 | var u = require('../util') |
4 | var pull = require('pull-stream') |
5 | |
6 | exports.message_link = [] |
7 | |
8 | exports.message_content = function (msg, sbot) { |
9 | if(msg.value.content.type !== 'vote') return |
10 | var link = msg.value.content.vote.link |
11 | return h('div', msg.value.content.vote.value > 0 ? 'yup' : 'nah', |
12 | u.decorate(exports.message_link, link, function (d, e, v) { return d(e, v, sbot) }) |
13 | ) |
14 | } |
15 | |
16 | exports.message_meta = function (msg, sbot) { |
17 | |
18 | var yupps = h('a') |
19 | |
20 | pull( |
21 | sbot.links({dest: msg.key, rel: 'vote'}), |
22 | pull.collect(function (err, votes) { |
23 | if(votes.length === 1) |
24 | yupps.textContent = ' 1 yup' |
25 | if(votes.length) |
26 | yupps.textContent = ' ' + votes.length + ' yupps' |
27 | }) |
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 | alert(JSON.stringify(yup, null, 2)) |
50 | }}, 'yup') |
51 | |
52 | } |
53 | |
54 | |
55 |
Built with git-ssb-web