Commit 7bd9775b75c52ca02f3e47ccb20e59533accb156
add blocking calls and observeables
mix irving committed on 9/14/2017, 12:33:20 AMParent: 50ccb6d724fb7b397e2736bf5f6642d920709c7a
Files changed
contact/async.js | changed |
contact/obs.js | changed |
package-lock.json | changed |
contact/async.js | ||
---|---|---|
@@ -9,14 +9,14 @@ | ||
9 | 9 | 'sbot.async.friendsGet': 'first' |
10 | 10 | }) |
11 | 11 | |
12 | 12 | exports.gives = nest({ |
13 | - 'contact.async': ['follow', 'unfollow', 'followerOf'] | |
13 | + 'contact.async': ['follow', 'unfollow', 'followerOf', 'block', 'unblock'] | |
14 | 14 | }) |
15 | 15 | |
16 | 16 | exports.create = function (api) { |
17 | 17 | return nest({ |
18 | - 'contact.async': {follow, unfollow, followerOf} | |
18 | + 'contact.async': {follow, unfollow, followerOf, block, unblock} | |
19 | 19 | }) |
20 | 20 | |
21 | 21 | function followerOf (source, dest, cb) { |
22 | 22 | api.sbot.async.friendsGet({source: source, dest: dest}, cb) |
@@ -38,9 +38,25 @@ | ||
38 | 38 | contact: id, |
39 | 39 | following: false |
40 | 40 | }, cb) |
41 | 41 | } |
42 | -} | |
43 | 42 | |
43 | + function block (id, cb) { | |
44 | + if (!ref.isFeed(id)) throw new Error('a feed id must be specified') | |
45 | + api.sbot.async.publish({ | |
46 | + type: 'contact', | |
47 | + contact: id, | |
48 | + blocking: true | |
49 | + }, cb) | |
50 | + } | |
44 | 51 | |
52 | + function unblock (id, cb) { | |
53 | + if (!ref.isFeed(id)) throw new Error('a feed id must be specified') | |
54 | + api.sbot.async.publish({ | |
55 | + type: 'contact', | |
56 | + contact: id, | |
57 | + blocking: false | |
58 | + }, cb) | |
59 | + } | |
45 | 60 | |
61 | +} | |
46 | 62 |
contact/obs.js | ||
---|---|---|
@@ -7,9 +7,9 @@ | ||
7 | 7 | 'sbot.pull.stream': 'first' |
8 | 8 | }) |
9 | 9 | |
10 | 10 | exports.gives = nest({ |
11 | - 'contact.obs': ['following', 'followers'], | |
11 | + 'contact.obs': ['following', 'followers', 'blocking', 'blockers'], | |
12 | 12 | 'sbot.hook.publish': true |
13 | 13 | }) |
14 | 14 | |
15 | 15 | exports.create = function (api) { |
@@ -19,9 +19,11 @@ | ||
19 | 19 | |
20 | 20 | return nest({ |
21 | 21 | 'contact.obs': { |
22 | 22 | following: (id) => values(get(id), 'following', true), |
23 | - followers: (id) => values(get(id), 'followers', true) | |
23 | + followers: (id) => values(get(id), 'followers', true), | |
24 | + blocking: (id) => values(get(id), 'blocking', true), | |
25 | + blockers: (id) => values(get(id), 'blockers', true), | |
24 | 26 | }, |
25 | 27 | 'sbot.hook.publish': function (msg) { |
26 | 28 | if (isContact(msg)) { |
27 | 29 | // HACK: make interface more responsive when sbot is busy |
@@ -38,8 +40,20 @@ | ||
38 | 40 | [source]: [msg.value.content] |
39 | 41 | } |
40 | 42 | }) |
41 | 43 | } |
44 | + if (typeof msg.value.content.blocking === 'boolean') { | |
45 | + update(source, { | |
46 | + blocking: { | |
47 | + [dest]: [msg.value.content] | |
48 | + } | |
49 | + }) | |
50 | + update(dest, { | |
51 | + blockers: { | |
52 | + [source]: [msg.value.content] | |
53 | + } | |
54 | + }) | |
55 | + } | |
42 | 56 | } |
43 | 57 | } |
44 | 58 | }) |
45 | 59 | |
@@ -64,8 +78,9 @@ | ||
64 | 78 | ) |
65 | 79 | } |
66 | 80 | |
67 | 81 | function update (id, values) { |
82 | + // values = { following, followers, blocking, blockedBy, ... } | |
68 | 83 | var state = get(id) |
69 | 84 | var lastState = state() |
70 | 85 | var changed = false |
71 | 86 | for (var key in values) { |
package-lock.json | ||
---|---|---|
@@ -2560,16 +2560,8 @@ | ||
2560 | 2560 | "looper": "3.0.0", |
2561 | 2561 | "pull-stream": "3.6.0" |
2562 | 2562 | } |
2563 | 2563 | }, |
2564 | - "string_decoder": { | |
2565 | - "version": "1.0.2", | |
2566 | - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.2.tgz", | |
2567 | - "integrity": "sha1-sp4fThEl+pehA4K4pTNze3SR4Xk=", | |
2568 | - "requires": { | |
2569 | - "safe-buffer": "5.0.1" | |
2570 | - } | |
2571 | - }, | |
2572 | 2564 | "string-width": { |
2573 | 2565 | "version": "1.0.2", |
2574 | 2566 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", |
2575 | 2567 | "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", |
@@ -2579,8 +2571,16 @@ | ||
2579 | 2571 | "is-fullwidth-code-point": "1.0.0", |
2580 | 2572 | "strip-ansi": "3.0.1" |
2581 | 2573 | } |
2582 | 2574 | }, |
2575 | + "string_decoder": { | |
2576 | + "version": "1.0.2", | |
2577 | + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.2.tgz", | |
2578 | + "integrity": "sha1-sp4fThEl+pehA4K4pTNze3SR4Xk=", | |
2579 | + "requires": { | |
2580 | + "safe-buffer": "5.0.1" | |
2581 | + } | |
2582 | + }, | |
2583 | 2583 | "strip-ansi": { |
2584 | 2584 | "version": "3.0.1", |
2585 | 2585 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", |
2586 | 2586 | "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", |
Built with git-ssb-web