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