git ssb

4+

Dominic / scuttlebot



Commit 680ea4ffaf54bf3796c8073ebfb67e931af69217

update plugins/friends and plugins/block

Dominic Tarr committed on 5/28/2017, 10:45:08 AM
Parent: 4250819350e538b6f5b1c63433e0b4b3f27ff6be

Files changed

plugins/block.jschanged
plugins/friends.jschanged
plugins/block.jsView
@@ -12,30 +12,21 @@
1212 //TODO: move other blocking code in here,
1313 // i think we'll need a hook system for this.
1414
1515 //if a currently connected peer is blocked, disconnect them immediately.
16- pull(
17- sbot.friends.createFriendStream({graph: 'flag', live: true}),
18- pull.drain(function (blocked) {
19- if(sbot.peers[blocked]) {
20- sbot.peers[blocked].forEach(function (b) {
21- b.close(true, function () {})
22- })
23- }
24- })
25- )
2616
17+ var g = {}
18+
19+ sbot.friends.post(function (_g) {
20+ g = _g
21+ })
22+
2723 function isBlocked (_opts) {
2824 var opts
29-
25+ if(!g) return //only possible briefly at startup
3026 if('string' === typeof _opts)
31- opts = {
32- source: sbot.id, dest: _opts, graph:'flag'
33- }
34- else opts = {
35- source: _opts.source, dest: _opts.dest, graph: 'flag'
36- }
37- return sbot.friends.get(opts)
27+ return g[sbot.id] ? g[sbot.id][_opts] === false : false
28+ return g[_opts.source] ? g[_opts.source][_opts.dest] === false : false
3829 }
3930
4031 sbot.createHistoryStream.hook(function (fn, args) {
4132 var opts = args[0], id = this.id
@@ -51,9 +42,9 @@
5142 if(!msg.content && msg.value.content)
5243 msg = msg.value
5344 if(msg.content.type !== 'contact') return true
5445 return !(
55- msg.content.flagged &&
46+ (msg.content.flagged || msg.content.blocking) &&
5647 msg.content.contact === id
5748 )
5849 })
5950 )
plugins/friends.jsView
@@ -7,8 +7,9 @@
77 var mdm = require('mdmanifest')
88 var valid = require('../lib/validators')
99 var apidoc = require('../lib/apidocs').friends
1010 var ref = require('ssb-ref')
11+var Obv = require('obv')
1112
1213 var F = require('ssb-friends')
1314 var block = require('ssb-friends/block')
1415
@@ -32,10 +33,12 @@
3233 exports.version = '1.0.0'
3334 exports.manifest = mdm.manifest(apidoc)
3435
3536 exports.init = function (sbot, config) {
36- var g = {}
37- var index = sbot._flumeUse('friends', Reduce(2, function (_, rel) {
37+ var post = Obv()
38+ post.set({})
39+ var index = sbot._flumeUse('friends', Reduce(2, function (g, rel) {
40+ if(!g) g = {}
3841 G.addEdge(g, rel.from, rel.to, rel.value)
3942 return g
4043 }, function (data) {
4144 if(data.value.content.type === 'contact' && ref.isFeed(data.value.content.contact)) {
@@ -51,10 +54,17 @@
5154 }
5255 }
5356 }))
5457
58+ index.since(function () {
59+ //it looks async but this will always be sync after loading
60+ index.get(null, function (_, v) {
61+ post.set(v)
62+ })
63+ })
64+
5565 return {
56-
66+ post: post,
5767 get: function (opts, cb) {
5868 index.get(opts, cb)
5969 },
6070
@@ -73,9 +83,9 @@
7383 function push (to, hops) {
7484 out.push(meta ? {id: to, hops: hops} : to)
7585 }
7686
77- var out = []
87+ var out = [], g = post.value
7888
7989 //the edge has already been added to g
8090 if(!reachable) {
8191 reachable = F.reachable(g, start, block)
@@ -113,4 +123,7 @@
113123 }
114124 }
115125
116126
127+
128+
129+

Built with git-ssb-web