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