Commit e56dd0fc65220e4f40d8a41f95306b8d8bb09369
comments for createFriendStream code...
Dominic Tarr committed on 5/21/2017, 9:51:07 PMParent: b3923852a5471785a61c33094414b62fa845b7b5
Files changed
plugins/friends.js | changed |
plugins/friends.js | ||
---|---|---|
@@ -33,18 +33,23 @@ | ||
33 | 33 | var g = null |
34 | 34 | |
35 | 35 | var index = sbot._flumeUse('friends', Reduce(1, function (g, rel) { |
36 | 36 | if(!g) g = {} |
37 | - | |
37 | + if(!ref.isFeed(rel.from)) throw new Error('FROM is not id') | |
38 | + if(!ref.isFeed(rel.to)) { | |
39 | + console.log('???', rel) | |
40 | + throw new Error('TO is not id') | |
41 | + } | |
38 | 42 | G.addEdge(g, rel.from, rel.to, rel.value) |
39 | 43 | return g |
40 | 44 | }, function (data) { |
41 | - if(data.value.content.type === 'contact' && ref.isFeed(data.value.content.contact)) | |
45 | + if(data.value.content.type === 'contact' && ref.isFeed(data.value.content.contact)) { | |
42 | 46 | return { |
43 | 47 | from: data.value.author, |
44 | 48 | to: data.value.content.contact, |
45 | 49 | value: data.value.content.following |
46 | 50 | } |
51 | + } | |
47 | 52 | })) |
48 | 53 | |
49 | 54 | return { |
50 | 55 | |
@@ -62,19 +67,26 @@ | ||
62 | 67 | g = g || {} |
63 | 68 | return pull( |
64 | 69 | index.stream(opts), |
65 | 70 | FlatMap(function (v) { |
71 | + //this code handles real time streaming of the hops map. | |
66 | 72 | function push (to, hops) { |
67 | 73 | out.push(meta ? {id: to, hops: hops} : to) |
68 | 74 | } |
69 | 75 | var out = [] |
70 | 76 | if(!v) return [] |
71 | 77 | if(v.from && v.to) { |
78 | + //add edge from->to (value) | |
72 | 79 | G.addEdge(g, v.from, v.to, v.value) |
80 | + //recalculate the portion of the graph, reachable in opts.hops | |
73 | 81 | var _reachable = G.hops(g, start, 0, opts.hops || 3, reachable) |
82 | + //for each node currently reachable | |
74 | 83 | for(var k in _reachable) { |
84 | + //check if it has _become_ reachable just now. | |
85 | + //if so add to the set | |
75 | 86 | if(reachable[k] == null) |
76 | 87 | push(k, reachable[k] = _reachable[k]) |
88 | + //if this has shortened the path, then update. | |
77 | 89 | else if(reachable[k] > _reachable[k]) |
78 | 90 | reachable[k] = _reachable[k] |
79 | 91 | //else, we where already able to reach this node. |
80 | 92 | } |
@@ -109,4 +121,5 @@ | ||
109 | 121 | } |
110 | 122 | } |
111 | 123 | |
112 | 124 | |
125 | + |
Built with git-ssb-web