Files: dbd346b4290841ab443bf51f71e9b5231b244870 / modules / like.js
1560 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 | var digs = h('a') |
23 | |
24 | var votes = [] |
25 | for(var k in CACHE) { |
26 | if(CACHE[k].content.type == 'vote' && |
27 | (CACHE[k].content.vote == msg.key || |
28 | CACHE[k].content.vote.link == msg.key |
29 | )) |
30 | votes.push({source: CACHE[k].author, dest: k, rel: 'vote'}) |
31 | } |
32 | |
33 | if(votes.length === 1) |
34 | digs.textContent = ' 1 Dig' |
35 | if(votes.length > 1) |
36 | digs.textContent = ' ' + votes.length + ' Digs' |
37 | |
38 | return digs |
39 | } |
40 | |
41 | exports.message_action = function (msg, sbot) { |
42 | if(msg.value.content.type !== 'vote') |
43 | return h('a.dig', {href: '#', onclick: function () { |
44 | var dig = { |
45 | type: 'vote', |
46 | vote: { link: msg.key, value: 1, expression: 'Dig' } |
47 | } |
48 | if(msg.value.content.recps) { |
49 | dig.recps = msg.value.content.recps.map(function (e) { |
50 | return e && typeof e !== 'string' ? e.link : e |
51 | }) |
52 | dig.private = true |
53 | } |
54 | //TODO: actually publish... |
55 | |
56 | message_confirm(dig) |
57 | }}, 'Dig') |
58 | |
59 | } |
60 | |
61 |
Built with git-ssb-web