Skip to content

Commit

Permalink
Merge branch 'main' into timeline-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Jul 3, 2023
2 parents 2defa4f + 8815efd commit fb18045
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 11 deletions.
27 changes: 23 additions & 4 deletions packages/bsky/src/services/moderation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,31 @@ export class ModerationService {
.orWhere('subjectUri', '=', subject)
})
}

if (ignoreSubjects?.length) {
builder = builder.where((qb) => {
return qb
.where('subjectDid', 'not in', ignoreSubjects)
.where('subjectUri', 'not in', ignoreSubjects)
const ignoreUris: string[] = []
const ignoreDids: string[] = []

ignoreSubjects.forEach((subject) => {
if (subject.startsWith('at://')) {
ignoreUris.push(subject)
} else if (subject.startsWith('did:')) {
ignoreDids.push(subject)
}
})

if (ignoreDids.length) {
builder = builder.where('subjectDid', 'not in', ignoreDids)
}
if (ignoreUris.length) {
builder = builder.where((qb) => {
// Without the null condition, postgres will ignore all reports where `subjectUri` is null
// which will make all the account reports be ignored as well
return qb
.where('subjectUri', 'not in', ignoreUris)
.orWhere('subjectUri', 'is', null)
})
}
}

if (reporters?.length) {
Expand Down
3 changes: 2 additions & 1 deletion packages/pds/src/app-view/api/app/bsky/feed/getTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export default function (server: Server, ctx: AppContext) {
body: res.data,
}
}
if (ctx.canProxyFeedConstruction(req)) {

if (ctx.cfg.bskyAppViewEndpoint) {
const res =
await ctx.appviewAgent.api.app.bsky.unspecced.getTimelineSkeleton(
{ limit, cursor },
Expand Down
26 changes: 22 additions & 4 deletions packages/pds/src/services/moderation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,29 @@ export class ModerationService {
}

if (ignoreSubjects?.length) {
builder = builder.where((qb) => {
return qb
.where('subjectDid', 'not in', ignoreSubjects)
.where('subjectUri', 'not in', ignoreSubjects)
const ignoreUris: string[] = []
const ignoreDids: string[] = []

ignoreSubjects.forEach((subject) => {
if (subject.startsWith('at://')) {
ignoreUris.push(subject)
} else if (subject.startsWith('did:')) {
ignoreDids.push(subject)
}
})

if (ignoreDids.length) {
builder = builder.where('subjectDid', 'not in', ignoreDids)
}
if (ignoreUris.length) {
builder = builder.where((qb) => {
// Without the null condition, postgres will ignore all reports where `subjectUri` is null
// which will make all the account reports be ignored as well
return qb
.where('subjectUri', 'not in', ignoreUris)
.orWhere('subjectUri', 'is', null)
})
}
}

if (reporters?.length) {
Expand Down
29 changes: 27 additions & 2 deletions packages/pds/tests/views/admin/get-moderation-reports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,40 @@ describe('pds admin get moderation reports view', () => {

const ignoreSubjects = getDids(allReports).slice(0, 2)

const filteredReports =
const filteredReportsByDid =
await agent.api.com.atproto.admin.getModerationReports(
{ ignoreSubjects },
{ headers: { authorization: adminAuth() } },
)

getDids(filteredReports).forEach((resultDid) =>
// Validate that when ignored by DID, all reports for that DID is ignored
getDids(filteredReportsByDid).forEach((resultDid) =>
expect(ignoreSubjects).not.toContain(resultDid),
)

const ignoredAtUriSubjects: string[] = [
`${
allReports.data.reports.find(({ subject }) => !!subject.uri)?.subject
?.uri
}`,
]
const filteredReportsByAtUri =
await agent.api.com.atproto.admin.getModerationReports(
{
ignoreSubjects: ignoredAtUriSubjects,
},
{ headers: { authorization: adminAuth() } },
)

// Validate that when ignored by at uri, only the reports for that at uri is ignored
expect(filteredReportsByAtUri.data.reports.length).toEqual(
allReports.data.reports.length - 1,
)
expect(
filteredReportsByAtUri.data.reports
.map(({ subject }) => subject.uri)
.filter(Boolean),
).not.toContain(ignoredAtUriSubjects[0])
})

it('gets all moderation reports.', async () => {
Expand Down

0 comments on commit fb18045

Please sign in to comment.