git ssb

16+

Dominic / patchbay



Tree: 3c2247fb3d903ae61e79bc60acac7876c3370fa4

Files: 3c2247fb3d903ae61e79bc60acac7876c3370fa4 / modules_basic / relationships.js

1275 bytesRaw
1var 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
8function 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
22exports.needs = { sbot_query: 'first' }
23
24exports.gives = {
25 follows: true,
26 followers: true,
27 follower_of: true
28}
29
30exports.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