git ssb

0+

ev / minbase



Tree: 3ee0398629a78832c2fbe78831ce756faeaeca74

Files: 3ee0398629a78832c2fbe78831ce756faeaeca74 / modules / relationships.js

1175 bytesRaw
1var pull = require('pull-stream')
2
3var sbotQuery = require('./scuttlebot').query
4
5//this is a bit crude, and doesn't actually show unfollows yet.
6
7function makeQuery (a, b) {
8 return {"$filter": {
9 value: {
10 author: a,
11 content: {
12 type: 'contact',
13 contact: b,
14 following: true
15 }
16 },
17 }}
18}
19
20
21exports.gives = {
22 follows: true,
23 followers: true,
24 follower_of: true
25}
26
27exports.create = function (api) {
28
29 return {
30 follows: function (id, cb) {
31 return sbotQuery({query: [
32 makeQuery(id, {$prefix:"@"}),
33 {"$map": ['value', 'content', 'contact']}
34 ]})
35 },
36
37 followers: function (id) {
38 return sbotQuery({query: [
39 makeQuery({$prefix:"@"}, id),
40 {"$map": ['value', 'author']}
41 ]})
42 },
43
44 follower_of: function (source, dest, cb) {
45 pull(
46 sbotQuery({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