git ssb

1+

Daan Patchwork / patchwork



Tree: 3451510316992d414ec76ba5b29681fe359b7428

Files: 3451510316992d414ec76ba5b29681fe359b7428 / lib / depject / contact / async.js

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

Built with git-ssb-web