Files: 644b1ba03f8e4f6fd3bd1ae92d31b7eb55791fd3 / modules_basic / relationships.js
1019 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.follows = function (id, cb) { |
23 | return sbot_query({query: [ |
24 | makeQuery(id, {$prefix:"@"}), |
25 | {"$map": ['value', 'content', 'contact']} |
26 | ]}) |
27 | } |
28 | |
29 | exports.followers = function (id) { |
30 | return sbot_query({query: [ |
31 | makeQuery({$prefix:"@"}, id), |
32 | {"$map": ['value', 'author']} |
33 | ]}) |
34 | } |
35 | |
36 | exports.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