git ssb

7+

dinoworm ๐Ÿ› / patchcore



Commit d95ae6e1a02431fa8661487edc645af596a31fbe

add message.sync.isBlocked with persistent personal blocklist

mix irving committed on 10/1/2017, 5:37:15 AM
Parent: eea3b69d83cfcb21e841e49256b7d926d861ff9d

Files changed

contact/obs.jschanged
feed/obs/thread.jschanged
feed/pull/channel.jschanged
feed/pull/mentions.jschanged
feed/pull/public.jschanged
feed/pull/rollup.jschanged
feed/pull/type.jschanged
message/sync/isBlocked.jsadded
contact/obs.jsView
@@ -3,9 +3,9 @@
33 var pull = require('pull-stream')
44 var ref = require('ssb-ref')
55
66 exports.needs = nest({
7- 'sbot.pull.stream': 'first'
7+ 'sbot.pull.stream': 'first',
88 })
99
1010 exports.gives = nest({
1111 'contact.obs': ['following', 'followers', 'blocking', 'blockers'],
feed/obs/thread.jsView
@@ -7,10 +7,9 @@
77 'backlinks.obs.for': 'first',
88 'sbot.async.get': 'first',
99 'message.sync.unbox': 'first',
1010 'message.sync.root': 'first',
11- 'contact.obs.blocking': 'first',
12- 'keys.sync.id': 'first'
11+ 'message.sync.isBlocked': 'first',
1312 })
1413
1514 exports.gives = nest('feed.obs.thread')
1615
@@ -19,29 +18,27 @@
1918
2019 function thread (rootId, { branch } = {}) {
2120 if (!ref.isLink(rootId)) throw new Error('an id must be specified')
2221 var sync = Value(false)
22+ const { isBlocked, unbox, root } = message.sync
2323
24- const blocking = api.contact.obs.blocking(api.keys.sync.id())
25-
2624 var prepend = MutantArray()
2725 api.sbot.async.get(rootId, (err, value) => {
2826 sync.set(true)
2927 if (!err) {
3028 var msg = unboxIfNeeded({key: rootId, value})
31- if (blocking().includes(msg.value.author)) msg.isBlocked = true
29+ if (isBlocked(msg)) msg.isBlocked = true
3230 prepend.push(Value(msg))
3331 }
3432 })
3533
3634 var backlinks = api.backlinks.obs.for(rootId)
3735 var replies = map(computed(backlinks, (msgs) => {
3836 return msgs.filter(msg => {
39- return !blocking().includes(msg.value.author) &&
40- msg.value.content.type !== 'vote' && (
41- api.message.sync.root(msg) === rootId ||
42- matchAny(msg.value.content.branch, rootId)
43- )
37+ const { type, branch } = msg.value.content
38+ return type !== 'vote'
39+ && !isBlocked(msg)
40+ && (root(msg) === rootId || matchAny(branch, rootId))
4441 })
4542 }), x => Value(x), {
4643 // avoid refresh of entire list when items added
4744 comparer: (a, b) => a === b
@@ -93,9 +90,9 @@
9390 }
9491
9592 function unboxIfNeeded (msg) {
9693 if (msg.value && typeof msg.value.content === 'string') {
97- return api.message.sync.unbox(msg) || msg
94+ return unbox(msg) || msg
9895 } else {
9996 return msg
10097 }
10198 }
feed/pull/channel.jsView
@@ -4,10 +4,9 @@
44
55 exports.gives = nest('feed.pull.channel')
66 exports.needs = nest({
77 'sbot.pull.backlinks': 'first',
8- 'contact.obs.blocking': 'first',
9- 'keys.sync.id': 'first'
8+ 'message.sync.isBlocked': 'first',
109 })
1110
1211 exports.create = function (api) {
1312 return nest('feed.pull.channel', function (channel) {
@@ -27,17 +26,15 @@
2726 timestamp: typeof lt === 'number' ? {$lt: lt, $gt: 0} : {$gt: 0}
2827 }
2928 }
3029
31- const blocking = api.contact.obs.blocking(api.keys.sync.id())
32-
3330 return pull(
3431 api.sbot.pull.backlinks(extend(opts, {
3532 query: [
3633 {$filter: filter}
3734 ]
3835 })),
39- pull.filter(msg => !blocking().includes(msg.value.author))
36+ pull.filter(msg => !api.message.sync.isBlocked(msg))
4037 )
4138 }
4239 })
4340 }
feed/pull/mentions.jsView
@@ -4,10 +4,9 @@
44 const ref = require('ssb-ref')
55
66 exports.needs = nest({
77 'sbot.pull.backlinks': 'first',
8- 'contact.obs.blocking': 'first',
9- 'keys.sync.id': 'first'
8+ 'message.sync.isBlocked': 'first'
109 })
1110
1211 exports.gives = nest('feed.pull.mentions')
1312
@@ -30,13 +29,11 @@
3029 }}
3130 ]
3231 })
3332
34- const blocking = api.contact.obs.blocking(api.keys.sync.id())
35-
3633 return pull(
3734 api.sbot.pull.backlinks(opts),
38- pull.filter((msg) => !blocking().includes(msg.value.author))
35+ pull.filter(msg => !api.message.sync.isBlocked(msg))
3936 )
4037 }
4138 })
4239 }
feed/pull/public.jsView
@@ -3,10 +3,9 @@
33
44 exports.gives = nest('feed.pull.public')
55 exports.needs = nest({
66 'sbot.pull.feed': 'first',
7- 'contact.obs.blocking': 'first',
8- 'keys.sync.id': 'first'
7+ 'message.sync.isBlocked': 'first',
98 })
109
1110 exports.create = function (api) {
1211 return nest('feed.pull.public', (opts) => {
@@ -14,12 +13,10 @@
1413 opts.lt = (opts.lt && opts.lt.value)
1514 ? opts.lt.value.timestamp
1615 : opts.lt
1716
18- const blocking = api.contact.obs.blocking(api.keys.sync.id())
19-
2017 return pull(
2118 api.sbot.pull.feed(opts),
22- pull.filter(msg => !blocking().includes(msg.value.author))
19+ pull.filter(msg => !api.message.sync.isBlocked(msg))
2320 )
2421 })
2522 }
feed/pull/rollup.jsView
@@ -11,12 +11,11 @@
1111
1212 exports.needs = nest({
1313 'backlinks.obs.for': 'first',
1414 'sbot.async.get': 'first',
15+ 'message.sync.isBlocked': 'first',
1516 'message.sync.root': 'first',
1617 'message.sync.unbox': 'first',
17- 'contact.obs.blocking': 'first',
18- 'keys.sync.id': 'first'
1918 })
2019
2120 exports.gives = nest('feed.pull.rollup', true)
2221
@@ -24,10 +23,8 @@
2423 // cache mostly just to avoid reading the same roots over and over again
2524 // not really big enough for multiple refresh cycles
2625 var cache = HLRU(100)
2726
28- const blocking = api.contact.obs.blocking(api.keys.sync.id())
29-
3027 return nest('feed.pull.rollup', function (rootFilter) {
3128 var seen = new Set()
3229 return pull(
3330 pull.map(msg => {
@@ -87,19 +84,18 @@
8784
8885 // FILTER
8986 pull.filter(msg => msg && msg.value && !api.message.sync.root(msg)),
9087 pull.filter(rootFilter || (() => true)),
88+ pull.filter(msg => !api.message.sync.isBlocked(msg))
9189
92- pull.filter(msg => !blocking().includes(msg.value.author)),
93-
9490 // ADD REPLIES
9591 pull.asyncMap((rootMessage, cb) => {
9692 // use global backlinks cache
9793 var backlinks = api.backlinks.obs.for(rootMessage.key)
9894 onceTrue(backlinks.sync, () => {
99- var replies = resolve(backlinks).filter((msg) => {
100- return !blocking().includes(msg.value.author) &&
101- api.message.sync.root(msg) === rootMessage.key
95+ var replies = resolve(backlinks).filter(msg => {
96+ return api.message.sync.root(msg) === rootMessage.key
97+ && !api.message.sync.isBlocked(msg)
10298 })
10399 cb(null, extend(rootMessage, { replies }))
104100 })
105101 })
feed/pull/type.jsView
@@ -4,10 +4,9 @@
44
55 exports.gives = nest('feed.pull.type')
66 exports.needs = nest({
77 'sbot.pull.messagesByType': 'first',
8- 'contact.obs.blocking': 'first',
9- 'keys.sync.id': 'first'
8+ 'message.sync.isBlocked': 'first',
109 })
1110
1211 exports.create = function (api) {
1312 return nest('feed.pull.type', (type) => {
@@ -19,13 +18,11 @@
1918 // handle last item passed in as lt
2019 lt: opts.lt && typeof opts.lt === 'object' ? opts.lt.timestamp : opts.lt
2120 })
2221
23- const blocking = api.contact.obs.blocking(api.keys.sync.id())
24-
2522 return pull(
2623 api.sbot.pull.messagesByType(opts),
27- pull.filter(msg => !blocking().includes(msg.value.author))
24+ pull.filter(msg => !api.message.sync.isBlocked(msg))
2825 )
2926 }
3027 })
3128 }
message/sync/isBlocked.jsView
@@ -1,0 +1,22 @@
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+

Built with git-ssb-web