git ssb

2+

dinoworm ๐Ÿ› / ssb-graphviz



Tree: 0882250828f8b296fbb0440e8f4e54238db0c88c

Files: 0882250828f8b296fbb0440e8f4e54238db0c88c / graph.js

787 bytesRaw
1const pull = require('pull-stream')
2const Sbot = require('ssb-client')
3const waterfall = require('run-waterfall')
4
5module.exports = Graph
6
7function 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