git ssb

16+

Dominic / patchbay



Tree: 5e399826faea89305f911f9f2fb8a9509f9a0319

Files: 5e399826faea89305f911f9f2fb8a9509f9a0319 / modules_basic / like.js

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

Built with git-ssb-web