git ssb

16+

Dominic / patchbay



Tree: bb8a40e081fb697ecee889adac26fb6f83e45ef5

Files: bb8a40e081fb697ecee889adac26fb6f83e45ef5 / modules / like.js

1433 bytesRaw
1
2var h = require('hyperscript')
3var u = require('../util')
4var pull = require('pull-stream')
5
6var plugs = require('../plugs')
7
8var message_confirm = plugs.first(exports.message_confirm = [])
9var message_link = plugs.first(exports.message_link = [])
10var sbot_links = plugs.first(exports.sbot_links = [])
11
12exports.message_content = function (msg, sbot) {
13 if(msg.value.content.type !== 'vote') return
14 var link = msg.value.content.vote.link
15 return h('div',
16 msg.value.content.vote.value > 0 ? 'Dug' : 'Undug',
17 ' ', message_link(link)
18 )
19}
20
21exports.message_meta = function (msg, sbot) {
22
23 var digs = h('a')
24
25 pull(
26 sbot_links({dest: msg.key, rel: 'vote'}),
27 pull.collect(function (err, votes) {
28 if(votes.length === 1)
29 digs.textContent = ' 1 Dig'
30 if(votes.length > 1)
31 digs.textContent = ' ' + votes.length + ' Digs'
32 })
33 )
34
35 return digs
36}
37
38exports.message_action = function (msg, sbot) {
39 if(msg.value.content.type !== 'vote')
40 return h('a.dig', {href: '#', onclick: function () {
41 var dig = {
42 type: 'vote',
43 vote: { link: msg.key, value: 1, expression: 'Dig' }
44 }
45 if(msg.value.content.recps) {
46 dig.recps = msg.value.content.recps.map(function (e) {
47 return e && typeof e !== 'string' ? e.link : e
48 })
49 dig.private = true
50 }
51 //TODO: actually publish...
52
53 message_confirm(dig)
54 }}, 'Dig')
55
56}
57
58

Built with git-ssb-web