-
Notifications
You must be signed in to change notification settings - Fork 5
/
graph.js
executable file
·53 lines (46 loc) · 1.52 KB
/
graph.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/env node
var pull = require('pull-stream')
var multicb = require('multicb')
module.exports = function (graph, userId, sbot, screen) {
var graphs = {
'follows': filteredFeeds('follow', false, 'Follows'),
'followers': filteredFeeds('follow', true, 'Followers'),
'flags': filteredFeeds('flag', false, 'Flags'),
'flaggers': filteredFeeds('flag', true, 'Flaggers'),
}
function filteredFeeds (graph, inbound, label) {
// construct list to render
var included = {}
sbot.friends.all(graph, function (err, g) {
if (inbound) {
// collect feeds with an edge to `userId`
for (var id2 in g)
if (g[id2][userId])
included[id2] = true
} else {
// use the already-computed `userId` edges
included = g[userId] || {}
}
})
function filter (entry) {
return included[entry.id]
}
// return function that'll construct the right view when called
return function () {
var el = require('./feeds')(sbot, screen, filter)
el.setLabel(label+': '+userId)
return el
}
}
return graphs[graph]()
}
if (!module.parent) {
var argv = require('minimist')(process.argv.slice(2))
var graph = argv._[0]
var userId = argv._[1]
if (['follows', 'followers', 'flags', 'flaggers'].indexOf(graph) === -1 || !require('ssb-ref').isFeed(userId)) {
console.error('Usage: graph.js [follows|followers|flags|flaggers] {feedid}')
process.exit(1)
}
require('./lib/app')(module.exports.bind(null, graph, userId))
}