git ssb

16+

Dominic / patchbay



Tree: f6391d5b5450e27f0c7a8dba7d82a53c4ad2634a

Files: f6391d5b5450e27f0c7a8dba7d82a53c4ad2634a / modules_basic / like.js

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

Built with git-ssb-web