git ssb

3+

dangerousbeans / scuttle-vue



Tree: b65df85068d01bbc7fd6b0ba8686cccbae6928ee

Files: b65df85068d01bbc7fd6b0ba8686cccbae6928ee / modules / dig.js

1798 bytesRaw
1var h = require('hyperscript')
2var u = require('../util')
3var pull = require('pull-stream')
4
5exports.needs = {
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.vote != null) {
37 if(CACHE[k].content.type == 'vote' &&
38 (CACHE[k].content.vote == msg.key ||
39 CACHE[k].content.vote.link == msg.key
40 ))
41 votes.push({source: CACHE[k].author, dest: k, rel: 'vote'})
42 }
43 }
44
45 if(votes.length === 1)
46 digs.textContent = ' 1 Dig'
47 if(votes.length > 1)
48 digs.textContent = ' ' + votes.length + ' Digs'
49
50 return digs
51 }
52
53 exports.message_action = function (msg, sbot) {
54 if(msg.value.content.type !== 'vote')
55 return h('a.dig', {href: '#', onclick: function (e) {
56 e.preventDefault()
57 var dig = {
58 type: 'vote',
59 vote: { link: msg.key, value: 1, expression: 'Dig' }
60 }
61 if(msg.value.content.recps) {
62 dig.recps = msg.value.content.recps.map(function (e) {
63 return e && typeof e !== 'string' ? e.link : e
64 })
65 dig.private = true
66 }
67 api.message_confirm(dig)
68 }}, 'Dig')
69
70 }
71 return exports
72}
73

Built with git-ssb-web