Skip to content

Commit

Permalink
Include own replies to own post roots via new filter `posts_and_autho…
Browse files Browse the repository at this point in the history
…r_threads` (bluesky-social#1776)

* Include own replies to own post roots in post_no_replies

* Updates

* Simplify

* snaps

* snaps

* Remove unused import

* Add new threads filter to getAuthorFeed

* Implement new filter

* Typo
  • Loading branch information
estrattonbailey authored Dec 8, 2023
1 parent 8f84207 commit ffe39aa
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-eyes-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@atproto/bsky': patch
---

Integrate `posts_and_author_threads` filter into `getAuthorFeed` implementation.
7 changes: 7 additions & 0 deletions .changeset/large-books-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@atproto/bsky': patch
'@atproto/api': patch
'@atproto/pds': patch
---

Add `posts_and_author_threads` filter to `getAuthorFeed`
3 changes: 2 additions & 1 deletion lexicons/app/bsky/feed/getAuthorFeed.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"knownValues": [
"posts_with_replies",
"posts_no_replies",
"posts_with_media"
"posts_with_media",
"posts_and_author_threads"
],
"default": "posts_with_replies"
}
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5572,6 +5572,7 @@ export const schemaDict = {
'posts_with_replies',
'posts_no_replies',
'posts_with_media',
'posts_and_author_threads',
],
default: 'posts_with_replies',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface QueryParams {
| 'posts_with_replies'
| 'posts_no_replies'
| 'posts_with_media'
| 'posts_and_author_threads'
| (string & {})
}

Expand Down
8 changes: 4 additions & 4 deletions packages/api/src/moderation/const/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,23 @@ export const LABELS: LabelDefinitionMap = {
strings: {
settings: {
en: {
name: 'Requested Hidden to Logged-out Users',
name: 'Sign-in Required',
description:
'This user has requested that their content only be shown to logged-in accounts.',
'This user has requested that their account only be shown to signed-in users.',
},
},
account: {
en: {
name: 'Sign-in Required',
description:
'This user has requested that their content only be shown to logged-in accounts.',
'This user has requested that their account only be shown to signed-in users.',
},
},
content: {
en: {
name: 'Sign-in Required',
description:
'This user has requested that their content only be shown to logged-in accounts.',
'This user has requested that their content only be shown to signed-in users.',
},
},
},
Expand Down
7 changes: 7 additions & 0 deletions packages/bsky/src/api/app/bsky/feed/getAuthorFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ export const skeleton = async (
feedItemsQb = feedItemsQb.where((qb) =>
qb.where('post.replyParent', 'is', null).orWhere('type', '=', 'repost'),
)
} else if (filter === 'posts_and_author_threads') {
feedItemsQb = feedItemsQb.where((qb) =>
qb
.where('type', '=', 'repost')
.orWhere('post.replyParent', 'is', null)
.orWhere('post.replyRoot', 'like', `at://${actorDid}/%`),
)
}

const keyset = new FeedKeyset(ref('feed_item.sortAt'), ref('feed_item.cid'))
Expand Down
1 change: 1 addition & 0 deletions packages/bsky/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5572,6 +5572,7 @@ export const schemaDict = {
'posts_with_replies',
'posts_no_replies',
'posts_with_media',
'posts_and_author_threads',
],
default: 'posts_with_replies',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface QueryParams {
| 'posts_with_replies'
| 'posts_no_replies'
| 'posts_with_media'
| 'posts_and_author_threads'
| (string & {})
}

Expand Down
95 changes: 95 additions & 0 deletions packages/bsky/tests/seeds/author-feed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { SeedClient } from '@atproto/dev-env'
import basicSeed from './basic'

export default async (sc: SeedClient) => {
await basicSeed(sc)
await sc.createAccount('eve', {
email: '[email protected]',
handle: 'eve.test',
password: 'eve-pass',
})
await sc.createAccount('fred', {
email: '[email protected]',
handle: 'fred.test',
password: 'fred-pass',
})

const alice = sc.dids.alice
const eve = sc.dids.eve
const fred = sc.dids.fred

/*
* Self thread
*/
await sc.post(eve, evePosts[0])
await sc.reply(
eve,
sc.posts[eve][0].ref,
sc.posts[eve][0].ref,
eveOwnThreadReplies[0],
)
await sc.reply(
eve,
sc.posts[eve][0].ref,
sc.replies[eve][0].ref,
eveOwnThreadReplies[1],
)
await sc.reply(
eve,
sc.posts[eve][0].ref,
sc.replies[eve][1].ref,
eveOwnThreadReplies[2],
)

/**
* Two replies to Alice
*/
await sc.reply(
eve,
sc.posts[alice][1].ref,
sc.posts[alice][1].ref,
eveAliceReplies[0],
)
await sc.reply(
eve,
sc.posts[alice][1].ref,
sc.replies[eve][3].ref,
eveAliceReplies[1],
)

/**
* Two replies to Fred, who replied to Eve's root post. This creates a
* "detached" thread, where one Fred post breaks the continuity.
*/
await sc.post(eve, evePosts[1])
await sc.reply(
fred,
sc.posts[eve][1].ref,
sc.posts[eve][1].ref,
fredReplies[0],
)
await sc.reply(
eve,
sc.posts[eve][1].ref,
sc.replies[fred][0].ref,
eveFredReplies[0],
)
await sc.reply(
eve,
sc.posts[eve][1].ref,
sc.replies[eve][4].ref,
eveFredReplies[1],
)

return sc
}

const evePosts = ['eve own thread', 'eve detached thread']
const eveOwnThreadReplies = [
'eve own reply 1',
'eve own reply 2',
'eve own reply 3',
]
const eveAliceReplies = ['eve reply to alice 1', 'eve reply to alice 2']
const eveFredReplies = ['eve reply to fred 1', 'eve reply to fred 2']
const fredReplies = ['fred reply to eve 1']
20 changes: 10 additions & 10 deletions packages/bsky/tests/views/__snapshots__/author-feed.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Array [
"createdAt": "1970-01-01T00:00:00.000000Z",
"text": "again",
},
"replyCount": 2,
"replyCount": 3,
"repostCount": 1,
"uri": "record(2)",
"viewer": Object {},
Expand Down Expand Up @@ -395,7 +395,7 @@ Array [
"createdAt": "1970-01-01T00:00:00.000000Z",
"text": "again",
},
"replyCount": 2,
"replyCount": 3,
"repostCount": 1,
"uri": "record(2)",
"viewer": Object {},
Expand Down Expand Up @@ -590,7 +590,7 @@ Array [
"createdAt": "1970-01-01T00:00:00.000000Z",
"text": "again",
},
"replyCount": 2,
"replyCount": 3,
"repostCount": 1,
"uri": "record(1)",
"viewer": Object {
Expand Down Expand Up @@ -638,7 +638,7 @@ Array [
"createdAt": "1970-01-01T00:00:00.000000Z",
"text": "again",
},
"replyCount": 2,
"replyCount": 3,
"repostCount": 1,
"uri": "record(1)",
"viewer": Object {
Expand Down Expand Up @@ -961,7 +961,7 @@ Array [
"createdAt": "1970-01-01T00:00:00.000000Z",
"text": "again",
},
"replyCount": 2,
"replyCount": 3,
"repostCount": 1,
"uri": "record(6)",
"viewer": Object {
Expand Down Expand Up @@ -1009,7 +1009,7 @@ Array [
"createdAt": "1970-01-01T00:00:00.000000Z",
"text": "again",
},
"replyCount": 2,
"replyCount": 3,
"repostCount": 1,
"uri": "record(6)",
"viewer": Object {
Expand Down Expand Up @@ -1326,7 +1326,7 @@ Array [
"createdAt": "1970-01-01T00:00:00.000000Z",
"text": "again",
},
"replyCount": 2,
"replyCount": 3,
"repostCount": 1,
"uri": "record(3)",
"viewer": Object {
Expand Down Expand Up @@ -1376,7 +1376,7 @@ Array [
"createdAt": "1970-01-01T00:00:00.000000Z",
"text": "again",
},
"replyCount": 2,
"replyCount": 3,
"repostCount": 1,
"uri": "record(3)",
"viewer": Object {
Expand Down Expand Up @@ -1765,7 +1765,7 @@ Array [
"createdAt": "1970-01-01T00:00:00.000000Z",
"text": "again",
},
"replyCount": 2,
"replyCount": 3,
"repostCount": 1,
"uri": "record(4)",
"viewer": Object {
Expand Down Expand Up @@ -1987,7 +1987,7 @@ Array [
"createdAt": "1970-01-01T00:00:00.000000Z",
"text": "again",
},
"replyCount": 2,
"replyCount": 3,
"repostCount": 1,
"uri": "record(4)",
"viewer": Object {
Expand Down
22 changes: 20 additions & 2 deletions packages/bsky/tests/views/author-feed.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import AtpAgent from '@atproto/api'
import { TestNetwork, SeedClient } from '@atproto/dev-env'
import { forSnapshot, paginateAll, stripViewerFromPost } from '../_util'
import basicSeed from '../seeds/basic'
import authorFeedSeed from '../seeds/author-feed'
import { isRecord } from '../../src/lexicon/types/app/bsky/feed/post'
import { isView as isEmbedRecordWithMedia } from '../../src/lexicon/types/app/bsky/embed/recordWithMedia'
import { isView as isImageEmbed } from '../../src/lexicon/types/app/bsky/embed/images'
Expand All @@ -16,19 +16,21 @@ describe('pds author feed views', () => {
let bob: string
let carol: string
let dan: string
let eve: string

beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'bsky_views_author_feed',
})
agent = network.bsky.getClient()
sc = network.getSeedClient()
await basicSeed(sc)
await authorFeedSeed(sc)
await network.processAll()
alice = sc.dids.alice
bob = sc.dids.bob
carol = sc.dids.carol
dan = sc.dids.dan
eve = sc.dids.eve
})

afterAll(async () => {
Expand Down Expand Up @@ -305,4 +307,20 @@ describe('pds author feed views', () => {
}),
).toBeTruthy()
})

it('posts_and_author_threads includes self-replies', async () => {
const { data: eveFeed } = await agent.api.app.bsky.feed.getAuthorFeed({
actor: eve,
filter: 'posts_and_author_threads',
})

expect(eveFeed.feed.length).toEqual(7)
expect(
eveFeed.feed.some(({ post }) => {
return (
isRecord(post.record) && post.record.reply && post.author.did === eve
)
}),
).toBeTruthy()
})
})
1 change: 1 addition & 0 deletions packages/pds/src/lexicon/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5572,6 +5572,7 @@ export const schemaDict = {
'posts_with_replies',
'posts_no_replies',
'posts_with_media',
'posts_and_author_threads',
],
default: 'posts_with_replies',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface QueryParams {
| 'posts_with_replies'
| 'posts_no_replies'
| 'posts_with_media'
| 'posts_and_author_threads'
| (string & {})
}

Expand Down

0 comments on commit ffe39aa

Please sign in to comment.