Files: a7018ed04f2f3649a770fa168f32d48b5ffdf057 / graph.js
787 bytesRaw
1 | const pull = require('pull-stream') |
2 | const Sbot = require('ssb-client') |
3 | const waterfall = require('run-waterfall') |
4 | |
5 | module.exports = Graph |
6 | |
7 | function Graph (sbot, cb) { |
8 | waterfall([ |
9 | (cb) => sbot.friends.all(cb), |
10 | (friends, cb) => { |
11 | cb(null, { |
12 | nodes: Object.keys(friends).map(id => ({ id })), |
13 | links: Object.keys(friends).reduce((sofar, friend) => { |
14 | const friendOfFriends = Object.keys(friends[friend]) |
15 | .filter(id => friends[friend][id] === true) |
16 | const edges = friendOfFriends.map(friendOfFriend => { |
17 | return { |
18 | fromId: friend, |
19 | toId: friendOfFriend |
20 | } |
21 | }) |
22 | return [ |
23 | ...sofar, |
24 | ...edges |
25 | ] |
26 | }, []) |
27 | }) |
28 | } |
29 | ], cb) |
30 | } |
31 |
Built with git-ssb-web