git ssb

16+

Dominic / patchbay



Tree: 8645df8d5c4edf3b8fe98b8e3b257e80ab48d09d

Files: 8645df8d5c4edf3b8fe98b8e3b257e80ab48d09d / modules_basic / like.js

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

Built with git-ssb-web