git ssb

16+

Dominic / patchbay



Tree: 33d49d724c13b515841075e0ae6d096034c78275

Files: 33d49d724c13b515841075e0ae6d096034c78275 / 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