git ssb

7+

dinoworm 🐛 / patchcore



Commit 37af73bc5ddcbd3b63159caf24f253e95f6f3664

don't include replies in threads or rollups from people blocked by root message author

Matt McKegg committed on 7/8/2018, 2:50:11 AM
Parent: 632f74ad8a65960017ff438eaf47b2e90ccd7cc8

Files changed

contact/obs.jschanged
feed/obs/thread.jschanged
feed/pull/with-replies.jschanged
message/sync/is-blocked.jschanged
contact/obs.jsView
@@ -9,9 +9,9 @@
99 'sbot.pull.stream': 'first'
1010 })
1111
1212 exports.gives = nest({
13- 'contact.obs': ['following', 'followers', 'blocking', 'blockers'],
13 + 'contact.obs': ['following', 'followers', 'blocking', 'blockers', 'raw'],
1414 'sbot.hook.publish': true
1515 })
1616
1717 exports.create = function (api) {
@@ -31,9 +31,10 @@
3131
3232 following: (key) => matchingValueKeys(get(key, cache), true),
3333 followers: (key) => matchingValueKeys(get(key, reverseCache), true),
3434 blocking: (key) => matchingValueKeys(get(key, cache), false),
35- blockers: (key) => matchingValueKeys(get(key, reverseCache), false)
35 + blockers: (key) => matchingValueKeys(get(key, reverseCache), false),
36 + raw: (key) => get(key, cache)
3637 },
3738 'sbot.hook.publish': function (msg) {
3839 if (!isContact(msg)) return
3940
feed/obs/thread.jsView
@@ -3,9 +3,9 @@
33 var ref = require('ssb-ref')
44 var isBlog = require('scuttle-blog/isBlog')
55 var Blog = require('scuttle-blog')
66
7-var { Array: MutantArray, Value, map, computed, concat } = require('mutant')
7 +var { Array: MutantArray, Value, map, computed, concat, ProxyCollection } = require('mutant')
88
99 exports.needs = nest({
1010 'backlinks.obs.for': 'first',
1111 'sbot.async.get': 'first',
@@ -23,46 +23,49 @@
2323 function thread (rootId, { branch } = {}) {
2424 if (!ref.isLink(rootId)) throw new Error('an id must be specified')
2525 var sync = Value(false)
2626 var { isBlocked, root } = api.message.sync
27 + var replies = ProxyCollection()
2728
2829 var prepend = MutantArray()
2930 api.sbot.async.get(rootId, (err, value) => {
31 + var rootMessage = null
3032 if (!err) {
31- var msg = unboxIfNeeded({key: rootId, value})
32- if (isBlocked(msg)) msg.isBlocked = true
33 + rootMessage = unboxIfNeeded({key: rootId, value})
34 + if (isBlocked(rootMessage)) rootMessage.isBlocked = true
3335
34- if (isBlog(msg)) {
36 + if (isBlog(rootMessage)) {
3537 // resolve the blog body before returning
36- Blog(api.sbot.obs.connection).async.get(msg, (err, result) => {
38 + Blog(api.sbot.obs.connection).async.get(rootMessage, (err, result) => {
3739 if (!err) {
38- msg.body = result.body
39- prepend.push(Value(msg))
40 + rootMessage.body = result.body
41 + prepend.push(Value(rootMessage))
4042 sync.set(true)
4143 }
4244 })
4345 } else {
4446 sync.set(true)
45- prepend.push(Value(msg))
47 + prepend.push(Value(rootMessage))
4648 }
4749 } else {
4850 sync.set(true)
4951 }
52 +
53 + // calcaulate after message has been resolved so that we can check if thread author blocks the reply
54 + // wrap computed in a map to turn into individual observables
55 + replies.set(map(computed(backlinks, (msgs) => {
56 + return sort(msgs.filter(msg => {
57 + const { type, branch } = msg.value.content
58 + return type !== 'vote' && !isBlocked(msg, rootMessage) && (root(msg) === rootId || matchAny(branch, rootId))
59 + }))
60 + }), x => Value(x), {
61 + // avoid refresh of entire list when items added
62 + comparer: (a, b) => a === b
63 + }))
5064 })
5165
5266 var backlinks = api.backlinks.obs.for(rootId)
5367
54- // wrap computed in a map to turn into individual observables
55- var replies = map(computed(backlinks, (msgs) => {
56- return sort(msgs.filter(msg => {
57- const { type, branch } = msg.value.content
58- return type !== 'vote' && !isBlocked(msg) && (root(msg) === rootId || matchAny(branch, rootId))
59- }))
60- }), x => Value(x), {
61- // avoid refresh of entire list when items added
62- comparer: (a, b) => a === b
63- })
64-
6568 // append the root message to the sorted replies list
6669 // -------------------------
6770 // concat preserves the individual observable messages so that clients don't need to
6871 // rerender the entire list when an item is added (map will only be called for new items)
feed/pull/with-replies.jsView
@@ -18,9 +18,9 @@
1818 // use global backlinks cache
1919 var backlinks = api.backlinks.obs.for(rootMessage.key)
2020 onceTrue(backlinks.sync, () => {
2121 var replies = resolve(backlinks).filter(msg => {
22- return api.message.sync.root(msg) === rootMessage.key && !api.message.sync.isBlocked(msg)
22 + return api.message.sync.root(msg) === rootMessage.key && !api.message.sync.isBlocked(msg, rootMessage)
2323 })
2424 cb(null, extend(rootMessage, { replies }))
2525 })
2626 })
message/sync/is-blocked.jsView
@@ -3,18 +3,27 @@
33 exports.gives = nest('message.sync.isBlocked')
44
55 exports.needs = nest({
66 'contact.obs.blocking': 'first',
7 + 'contact.obs.raw': 'first',
78 'keys.sync.id': 'first'
89 })
910
1011 exports.create = function (api) {
1112 var cache = null
1213
13- return nest('message.sync.isBlocked', function isBlockedMessage (msg) {
14 + return nest('message.sync.isBlocked', function isBlockedMessage (msg, rootMessage) {
1415 if (!cache) {
1516 cache = api.contact.obs.blocking(api.keys.sync.id())
1617 }
1718
19 + if (rootMessage) {
20 + // check if the author of the root message blocks the author of the message
21 + var rawContact = api.contact.obs.raw(rootMessage.value.author)
22 + if (rawContact()[msg.value.author] === false) {
23 + return true
24 + }
25 + }
26 +
1827 return cache().includes(msg.value.author)
1928 })
2029 }

Built with git-ssb-web