Commit bcf23f7ed7e27cc8755003023c9fd57775f79ca9
tidy, fix some bugs in blocking display
Matt McKegg committed on 10/14/2017, 2:17:36 AMParent: 69ad8a490ee9bf4c8a9f0ebe199cbaf19d7ab938
Files changed
feed/obs/thread.js | changed |
feed/pull/rollup.js | changed |
message/sync/isBlocked.js | deleted |
message/sync/is-blocked.js | added |
feed/obs/thread.js | ||
---|---|---|
@@ -7,9 +7,9 @@ | ||
7 | 7 | 'backlinks.obs.for': 'first', |
8 | 8 | 'sbot.async.get': 'first', |
9 | 9 | 'message.sync.unbox': 'first', |
10 | 10 | 'message.sync.root': 'first', |
11 | - 'message.sync.isBlocked': 'first', | |
11 | + 'message.sync.isBlocked': 'first' | |
12 | 12 | }) |
13 | 13 | |
14 | 14 | exports.gives = nest('feed.obs.thread') |
15 | 15 | |
@@ -18,9 +18,9 @@ | ||
18 | 18 | |
19 | 19 | function thread (rootId, { branch } = {}) { |
20 | 20 | if (!ref.isLink(rootId)) throw new Error('an id must be specified') |
21 | 21 | var sync = Value(false) |
22 | - const { isBlocked, unbox, root } = message.sync | |
22 | + var { isBlocked, root } = api.message.sync | |
23 | 23 | |
24 | 24 | var prepend = MutantArray() |
25 | 25 | api.sbot.async.get(rootId, (err, value) => { |
26 | 26 | sync.set(true) |
@@ -34,11 +34,9 @@ | ||
34 | 34 | var backlinks = api.backlinks.obs.for(rootId) |
35 | 35 | var replies = map(computed(backlinks, (msgs) => { |
36 | 36 | return msgs.filter(msg => { |
37 | 37 | const { type, branch } = msg.value.content |
38 | - return type !== 'vote' | |
39 | - && !isBlocked(msg) | |
40 | - && (root(msg) === rootId || matchAny(branch, rootId)) | |
38 | + return type !== 'vote' && !isBlocked(msg) && (root(msg) === rootId || matchAny(branch, rootId)) | |
41 | 39 | }) |
42 | 40 | }), x => Value(x), { |
43 | 41 | // avoid refresh of entire list when items added |
44 | 42 | comparer: (a, b) => a === b |
@@ -90,9 +88,9 @@ | ||
90 | 88 | } |
91 | 89 | |
92 | 90 | function unboxIfNeeded (msg) { |
93 | 91 | if (msg.value && typeof msg.value.content === 'string') { |
94 | - return unbox(msg) || msg | |
92 | + return api.message.sync.unbox(msg) || msg | |
95 | 93 | } else { |
96 | 94 | return msg |
97 | 95 | } |
98 | 96 | } |
feed/pull/rollup.js | ||
---|---|---|
@@ -84,18 +84,17 @@ | ||
84 | 84 | |
85 | 85 | // FILTER |
86 | 86 | pull.filter(msg => msg && msg.value && !api.message.sync.root(msg)), |
87 | 87 | pull.filter(rootFilter || (() => true)), |
88 | - pull.filter(msg => !api.message.sync.isBlocked(msg)) | |
88 | + pull.filter(msg => !api.message.sync.isBlocked(msg)), | |
89 | 89 | |
90 | 90 | // ADD REPLIES |
91 | 91 | pull.asyncMap((rootMessage, cb) => { |
92 | 92 | // use global backlinks cache |
93 | 93 | var backlinks = api.backlinks.obs.for(rootMessage.key) |
94 | 94 | onceTrue(backlinks.sync, () => { |
95 | 95 | var replies = resolve(backlinks).filter(msg => { |
96 | - return api.message.sync.root(msg) === rootMessage.key | |
97 | - && !api.message.sync.isBlocked(msg) | |
96 | + return api.message.sync.root(msg) === rootMessage.key && !api.message.sync.isBlocked(msg) | |
98 | 97 | }) |
99 | 98 | cb(null, extend(rootMessage, { replies })) |
100 | 99 | }) |
101 | 100 | }) |
message/sync/isBlocked.js | ||
---|---|---|
@@ -1,22 +1,0 @@ | ||
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 _myBlocking | |
12 | - | |
13 | - return nest('message.sync.isBlocked', function isBlockedMessage (msg) { | |
14 | - if (!_myBlocking) { | |
15 | - const myKey = api.keys.sync.id() | |
16 | - _myBlocking = api.contact.obs.blocking(myKey) | |
17 | - } | |
18 | - | |
19 | - return _myBlocking.includes(msg.value.author) | |
20 | - }) | |
21 | -} | |
22 | - |
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