Files: d9ba09fe7118718dfeddc73ddab338839d9e78c7 / modules_basic / relationships.js
1119 bytesRaw
1 | var pull = require('pull-stream') |
2 | |
3 | function makeQuery (a, b) { |
4 | return {"$filter": { |
5 | value: { |
6 | author: a, |
7 | content: { |
8 | type: 'contact', |
9 | contact: b, |
10 | following: true |
11 | } |
12 | }, |
13 | }} |
14 | } |
15 | |
16 | |
17 | exports.needs = { sbot_query: 'first' } |
18 | |
19 | exports.gives = { |
20 | follows: true, |
21 | followers: true, |
22 | follower_of: true |
23 | } |
24 | |
25 | exports.create = function (api) { |
26 | |
27 | return { |
28 | follows: function (id, cb) { |
29 | return api.sbot_query({query: [ |
30 | makeQuery(id, {$prefix:"@"}), |
31 | {"$map": ['value', 'content', 'contact']} |
32 | ]}) |
33 | }, |
34 | |
35 | followers: function (id) { |
36 | return api.sbot_query({query: [ |
37 | makeQuery({$prefix:"@"}, id), |
38 | {"$map": ['value', 'author']} |
39 | ]}) |
40 | }, |
41 | |
42 | follower_of: function (source, dest, cb) { |
43 | pull( |
44 | api.sbot_query({query: [ |
45 | makeQuery(source, dest), |
46 | {$map: ['value', 'content', 'following']} |
47 | ]}), |
48 | pull.collect(function (err, ary) { |
49 | if(err) return cb(err) |
50 | else cb(null, ary.pop()) //will be true, or undefined/false |
51 | }) |
52 | ) |
53 | } |
54 | } |
55 | |
56 | } |
57 | |
58 |
Built with git-ssb-web