Files: 798d7ea858881504d038705f550581dd75eabaa3 / modules / like.js
1405 bytesRaw
1 | |
2 | var h = require('hyperscript') |
3 | var u = require('../util') |
4 | var pull = require('pull-stream') |
5 | |
6 | var plugs = require('../plugs') |
7 | |
8 | var message_confirm = plugs.first(exports.message_confirm = []) |
9 | var message_link = plugs.first(exports.message_link = []) |
10 | var sbot_links = plugs.first(exports.sbot_links = []) |
11 | |
12 | exports.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 | |
21 | exports.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 | |
38 | exports.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