git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: d06c60e3b13b5795e7acad4aff8901f5039efb83

Files: d06c60e3b13b5795e7acad4aff8901f5039efb83 / contact / async.js

1077 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})
10
11exports.gives = nest({
12 'contact.async': ['follow', 'unfollow', 'followerOf']
13})
14
15exports.create = function (api) {
16 return nest({
17 'contact.async': {follow, unfollow, followerOf}
18 })
19
20 function followerOf (source, dest, cb) {
21 var following = api.contact.obs.following(source)
22 onceTrue(following.sync, () => {
23 var value = resolve(following)
24 cb(null, value && value.has(dest))
25 })
26 }
27
28 function follow (id, cb) {
29 if (!ref.isFeed(id)) throw new Error('a feed id must be specified')
30 api.sbot.async.publish({
31 type: 'contact',
32 contact: id,
33 following: true
34 }, cb)
35 }
36
37 function unfollow (id, cb) {
38 if (!ref.isFeed(id)) throw new Error('a feed id must be specified')
39 api.sbot.async.publish({
40 type: 'contact',
41 contact: id,
42 following: false
43 }, cb)
44 }
45}
46

Built with git-ssb-web