git ssb

7+

dinoworm ๐Ÿ› / patchcore



Commit bcf23f7ed7e27cc8755003023c9fd57775f79ca9

tidy, fix some bugs in blocking display

Matt McKegg committed on 10/14/2017, 2:17:36 AM
Parent: 69ad8a490ee9bf4c8a9f0ebe199cbaf19d7ab938

Files changed

feed/obs/thread.jschanged
feed/pull/rollup.jschanged
message/sync/isBlocked.jsdeleted
message/sync/is-blocked.jsadded
feed/obs/thread.jsView
@@ -7,9 +7,9 @@
77 'backlinks.obs.for': 'first',
88 'sbot.async.get': 'first',
99 'message.sync.unbox': 'first',
1010 'message.sync.root': 'first',
11- 'message.sync.isBlocked': 'first',
11+ 'message.sync.isBlocked': 'first'
1212 })
1313
1414 exports.gives = nest('feed.obs.thread')
1515
@@ -18,9 +18,9 @@
1818
1919 function thread (rootId, { branch } = {}) {
2020 if (!ref.isLink(rootId)) throw new Error('an id must be specified')
2121 var sync = Value(false)
22- const { isBlocked, unbox, root } = message.sync
22+ var { isBlocked, root } = api.message.sync
2323
2424 var prepend = MutantArray()
2525 api.sbot.async.get(rootId, (err, value) => {
2626 sync.set(true)
@@ -34,11 +34,9 @@
3434 var backlinks = api.backlinks.obs.for(rootId)
3535 var replies = map(computed(backlinks, (msgs) => {
3636 return msgs.filter(msg => {
3737 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))
4139 })
4240 }), x => Value(x), {
4341 // avoid refresh of entire list when items added
4442 comparer: (a, b) => a === b
@@ -90,9 +88,9 @@
9088 }
9189
9290 function unboxIfNeeded (msg) {
9391 if (msg.value && typeof msg.value.content === 'string') {
94- return unbox(msg) || msg
92+ return api.message.sync.unbox(msg) || msg
9593 } else {
9694 return msg
9795 }
9896 }
feed/pull/rollup.jsView
@@ -84,18 +84,17 @@
8484
8585 // FILTER
8686 pull.filter(msg => msg && msg.value && !api.message.sync.root(msg)),
8787 pull.filter(rootFilter || (() => true)),
88- pull.filter(msg => !api.message.sync.isBlocked(msg))
88+ pull.filter(msg => !api.message.sync.isBlocked(msg)),
8989
9090 // ADD REPLIES
9191 pull.asyncMap((rootMessage, cb) => {
9292 // use global backlinks cache
9393 var backlinks = api.backlinks.obs.for(rootMessage.key)
9494 onceTrue(backlinks.sync, () => {
9595 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)
9897 })
9998 cb(null, extend(rootMessage, { replies }))
10099 })
101100 })
message/sync/isBlocked.jsView
@@ -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.jsView
@@ -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