git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: 3a6b42e980da99c6778fd2db5f693fa7d89d7207

Files: 3a6b42e980da99c6778fd2db5f693fa7d89d7207 / contact / async.js

1005 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']
14})
15
16exports.create = function (api) {
17 return nest({
18 'contact.async': {follow, unfollow, followerOf}
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
44
45
46
47

Built with git-ssb-web