Files: 1462eddad93e346c412fe00dd5fb4468adf1ee04 / modules_basic / relationships.js
1275 bytesRaw
1 | var pull = require('pull-stream') |
2 | //var plugs = require('../plugs') |
3 | |
4 | //var sbot_query = plugs.first(exports.sbot_query = []) |
5 | |
6 | //this is a bit crude, and doesn't actually show unfollows yet. |
7 | |
8 | function 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 | |
22 | exports.needs = { sbot_query: 'first' } |
23 | |
24 | exports.gives = { |
25 | follows: true, |
26 | followers: true, |
27 | follower_of: true |
28 | } |
29 | |
30 | exports.create = function (api) { |
31 | |
32 | return { |
33 | follows: function (id, cb) { |
34 | return api.sbot_query({query: [ |
35 | makeQuery(id, {$prefix:"@"}), |
36 | {"$map": ['value', 'content', 'contact']} |
37 | ]}) |
38 | }, |
39 | |
40 | followers: function (id) { |
41 | return api.sbot_query({query: [ |
42 | makeQuery({$prefix:"@"}, id), |
43 | {"$map": ['value', 'author']} |
44 | ]}) |
45 | }, |
46 | |
47 | follower_of: function (source, dest, cb) { |
48 | pull( |
49 | api.sbot_query({query: [ |
50 | makeQuery(source, dest), |
51 | {$map: ['value', 'content', 'following']} |
52 | ]}), |
53 | pull.collect(function (err, ary) { |
54 | if(err) return cb(err) |
55 | else cb(null, ary.pop()) //will be true, or undefined/false |
56 | }) |
57 | ) |
58 | } |
59 | } |
60 | |
61 | } |
62 | |
63 |
Built with git-ssb-web