Skip to content

Commit

Permalink
moderation events working
Browse files Browse the repository at this point in the history
  • Loading branch information
dholms committed Dec 20, 2023
1 parent ecb163e commit 6fb8d5b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
26 changes: 25 additions & 1 deletion packages/ozone/src/services/moderation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
isModEventEmail,
RepoRef,
RepoBlobRef,
AccountView,
} from '../../lexicon/types/com/atproto/admin/defs'
import { addHoursToDate } from '../../util/date'
import {
Expand All @@ -32,6 +33,7 @@ import { StatusKeyset, TimeIdKeyset } from './pagination'
import AtpAgent from '@atproto/api'
import { Label } from '../../lexicon/types/com/atproto/label/defs'
import { sql } from 'kysely'
import { dedupeStrs } from '@atproto/common'

export class ModerationService {
constructor(public db: Database, public appviewAgent: AtpAgent) {}
Expand Down Expand Up @@ -123,7 +125,29 @@ export class ModerationService {

const result = await paginatedBuilder.execute()

return { cursor: keyset.packFromResult(result), events: result }
const dids = dedupeStrs([
...result.map((row) => row.subjectDid),
...result.map((row) => row.createdBy),
])
const handlesByDid = await this.getHandlesByDid(dids)

const resultWithHandles = result.map((r) => ({
...r,
creatorHandle: handlesByDid.get(r.createdBy),
subjectHandle: handlesByDid.get(r.subjectDid),
}))

return { cursor: keyset.packFromResult(result), events: resultWithHandles }
}

async getHandlesByDid(dids: string[]) {
if (dids.length === 0) return new Map()
const res = await this.appviewAgent.api.com.atproto.admin.getAccountInfos({
dids,
})
return res.data.infos.reduce((acc, cur) => {
return acc.set(cur.did, cur.handle)
}, new Map<string, string>())
}

async getReport(id: number): Promise<ModerationEventRow | undefined> {
Expand Down
6 changes: 5 additions & 1 deletion packages/ozone/tests/admin/moderation-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ describe('moderation-events', () => {
beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'bsky_moderation_events',
ozone: { enabled: true },
})
agent = network.bsky.getClient()
if (!network.ozone) {
throw new Error('Ozone not setup')
}
agent = network.ozone?.getClient()
pdsAgent = network.pds.getClient()
sc = network.getSeedClient()
await basicSeed(sc)
Expand Down

0 comments on commit 6fb8d5b

Please sign in to comment.