git ssb

4+

Dominic / scuttlebot



Commit e56dd0fc65220e4f40d8a41f95306b8d8bb09369

comments for createFriendStream code...

Dominic Tarr committed on 5/21/2017, 9:51:07 PM
Parent: b3923852a5471785a61c33094414b62fa845b7b5

Files changed

plugins/friends.jschanged
plugins/friends.jsView
@@ -33,18 +33,23 @@
3333 var g = null
3434
3535 var index = sbot._flumeUse('friends', Reduce(1, function (g, rel) {
3636 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+ }
3842 G.addEdge(g, rel.from, rel.to, rel.value)
3943 return g
4044 }, 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)) {
4246 return {
4347 from: data.value.author,
4448 to: data.value.content.contact,
4549 value: data.value.content.following
4650 }
51+ }
4752 }))
4853
4954 return {
5055
@@ -62,19 +67,26 @@
6267 g = g || {}
6368 return pull(
6469 index.stream(opts),
6570 FlatMap(function (v) {
71+ //this code handles real time streaming of the hops map.
6672 function push (to, hops) {
6773 out.push(meta ? {id: to, hops: hops} : to)
6874 }
6975 var out = []
7076 if(!v) return []
7177 if(v.from && v.to) {
78+ //add edge from->to (value)
7279 G.addEdge(g, v.from, v.to, v.value)
80+ //recalculate the portion of the graph, reachable in opts.hops
7381 var _reachable = G.hops(g, start, 0, opts.hops || 3, reachable)
82+ //for each node currently reachable
7483 for(var k in _reachable) {
84+ //check if it has _become_ reachable just now.
85+ //if so add to the set
7586 if(reachable[k] == null)
7687 push(k, reachable[k] = _reachable[k])
88+ //if this has shortened the path, then update.
7789 else if(reachable[k] > _reachable[k])
7890 reachable[k] = _reachable[k]
7991 //else, we where already able to reach this node.
8092 }
@@ -109,4 +121,5 @@
109121 }
110122 }
111123
112124
125+

Built with git-ssb-web