Commit 680ea4ffaf54bf3796c8073ebfb67e931af69217
update plugins/friends and plugins/block
Dominic Tarr committed on 5/28/2017, 10:45:08 AMParent: 4250819350e538b6f5b1c63433e0b4b3f27ff6be
Files changed
plugins/block.js | changed |
plugins/friends.js | changed |
plugins/block.js | ||
---|---|---|
@@ -12,30 +12,21 @@ | ||
12 | 12 | //TODO: move other blocking code in here, |
13 | 13 | // i think we'll need a hook system for this. |
14 | 14 | |
15 | 15 | //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 | - ) | |
26 | 16 | |
17 | + var g = {} | |
18 | + | |
19 | + sbot.friends.post(function (_g) { | |
20 | + g = _g | |
21 | + }) | |
22 | + | |
27 | 23 | function isBlocked (_opts) { |
28 | 24 | var opts |
29 | - | |
25 | + if(!g) return //only possible briefly at startup | |
30 | 26 | 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 | |
38 | 29 | } |
39 | 30 | |
40 | 31 | sbot.createHistoryStream.hook(function (fn, args) { |
41 | 32 | var opts = args[0], id = this.id |
@@ -51,9 +42,9 @@ | ||
51 | 42 | if(!msg.content && msg.value.content) |
52 | 43 | msg = msg.value |
53 | 44 | if(msg.content.type !== 'contact') return true |
54 | 45 | return !( |
55 | - msg.content.flagged && | |
46 | + (msg.content.flagged || msg.content.blocking) && | |
56 | 47 | msg.content.contact === id |
57 | 48 | ) |
58 | 49 | }) |
59 | 50 | ) |
plugins/friends.js | ||
---|---|---|
@@ -7,8 +7,9 @@ | ||
7 | 7 | var mdm = require('mdmanifest') |
8 | 8 | var valid = require('../lib/validators') |
9 | 9 | var apidoc = require('../lib/apidocs').friends |
10 | 10 | var ref = require('ssb-ref') |
11 | +var Obv = require('obv') | |
11 | 12 | |
12 | 13 | var F = require('ssb-friends') |
13 | 14 | var block = require('ssb-friends/block') |
14 | 15 | |
@@ -32,10 +33,12 @@ | ||
32 | 33 | exports.version = '1.0.0' |
33 | 34 | exports.manifest = mdm.manifest(apidoc) |
34 | 35 | |
35 | 36 | 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 = {} | |
38 | 41 | G.addEdge(g, rel.from, rel.to, rel.value) |
39 | 42 | return g |
40 | 43 | }, function (data) { |
41 | 44 | if(data.value.content.type === 'contact' && ref.isFeed(data.value.content.contact)) { |
@@ -51,10 +54,17 @@ | ||
51 | 54 | } |
52 | 55 | } |
53 | 56 | })) |
54 | 57 | |
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 | + | |
55 | 65 | return { |
56 | - | |
66 | + post: post, | |
57 | 67 | get: function (opts, cb) { |
58 | 68 | index.get(opts, cb) |
59 | 69 | }, |
60 | 70 | |
@@ -73,9 +83,9 @@ | ||
73 | 83 | function push (to, hops) { |
74 | 84 | out.push(meta ? {id: to, hops: hops} : to) |
75 | 85 | } |
76 | 86 | |
77 | - var out = [] | |
87 | + var out = [], g = post.value | |
78 | 88 | |
79 | 89 | //the edge has already been added to g |
80 | 90 | if(!reachable) { |
81 | 91 | reachable = F.reachable(g, start, block) |
@@ -113,4 +123,7 @@ | ||
113 | 123 | } |
114 | 124 | } |
115 | 125 | |
116 | 126 | |
127 | + | |
128 | + | |
129 | + |
Built with git-ssb-web