Files: 8435ae7885131874152a7f03cd5055903c5b0906 / modules / like.js
1433 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 ? 'Dug' : 'Undug', |
17 | ' ', message_link(link) |
18 | ) |
19 | } |
20 | |
21 | exports.message_meta = function (msg, sbot) { |
22 | |
23 | var digs = 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 | digs.textContent = ' 1 Dig' |
30 | if(votes.length > 1) |
31 | digs.textContent = ' ' + votes.length + ' Digs' |
32 | }) |
33 | ) |
34 | |
35 | return digs |
36 | } |
37 | |
38 | exports.message_action = function (msg, sbot) { |
39 | if(msg.value.content.type !== 'vote') |
40 | return h('a.dig', {href: '#', onclick: function () { |
41 | var dig = { |
42 | type: 'vote', |
43 | vote: { link: msg.key, value: 1, expression: 'Dig' } |
44 | } |
45 | if(msg.value.content.recps) { |
46 | dig.recps = msg.value.content.recps.map(function (e) { |
47 | return e && typeof e !== 'string' ? e.link : e |
48 | }) |
49 | dig.private = true |
50 | } |
51 | //TODO: actually publish... |
52 | |
53 | message_confirm(dig) |
54 | }}, 'Dig') |
55 | |
56 | } |
57 | |
58 |
Built with git-ssb-web