git ssb

16+

Dominic / patchbay



Tree: da116a36a6e34b4499633c0a896b9bf32d263383

Files: da116a36a6e34b4499633c0a896b9bf32d263383 / modules_basic / relationships.js

1019 bytesRaw
1var pull = require('pull-stream')
2var plugs = require('../plugs')
3
4var sbot_query = plugs.first(exports.sbot_query = [])
5
6//this is a bit crude, and doesn't actually show unfollows yet.
7
8function makeQuery (a, b) {
9 return {"$filter": {
10 value: {
11 author: a,
12 content: {
13 type: 'contact',
14 contact: b,
15 following: true
16 }
17 },
18 }}
19}
20
21
22exports.follows = function (id, cb) {
23 return sbot_query({query: [
24 makeQuery(id, {$prefix:"@"}),
25 {"$map": ['value', 'content', 'contact']}
26 ]})
27}
28
29exports.followers = function (id) {
30 return sbot_query({query: [
31 makeQuery({$prefix:"@"}, id),
32 {"$map": ['value', 'author']}
33 ]})
34}
35
36exports.follower_of = function (source, dest, cb) {
37 pull(
38 sbot_query({query: [
39 makeQuery(source, dest),
40 {$map: ['value', 'content', 'following']}
41 ]}),
42 pull.collect(function (err, ary) {
43 if(err) return cb(err)
44 else cb(null, ary.pop()) //will be true, or undefined/false
45 })
46 )
47}
48
49
50
51

Built with git-ssb-web