From 9cec13ee46aabcda71a6245e28e96d968ed9a289 Mon Sep 17 00:00:00 2001 From: devin ivy Date: Fri, 1 Dec 2023 18:15:27 -0500 Subject: [PATCH] Do not generate notifs when post violates threadgate (#1901) * do not generate notifs when post violates threadgate * don't count threadgate-violating replies, style --- .../src/services/indexing/plugins/post.ts | 13 ++++++++++ .../bsky/tests/views/threadgating.test.ts | 26 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/packages/bsky/src/services/indexing/plugins/post.ts b/packages/bsky/src/services/indexing/plugins/post.ts index 5f2fca934ce..af581b3bdff 100644 --- a/packages/bsky/src/services/indexing/plugins/post.ts +++ b/packages/bsky/src/services/indexing/plugins/post.ts @@ -112,6 +112,7 @@ const insertFn = async ( obj.reply, ) if (invalidReplyRoot || violatesThreadGate) { + Object.assign(insertedPost, { invalidReplyRoot, violatesThreadGate }) await db .updateTable('post') .where('uri', '=', post.uri) @@ -241,6 +242,13 @@ const notifsForInsert = (obj: IndexedPost) => { } } + if (obj.post.violatesThreadGate) { + // don't generate reply notifications when post violates threadgate + return notifs + } + + // reply notifications + for (const ancestor of obj.ancestors ?? []) { if (ancestor.uri === obj.post.uri) continue // no need to notify for own post if (ancestor.height < REPLY_NOTIF_DEPTH) { @@ -353,6 +361,11 @@ const updateAggregates = async (db: DatabaseSchema, postIdx: IndexedPost) => { replyCount: db .selectFrom('post') .where('post.replyParent', '=', postIdx.post.replyParent) + .where((qb) => + qb + .where('post.violatesThreadGate', 'is', null) + .orWhere('post.violatesThreadGate', '=', false), + ) .select(countAll.as('count')), }) .onConflict((oc) => diff --git a/packages/bsky/tests/views/threadgating.test.ts b/packages/bsky/tests/views/threadgating.test.ts index 53e5961b595..5f530b33536 100644 --- a/packages/bsky/tests/views/threadgating.test.ts +++ b/packages/bsky/tests/views/threadgating.test.ts @@ -64,6 +64,32 @@ describe('views with thread gating', () => { await checkReplyDisabled(post.ref.uriStr, sc.dids.alice, true) }) + it('does not generate notifications when post violates threadgate.', async () => { + const post = await sc.post(sc.dids.carol, 'notifications') + await pdsAgent.api.app.bsky.feed.threadgate.create( + { repo: sc.dids.carol, rkey: post.ref.uri.rkey }, + { post: post.ref.uriStr, createdAt: iso(), allow: [] }, + sc.getHeaders(sc.dids.carol), + ) + const reply = await sc.reply( + sc.dids.alice, + post.ref, + post.ref, + 'notifications reply', + ) + await network.processAll() + const { + data: { notifications }, + } = await agent.api.app.bsky.notification.listNotifications( + {}, + { headers: await network.serviceHeaders(sc.dids.carol) }, + ) + const notificationFromReply = notifications.find( + (notif) => notif.uri === reply.ref.uriStr, + ) + expect(notificationFromReply).toBeUndefined() + }) + it('applies gate for mention rule.', async () => { const post = await sc.post( sc.dids.carol,