git ssb

7+

dinoworm ๐Ÿ› / patchcore



Commit 3874b7fbf1d24582021a15bf44be07ada911f403

Merge branch 'dont-show-post-of-blocked'

Matt McKegg committed on 10/14/2017, 2:18:04 AM
Parent: 40c2f3dae32d12b6a79216ecb01df3cf7c57ce4b
Parent: bcf23f7ed7e27cc8755003023c9fd57775f79ca9

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/html/render/post.jschanged
message/sync/is-blocked.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
@@ -6,9 +6,10 @@
66 exports.needs = nest({
77 'backlinks.obs.for': 'first',
88 'sbot.async.get': 'first',
99 'message.sync.unbox': 'first',
10- 'message.sync.root': 'first'
10+ 'message.sync.root': 'first',
11+ 'message.sync.isBlocked': 'first'
1112 })
1213
1314 exports.gives = nest('feed.obs.thread')
1415
@@ -17,26 +18,25 @@
1718
1819 function thread (rootId, { branch } = {}) {
1920 if (!ref.isLink(rootId)) throw new Error('an id must be specified')
2021 var sync = Value(false)
22+ var { isBlocked, root } = api.message.sync
2123
2224 var prepend = MutantArray()
2325 api.sbot.async.get(rootId, (err, value) => {
2426 sync.set(true)
2527 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))
2931 }
3032 })
3133
3234 var backlinks = api.backlinks.obs.for(rootId)
3335 var replies = map(computed(backlinks, (msgs) => {
3436 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))
3939 })
4040 }), x => Value(x), {
4141 // avoid refresh of entire list when items added
4242 comparer: (a, b) => a === b
feed/pull/channel.jsView
@@ -1,10 +1,12 @@
11 const nest = require('depnest')
22 const extend = require('xtend')
3+var pull = require('pull-stream')
34
45 exports.gives = nest('feed.pull.channel')
56 exports.needs = nest({
6- 'sbot.pull.backlinks': 'first'
7+ 'sbot.pull.backlinks': 'first',
8+ 'message.sync.isBlocked': 'first',
79 })
810
911 exports.create = function (api) {
1012 return nest('feed.pull.channel', function (channel) {
@@ -24,12 +26,15 @@
2426 timestamp: typeof lt === 'number' ? {$lt: lt, $gt: 0} : {$gt: 0}
2527 }
2628 }
2729
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+ )
3338 }
3439 })
3540 }
feed/pull/mentions.jsView
@@ -3,9 +3,10 @@
33 const pull = require('pull-stream')
44 const ref = require('ssb-ref')
55
66 exports.needs = nest({
7- 'sbot.pull.backlinks': 'first'
7+ 'sbot.pull.backlinks': 'first',
8+ 'message.sync.isBlocked': 'first'
89 })
910
1011 exports.gives = nest('feed.pull.mentions')
1112
@@ -28,8 +29,11 @@
2829 }}
2930 ]
3031 })
3132
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+ )
3337 }
3438 })
3539 }
feed/pull/public.jsView
@@ -1,13 +1,22 @@
11 const nest = require('depnest')
2+var pull = require('pull-stream')
23
34 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+
510 exports.create = function (api) {
611 return nest('feed.pull.public', (opts) => {
712 // handle last item passed in as lt
813 opts.lt = (opts.lt && opts.lt.value)
914 ? opts.lt.value.timestamp
1015 : 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+ )
1221 })
1322 }
feed/pull/rollup.jsView
@@ -11,10 +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',
16- 'message.sync.unbox': 'first'
17+ 'message.sync.unbox': 'first',
1718 })
1819
1920 exports.gives = nest('feed.pull.rollup', true)
2021
@@ -83,16 +84,17 @@
8384
8485 // FILTER
8586 pull.filter(msg => msg && msg.value && !api.message.sync.root(msg)),
8687 pull.filter(rootFilter || (() => true)),
88+ pull.filter(msg => !api.message.sync.isBlocked(msg)),
8789
8890 // ADD REPLIES
8991 pull.asyncMap((rootMessage, cb) => {
9092 // use global backlinks cache
9193 var backlinks = api.backlinks.obs.for(rootMessage.key)
9294 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)
9597 })
9698 cb(null, extend(rootMessage, { replies }))
9799 })
98100 })
feed/pull/type.jsView
@@ -1,9 +1,14 @@
11 const nest = require('depnest')
22 const extend = require('xtend')
3+const pull = require('pull-stream')
34
45 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+
611 exports.create = function (api) {
712 return nest('feed.pull.type', (type) => {
813 if (typeof type !== 'string') throw new Error('a type must be specified')
914
@@ -13,8 +18,11 @@
1318 // handle last item passed in as lt
1419 lt: opts.lt && typeof opts.lt === 'object' ? opts.lt.timestamp : opts.lt
1520 })
1621
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+ )
1826 }
1927 })
2028 }
message/html/render/post.jsView
@@ -17,9 +17,9 @@
1717 return nest('message.html.render', function renderMessage (msg, opts) {
1818 if (msg.value.content.type !== 'post') return
1919 var element = api.message.html.layout(msg, extend({
2020 title: messageTitle(msg),
21- content: messageContent(msg),
21+ content: msg.isBlocked ? 'Content of a blocked user' : messageContent(msg),
2222 layout: 'default'
2323 }, opts))
2424
2525 return api.message.html.decorate(element, { msg })
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