Files: 19df811a89f199ca6aa042c09ff9aeaa2e7ea1f8 / contact / async.js
1457 bytesRaw
1 | var nest = require('depnest') |
2 | var onceTrue = require('mutant/once-true') |
3 | var resolve = require('mutant/resolve') |
4 | var ref = require('ssb-ref') |
5 | |
6 | exports.needs = nest({ |
7 | 'contact.obs.following': 'first', |
8 | 'sbot.async.publish': 'first', |
9 | 'sbot.async.friendsGet': 'first' |
10 | }) |
11 | |
12 | exports.gives = nest({ |
13 | 'contact.async': ['follow', 'unfollow', 'followerOf', 'block', 'unblock'] |
14 | }) |
15 | |
16 | exports.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