git ssb

16+

Dominic / patchbay



Tree: 539c2721f7440d5a437ac3dc66c7d64f7876505e

Files: 539c2721f7440d5a437ac3dc66c7d64f7876505e / modules_basic / relationships.js

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