git ssb

7+

dinoworm ๐Ÿ› / patchcore



Commit 7bd9775b75c52ca02f3e47ccb20e59533accb156

add blocking calls and observeables

mix irving committed on 9/14/2017, 12:33:20 AM
Parent: 50ccb6d724fb7b397e2736bf5f6642d920709c7a

Files changed

contact/async.jschanged
contact/obs.jschanged
package-lock.jsonchanged
contact/async.jsView
@@ -9,14 +9,14 @@
99 'sbot.async.friendsGet': 'first'
1010 })
1111
1212 exports.gives = nest({
13- 'contact.async': ['follow', 'unfollow', 'followerOf']
13+ 'contact.async': ['follow', 'unfollow', 'followerOf', 'block', 'unblock']
1414 })
1515
1616 exports.create = function (api) {
1717 return nest({
18- 'contact.async': {follow, unfollow, followerOf}
18+ 'contact.async': {follow, unfollow, followerOf, block, unblock}
1919 })
2020
2121 function followerOf (source, dest, cb) {
2222 api.sbot.async.friendsGet({source: source, dest: dest}, cb)
@@ -38,9 +38,25 @@
3838 contact: id,
3939 following: false
4040 }, cb)
4141 }
42-}
4342
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+ }
4451
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+ }
4560
61+}
4662
contact/obs.jsView
@@ -7,9 +7,9 @@
77 'sbot.pull.stream': 'first'
88 })
99
1010 exports.gives = nest({
11- 'contact.obs': ['following', 'followers'],
11+ 'contact.obs': ['following', 'followers', 'blocking', 'blockers'],
1212 'sbot.hook.publish': true
1313 })
1414
1515 exports.create = function (api) {
@@ -19,9 +19,11 @@
1919
2020 return nest({
2121 'contact.obs': {
2222 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),
2426 },
2527 'sbot.hook.publish': function (msg) {
2628 if (isContact(msg)) {
2729 // HACK: make interface more responsive when sbot is busy
@@ -38,8 +40,20 @@
3840 [source]: [msg.value.content]
3941 }
4042 })
4143 }
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+ }
4256 }
4357 }
4458 })
4559
@@ -64,8 +78,9 @@
6478 )
6579 }
6680
6781 function update (id, values) {
82+ // values = { following, followers, blocking, blockedBy, ... }
6883 var state = get(id)
6984 var lastState = state()
7085 var changed = false
7186 for (var key in values) {
package-lock.jsonView
@@ -2560,16 +2560,8 @@
25602560 "looper": "3.0.0",
25612561 "pull-stream": "3.6.0"
25622562 }
25632563 },
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- },
25722564 "string-width": {
25732565 "version": "1.0.2",
25742566 "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
25752567 "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
@@ -2579,8 +2571,16 @@
25792571 "is-fullwidth-code-point": "1.0.0",
25802572 "strip-ansi": "3.0.1"
25812573 }
25822574 },
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+ },
25832583 "strip-ansi": {
25842584 "version": "3.0.1",
25852585 "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
25862586 "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",

Built with git-ssb-web