git ssb

7+

dinoworm ๐Ÿ› / patchcore



Tree: 80ba6fee5d82b4a5f3ffa668f3115933558ebc92

Files: 80ba6fee5d82b4a5f3ffa668f3115933558ebc92 / contact / async.js

1002 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

Built with git-ssb-web