git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: bcf23f7ed7e27cc8755003023c9fd57775f79ca9

Files: bcf23f7ed7e27cc8755003023c9fd57775f79ca9 / contact / async.js

1457 bytesRaw
1var nest = require('depnest')
2var onceTrue = require('mutant/once-true')
3var resolve = require('mutant/resolve')
4var ref = require('ssb-ref')
5
6exports.needs = nest({
7 'contact.obs.following': 'first',
8 'sbot.async.publish': 'first',
9 'sbot.async.friendsGet': 'first'
10})
11
12exports.gives = nest({
13 'contact.async': ['follow', 'unfollow', 'followerOf', 'block', 'unblock']
14})
15
16exports.create = function (api) {
17 return nest({
18 'contact.async': {follow, unfollow, followerOf, block, unblock}
19 })
20
21 function followerOf (source, dest, cb) {
22 api.sbot.async.friendsGet({source: source, dest: dest}, cb)
23 }
24
25 function follow (id, cb) {
26 if (!ref.isFeed(id)) throw new Error('a feed id must be specified')
27 api.sbot.async.publish({
28 type: 'contact',
29 contact: id,
30 following: true
31 }, cb)
32 }
33
34 function unfollow (id, cb) {
35 if (!ref.isFeed(id)) throw new Error('a feed id must be specified')
36 api.sbot.async.publish({
37 type: 'contact',
38 contact: id,
39 following: false
40 }, cb)
41 }
42
43 function block (id, cb) {
44 if (!ref.isFeed(id)) throw new Error('a feed id must be specified')
45 api.sbot.async.publish({
46 type: 'contact',
47 contact: id,
48 blocking: true
49 }, cb)
50 }
51
52 function unblock (id, cb) {
53 if (!ref.isFeed(id)) throw new Error('a feed id must be specified')
54 api.sbot.async.publish({
55 type: 'contact',
56 contact: id,
57 blocking: false
58 }, cb)
59 }
60}
61
62

Built with git-ssb-web