Skip to content

Commit

Permalink
Do not generate notifs when post violates threadgate (#1901)
Browse files Browse the repository at this point in the history
* do not generate notifs when post violates threadgate

* don't count threadgate-violating replies, style
  • Loading branch information
devinivy authored Dec 1, 2023
1 parent 1f3fad2 commit 9cec13e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/bsky/src/services/indexing/plugins/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) =>
Expand Down
26 changes: 26 additions & 0 deletions packages/bsky/tests/views/threadgating.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9cec13e

Please sign in to comment.