git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: 2faca8a26207e316f21cadb9222ed640b7e76c16

Files: 2faca8a26207e316f21cadb9222ed640b7e76c16 / contact / async.js

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

Built with git-ssb-web