Files: a3d2c0a84691aab64838207f75583d4e86d564b5 / modules_basic / like.js
2233 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.needs = { |
13 | avatar_name: 'first', |
14 | message_confirm: 'first', |
15 | message_link: 'first', |
16 | sbot_links: 'first' |
17 | } |
18 | |
19 | exports.gives = { |
20 | message_content: true, |
21 | message_content_mini: true, |
22 | message_meta: true, |
23 | message_action: true |
24 | } |
25 | |
26 | exports.create = function (api) { |
27 | var exports = {} |
28 | |
29 | exports.message_content = |
30 | exports.message_content_mini = function (msg, sbot) { |
31 | if(msg.value.content.type !== 'vote') return |
32 | var link = msg.value.content.vote.link |
33 | return [ |
34 | msg.value.content.vote.value > 0 ? 'dug' : 'undug', |
35 | ' ', api.message_link(link) |
36 | ] |
37 | } |
38 | |
39 | exports.message_meta = function (msg, sbot) { |
40 | var digs = h('a') |
41 | |
42 | var votes = [] |
43 | for(var k in CACHE) { |
44 | if(CACHE[k].content.type == 'vote' && |
45 | (CACHE[k].content.vote == msg.key || |
46 | CACHE[k].content.vote.link == msg.key |
47 | )) |
48 | votes.push({source: CACHE[k].author, dest: k, rel: 'vote'}) |
49 | } |
50 | |
51 | if(votes.length === 1) |
52 | digs.textContent = ' 1 Dig' |
53 | else if(votes.length > 1) |
54 | digs.textContent = ' ' + votes.length + ' Digs' |
55 | |
56 | pull( |
57 | pull.values(votes.map(vote => { |
58 | return api.avatar_name(vote.source) |
59 | })), |
60 | pull.collect(function (err, ary) { |
61 | digs.title = ary.map(x => x.innerHTML).join(" ") |
62 | }) |
63 | ) |
64 | |
65 | return digs |
66 | } |
67 | |
68 | exports.message_action = function (msg, sbot) { |
69 | if(msg.value.content.type !== 'vote') |
70 | return h('a.dig', {href: '#', onclick: function () { |
71 | var dig = { |
72 | type: 'vote', |
73 | vote: { link: msg.key, value: 1, expression: 'Dig' } |
74 | } |
75 | if(msg.value.content.recps) { |
76 | dig.recps = msg.value.content.recps.map(function (e) { |
77 | return e && typeof e !== 'string' ? e.link : e |
78 | }) |
79 | dig.private = true |
80 | } |
81 | //TODO: actually publish... |
82 | |
83 | api.message_confirm(dig) |
84 | }}, 'Dig') |
85 | |
86 | } |
87 | return exports |
88 | } |
89 |
Built with git-ssb-web