Commit 3874b7fbf1d24582021a15bf44be07ada911f403
Merge branch 'dont-show-post-of-blocked'
Matt McKegg committed on 10/14/2017, 2:18:04 AMParent: 40c2f3dae32d12b6a79216ecb01df3cf7c57ce4b
Parent: bcf23f7ed7e27cc8755003023c9fd57775f79ca9
Files changed
contact/obs.js | changed |
feed/obs/thread.js | changed |
feed/pull/channel.js | changed |
feed/pull/mentions.js | changed |
feed/pull/public.js | changed |
feed/pull/rollup.js | changed |
feed/pull/type.js | changed |
message/html/render/post.js | changed |
message/sync/is-blocked.js | added |
contact/obs.js | ||
---|---|---|
@@ -3,9 +3,9 @@ | ||
3 | 3 | var pull = require('pull-stream') |
4 | 4 | var ref = require('ssb-ref') |
5 | 5 | |
6 | 6 | exports.needs = nest({ |
7 | - 'sbot.pull.stream': 'first' | |
7 | + 'sbot.pull.stream': 'first', | |
8 | 8 | }) |
9 | 9 | |
10 | 10 | exports.gives = nest({ |
11 | 11 | 'contact.obs': ['following', 'followers', 'blocking', 'blockers'], |
feed/obs/thread.js | ||
---|---|---|
@@ -6,9 +6,10 @@ | ||
6 | 6 | exports.needs = nest({ |
7 | 7 | 'backlinks.obs.for': 'first', |
8 | 8 | 'sbot.async.get': 'first', |
9 | 9 | 'message.sync.unbox': 'first', |
10 | - 'message.sync.root': 'first' | |
10 | + 'message.sync.root': 'first', | |
11 | + 'message.sync.isBlocked': 'first' | |
11 | 12 | }) |
12 | 13 | |
13 | 14 | exports.gives = nest('feed.obs.thread') |
14 | 15 | |
@@ -17,26 +18,25 @@ | ||
17 | 18 | |
18 | 19 | function thread (rootId, { branch } = {}) { |
19 | 20 | if (!ref.isLink(rootId)) throw new Error('an id must be specified') |
20 | 21 | var sync = Value(false) |
22 | + var { isBlocked, root } = api.message.sync | |
21 | 23 | |
22 | 24 | var prepend = MutantArray() |
23 | 25 | api.sbot.async.get(rootId, (err, value) => { |
24 | 26 | sync.set(true) |
25 | 27 | if (!err) { |
26 | - prepend.push( | |
27 | - Value(unboxIfNeeded({key: rootId, value})) | |
28 | - ) | |
28 | + var msg = unboxIfNeeded({key: rootId, value}) | |
29 | + if (isBlocked(msg)) msg.isBlocked = true | |
30 | + prepend.push(Value(msg)) | |
29 | 31 | } |
30 | 32 | }) |
31 | 33 | |
32 | 34 | var backlinks = api.backlinks.obs.for(rootId) |
33 | 35 | var replies = map(computed(backlinks, (msgs) => { |
34 | 36 | return msgs.filter(msg => { |
35 | - return msg.value.content.type !== 'vote' && ( | |
36 | - api.message.sync.root(msg) === rootId || | |
37 | - matchAny(msg.value.content.branch, rootId) | |
38 | - ) | |
37 | + const { type, branch } = msg.value.content | |
38 | + return type !== 'vote' && !isBlocked(msg) && (root(msg) === rootId || matchAny(branch, rootId)) | |
39 | 39 | }) |
40 | 40 | }), x => Value(x), { |
41 | 41 | // avoid refresh of entire list when items added |
42 | 42 | comparer: (a, b) => a === b |
feed/pull/channel.js | ||
---|---|---|
@@ -1,10 +1,12 @@ | ||
1 | 1 | const nest = require('depnest') |
2 | 2 | const extend = require('xtend') |
3 | +var pull = require('pull-stream') | |
3 | 4 | |
4 | 5 | exports.gives = nest('feed.pull.channel') |
5 | 6 | exports.needs = nest({ |
6 | - 'sbot.pull.backlinks': 'first' | |
7 | + 'sbot.pull.backlinks': 'first', | |
8 | + 'message.sync.isBlocked': 'first', | |
7 | 9 | }) |
8 | 10 | |
9 | 11 | exports.create = function (api) { |
10 | 12 | return nest('feed.pull.channel', function (channel) { |
@@ -24,12 +26,15 @@ | ||
24 | 26 | timestamp: typeof lt === 'number' ? {$lt: lt, $gt: 0} : {$gt: 0} |
25 | 27 | } |
26 | 28 | } |
27 | 29 | |
28 | - return api.sbot.pull.backlinks(extend(opts, { | |
29 | - query: [ | |
30 | - {$filter: filter} | |
31 | - ] | |
32 | - })) | |
30 | + return pull( | |
31 | + api.sbot.pull.backlinks(extend(opts, { | |
32 | + query: [ | |
33 | + {$filter: filter} | |
34 | + ] | |
35 | + })), | |
36 | + pull.filter(msg => !api.message.sync.isBlocked(msg)) | |
37 | + ) | |
33 | 38 | } |
34 | 39 | }) |
35 | 40 | } |
feed/pull/mentions.js | ||
---|---|---|
@@ -3,9 +3,10 @@ | ||
3 | 3 | const pull = require('pull-stream') |
4 | 4 | const ref = require('ssb-ref') |
5 | 5 | |
6 | 6 | exports.needs = nest({ |
7 | - 'sbot.pull.backlinks': 'first' | |
7 | + 'sbot.pull.backlinks': 'first', | |
8 | + 'message.sync.isBlocked': 'first' | |
8 | 9 | }) |
9 | 10 | |
10 | 11 | exports.gives = nest('feed.pull.mentions') |
11 | 12 | |
@@ -28,8 +29,11 @@ | ||
28 | 29 | }} |
29 | 30 | ] |
30 | 31 | }) |
31 | 32 | |
32 | - return api.sbot.pull.backlinks(opts) | |
33 | + return pull( | |
34 | + api.sbot.pull.backlinks(opts), | |
35 | + pull.filter(msg => !api.message.sync.isBlocked(msg)) | |
36 | + ) | |
33 | 37 | } |
34 | 38 | }) |
35 | 39 | } |
feed/pull/public.js | ||
---|---|---|
@@ -1,13 +1,22 @@ | ||
1 | 1 | const nest = require('depnest') |
2 | +var pull = require('pull-stream') | |
2 | 3 | |
3 | 4 | exports.gives = nest('feed.pull.public') |
4 | -exports.needs = nest('sbot.pull.feed', 'first') | |
5 | +exports.needs = nest({ | |
6 | + 'sbot.pull.feed': 'first', | |
7 | + 'message.sync.isBlocked': 'first', | |
8 | +}) | |
9 | + | |
5 | 10 | exports.create = function (api) { |
6 | 11 | return nest('feed.pull.public', (opts) => { |
7 | 12 | // handle last item passed in as lt |
8 | 13 | opts.lt = (opts.lt && opts.lt.value) |
9 | 14 | ? opts.lt.value.timestamp |
10 | 15 | : opts.lt |
11 | - return api.sbot.pull.feed(opts) | |
16 | + | |
17 | + return pull( | |
18 | + api.sbot.pull.feed(opts), | |
19 | + pull.filter(msg => !api.message.sync.isBlocked(msg)) | |
20 | + ) | |
12 | 21 | }) |
13 | 22 | } |
feed/pull/rollup.js | ||
---|---|---|
@@ -11,10 +11,11 @@ | ||
11 | 11 | |
12 | 12 | exports.needs = nest({ |
13 | 13 | 'backlinks.obs.for': 'first', |
14 | 14 | 'sbot.async.get': 'first', |
15 | + 'message.sync.isBlocked': 'first', | |
15 | 16 | 'message.sync.root': 'first', |
16 | - 'message.sync.unbox': 'first' | |
17 | + 'message.sync.unbox': 'first', | |
17 | 18 | }) |
18 | 19 | |
19 | 20 | exports.gives = nest('feed.pull.rollup', true) |
20 | 21 | |
@@ -83,16 +84,17 @@ | ||
83 | 84 | |
84 | 85 | // FILTER |
85 | 86 | pull.filter(msg => msg && msg.value && !api.message.sync.root(msg)), |
86 | 87 | pull.filter(rootFilter || (() => true)), |
88 | + pull.filter(msg => !api.message.sync.isBlocked(msg)), | |
87 | 89 | |
88 | 90 | // ADD REPLIES |
89 | 91 | pull.asyncMap((rootMessage, cb) => { |
90 | 92 | // use global backlinks cache |
91 | 93 | var backlinks = api.backlinks.obs.for(rootMessage.key) |
92 | 94 | onceTrue(backlinks.sync, () => { |
93 | - var replies = resolve(backlinks).filter((msg) => { | |
94 | - return api.message.sync.root(msg) === rootMessage.key | |
95 | + var replies = resolve(backlinks).filter(msg => { | |
96 | + return api.message.sync.root(msg) === rootMessage.key && !api.message.sync.isBlocked(msg) | |
95 | 97 | }) |
96 | 98 | cb(null, extend(rootMessage, { replies })) |
97 | 99 | }) |
98 | 100 | }) |
feed/pull/type.js | ||
---|---|---|
@@ -1,9 +1,14 @@ | ||
1 | 1 | const nest = require('depnest') |
2 | 2 | const extend = require('xtend') |
3 | +const pull = require('pull-stream') | |
3 | 4 | |
4 | 5 | exports.gives = nest('feed.pull.type') |
5 | -exports.needs = nest('sbot.pull.messagesByType', 'first') | |
6 | +exports.needs = nest({ | |
7 | + 'sbot.pull.messagesByType': 'first', | |
8 | + 'message.sync.isBlocked': 'first', | |
9 | +}) | |
10 | + | |
6 | 11 | exports.create = function (api) { |
7 | 12 | return nest('feed.pull.type', (type) => { |
8 | 13 | if (typeof type !== 'string') throw new Error('a type must be specified') |
9 | 14 | |
@@ -13,8 +18,11 @@ | ||
13 | 18 | // handle last item passed in as lt |
14 | 19 | lt: opts.lt && typeof opts.lt === 'object' ? opts.lt.timestamp : opts.lt |
15 | 20 | }) |
16 | 21 | |
17 | - return api.sbot.pull.messagesByType(opts) | |
22 | + return pull( | |
23 | + api.sbot.pull.messagesByType(opts), | |
24 | + pull.filter(msg => !api.message.sync.isBlocked(msg)) | |
25 | + ) | |
18 | 26 | } |
19 | 27 | }) |
20 | 28 | } |
message/html/render/post.js | ||
---|---|---|
@@ -17,9 +17,9 @@ | ||
17 | 17 | return nest('message.html.render', function renderMessage (msg, opts) { |
18 | 18 | if (msg.value.content.type !== 'post') return |
19 | 19 | var element = api.message.html.layout(msg, extend({ |
20 | 20 | title: messageTitle(msg), |
21 | - content: messageContent(msg), | |
21 | + content: msg.isBlocked ? 'Content of a blocked user' : messageContent(msg), | |
22 | 22 | layout: 'default' |
23 | 23 | }, opts)) |
24 | 24 | |
25 | 25 | return api.message.html.decorate(element, { msg }) |
message/sync/is-blocked.js | ||
---|---|---|
@@ -1,0 +1,20 @@ | ||
1 | +const nest = require('depnest') | |
2 | + | |
3 | +exports.gives = nest('message.sync.isBlocked') | |
4 | + | |
5 | +exports.needs = nest({ | |
6 | + 'contact.obs.blocking': 'first', | |
7 | + 'keys.sync.id': 'first' | |
8 | +}) | |
9 | + | |
10 | +exports.create = function (api) { | |
11 | + var cache = null | |
12 | + | |
13 | + return nest('message.sync.isBlocked', function isBlockedMessage (msg) { | |
14 | + if (!cache) { | |
15 | + cache = api.contact.obs.blocking(api.keys.sync.id()) | |
16 | + } | |
17 | + | |
18 | + return cache().includes(msg.value.author) | |
19 | + }) | |
20 | +} |
Built with git-ssb-web