Files: b62ecd6f843b26f37e70c7b6d65c71db35bbf922 / modules / like.js
1803 bytesRaw
1 | var h = require('hyperscript') |
2 | var u = require('../util') |
3 | var pull = require('pull-stream') |
4 | |
5 | var plugs = require('../plugs') |
6 | |
7 | exports.needs = { |
8 | message_confirm: 'first', |
9 | message_link: 'first', |
10 | sbot_links: 'first' |
11 | } |
12 | |
13 | exports.gives = { |
14 | message_content: true, |
15 | message_content_mini: true, |
16 | message_meta: true, |
17 | message_action: true |
18 | } |
19 | |
20 | exports.create = function (api) { |
21 | var exports = {} |
22 | |
23 | exports.message_content = |
24 | exports.message_content_mini = function (msg, sbot) { |
25 | if(msg.value.content.type !== 'vote') return |
26 | var link = msg.value.content.vote.link |
27 | return [ |
28 | msg.value.content.vote.value > 0 ? 'dug' : 'undug', |
29 | ' ', api.message_link(link) |
30 | ] |
31 | } |
32 | |
33 | exports.message_meta = function (msg, sbot) { |
34 | var digs = h('a') |
35 | |
36 | var votes = [] |
37 | for(var k in CACHE) { |
38 | if (CACHE[k].content.vote != null) { |
39 | if(CACHE[k].content.type == 'vote' && |
40 | (CACHE[k].content.vote == msg.key || |
41 | CACHE[k].content.vote.link == msg.key |
42 | )) |
43 | votes.push({source: CACHE[k].author, dest: k, rel: 'vote'}) |
44 | } |
45 | } |
46 | |
47 | if(votes.length === 1) |
48 | digs.textContent = ' 1 Dig' |
49 | if(votes.length > 1) |
50 | digs.textContent = ' ' + votes.length + ' Digs' |
51 | |
52 | return digs |
53 | } |
54 | |
55 | exports.message_action = function (msg, sbot) { |
56 | if(msg.value.content.type !== 'vote') |
57 | return h('a.dig', {href: '#', onclick: function () { |
58 | var dig = { |
59 | type: 'vote', |
60 | vote: { link: msg.key, value: 1, expression: 'Dig' } |
61 | } |
62 | if(msg.value.content.recps) { |
63 | dig.recps = msg.value.content.recps.map(function (e) { |
64 | return e && typeof e !== 'string' ? e.link : e |
65 | }) |
66 | dig.private = true |
67 | } |
68 | api.message_confirm(dig) |
69 | }}, 'Dig') |
70 | |
71 | } |
72 | return exports |
73 | } |
74 |
Built with git-ssb-web