Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Oct 12, 2023
1 parent 91c65f0 commit a1298b4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
16 changes: 15 additions & 1 deletion packages/bsky/src/api/com/atproto/admin/searchRepos.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Server } from '../../../../lexicon'
import AppContext from '../../../../context'
import { addAccountInfoToRepoView, getPdsAccountInfos } from './util'

export default function (server: Server, ctx: AppContext) {
server.com.atproto.admin.searchRepos({
Expand All @@ -14,11 +15,24 @@ export default function (server: Server, ctx: AppContext) {
const { results, cursor: resCursor } = await ctx.services
.actor(db)
.getSearchResults({ query, limit, cursor, includeSoftDeleted: true })

const [partialRepos, actorInfos] = await Promise.all([
moderationService.views.repo(results),
getPdsAccountInfos(
ctx,
results.map((r) => r.did),
),
])

const repos = partialRepos.map((repo) =>
addAccountInfoToRepoView(repo, actorInfos[repo.did] ?? null),
)

return {
encoding: 'application/json',
body: {
cursor: resCursor,
repos: await moderationService.views.repo(results),
repos,
},
}
},
Expand Down
16 changes: 16 additions & 0 deletions packages/bsky/src/api/com/atproto/admin/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ export const getPdsAccountInfo = async (
}
}

export const getPdsAccountInfos = async (
ctx: AppContext,
dids: string[],
): Promise<Record<string, UserAccountView>> => {
const unique = [...new Set(dids)]
const infos = await Promise.all(
unique.map((did) => getPdsAccountInfo(ctx, did)),
)
return infos.reduce((acc, cur) => {
if (cur) {
acc[cur.did] = cur
}
return acc
}, {} as Record<string, UserAccountView>)
}

export const addAccountInfoToRepoViewDetail = (
repoView: RepoViewDetail,
accountInfo: UserAccountView | null,
Expand Down
4 changes: 2 additions & 2 deletions packages/bsky/tests/auto-moderator/takedowns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('takedowner', () => {
.where('uri', '=', post.ref.uriStr)
.select('takedownId')
.executeTakeFirst()
expect(recordPds?.takedownId).toEqual(modAction.id)
expect(recordPds?.takedownId).toEqual(modAction.id.toString())

expect(testInvalidator.invalidated.length).toBe(1)
expect(testInvalidator.invalidated[0].subject).toBe(
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('takedowner', () => {
.where('uri', '=', res.data.uri)
.select('takedownId')
.executeTakeFirst()
expect(recordPds?.takedownId).toEqual(modAction.id)
expect(recordPds?.takedownId).toEqual(modAction.id.toString())

expect(testInvalidator.invalidated.length).toBe(2)
expect(testInvalidator.invalidated[1].subject).toBe(
Expand Down

0 comments on commit a1298b4

Please sign in to comment.