Skip to content

Commit

Permalink
Ozone namespace changes and decouple labels from sdk (#46)
Browse files Browse the repository at this point in the history
* ✨ Update ozone namespace

* ✨ Hard code label definitions
  • Loading branch information
foysalit authored Mar 12, 2024
1 parent f0ae6cf commit 4c83d5d
Show file tree
Hide file tree
Showing 40 changed files with 1,285 additions and 442 deletions.
9 changes: 4 additions & 5 deletions app/actions/ModActionPanel/BlobList.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { ComponentProps } from 'react'
import Link from 'next/link'
import { ComAtprotoAdminDefs } from '@atproto/api'
import { ToolsOzoneModerationDefs } from '@atproto/api'
import { ShieldExclamationIcon } from '@heroicons/react/20/solid'
import { formatBytes } from '@/lib/util'
import { ReviewStateIconLink } from '@/subject/ReviewStateMarker'

export function BlobList(props: {
name: string
disabled?: boolean
blobs: ComAtprotoAdminDefs.BlobView[]
blobs: ToolsOzoneModerationDefs.BlobView[]
}) {
const { name, disabled, blobs } = props
return (
Expand Down Expand Up @@ -52,8 +51,8 @@ export function BlobList(props: {
<p id={`blob-${blob.cid}-description`}>
<Chip>{blob.mimeType}</Chip>
<Chip>{formatBytes(blob.size)}</Chip>
{(ComAtprotoAdminDefs.isImageDetails(blob.details) ||
ComAtprotoAdminDefs.isVideoDetails(blob.details)) && (
{(ToolsOzoneModerationDefs.isImageDetails(blob.details) ||
ToolsOzoneModerationDefs.isVideoDetails(blob.details)) && (
<Chip>
{blob.details.height}x{blob.details.width}px
</Chip>
Expand Down
18 changes: 8 additions & 10 deletions app/actions/ModActionPanel/QuickAction.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// TODO: This is badly named so that we can rebuild this component without breaking the old one
import { useQuery } from '@tanstack/react-query'
import {
ComAtprotoAdminDefs,
ComAtprotoAdminEmitModerationEvent,
ComAtprotoModerationDefs,
ToolsOzoneModerationDefs,
ToolsOzoneModerationEmitEvent,
} from '@atproto/api'
import { FormEvent, useEffect, useRef, useState } from 'react'
import { ActionPanel } from '@/common/ActionPanel'
Expand Down Expand Up @@ -56,9 +56,7 @@ type Props = {
setSubject: (subject: string) => void
subjectOptions?: string[]
isInitialLoading: boolean
onSubmit: (
vals: ComAtprotoAdminEmitModerationEvent.InputSchema,
) => Promise<void>
onSubmit: (vals: ToolsOzoneModerationEmitEvent.InputSchema) => Promise<void>
}

const dateFormatter = new Intl.DateTimeFormat('en-US', {
Expand Down Expand Up @@ -170,9 +168,9 @@ function Form(
})
const isSubjetDid = subject.startsWith('did:')
const isReviewClosed =
subjectStatus?.reviewState === ComAtprotoAdminDefs.REVIEWCLOSED
subjectStatus?.reviewState === ToolsOzoneModerationDefs.REVIEWCLOSED
const isEscalated =
subjectStatus?.reviewState === ComAtprotoAdminDefs.REVIEWESCALATED
subjectStatus?.reviewState === ToolsOzoneModerationDefs.REVIEWESCALATED

const allLabels = getLabelsForSubject({ repo, record })
const currentLabels = allLabels.map((label) =>
Expand Down Expand Up @@ -740,15 +738,15 @@ function Form(

async function getSubject(subject: string) {
if (subject.startsWith('did:')) {
const { data: repo } = await client.api.com.atproto.admin.getRepo(
const { data: repo } = await client.api.tools.ozone.moderation.getRepo(
{
did: subject,
},
{ headers: client.proxyHeaders() },
)
return { repo }
} else if (subject.startsWith('at://')) {
const { data: record } = await client.api.com.atproto.admin.getRecord(
const { data: record } = await client.api.tools.ozone.moderation.getRecord(
{
uri: subject,
},
Expand All @@ -763,7 +761,7 @@ async function getSubject(subject: string) {
async function getSubjectStatus(subject: string) {
const {
data: { subjectStatuses },
} = await client.api.com.atproto.admin.queryModerationStatuses(
} = await client.api.tools.ozone.moderation.queryStatuses(
{
subject,
includeMuted: true,
Expand Down
2 changes: 1 addition & 1 deletion app/actions/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function Action({ params }: { params: { id: string } }) {
const { data: action, error } = useQuery({
queryKey: ['action', { id }],
queryFn: async () => {
const { data } = await client.api.com.atproto.admin.getModerationEvent(
const { data } = await client.api.tools.ozone.moderation.getEvent(
{
id: parseInt(id, 10),
},
Expand Down
2 changes: 1 addition & 1 deletion app/events/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function EventViewPage({ params }: { params: { id: string } }) {
const { data: event, error } = useQuery({
queryKey: ['event', { id }],
queryFn: async () => {
const { data } = await client.api.com.atproto.admin.getModerationEvent(
const { data } = await client.api.tools.ozone.moderation.getEvent(
{
id: parseInt(id, 10),
},
Expand Down
4 changes: 2 additions & 2 deletions app/events/page-content.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTitle } from 'react-use'
import { ModEventList } from '@/mod-event/EventList'
import { emitEvent } from '@/mod-event/helpers/emitEvent'
import { ComAtprotoAdminEmitModerationEvent } from '@atproto/api'
import { ToolsOzoneModerationEmitEvent } from '@atproto/api'
import { ModActionPanelQuick } from 'app/actions/ModActionPanel/QuickAction'
import { usePathname, useRouter, useSearchParams } from 'next/navigation'

Expand Down Expand Up @@ -35,7 +35,7 @@ export default function EventListPageContent() {
subjectOptions={[quickOpenParam]}
isInitialLoading={false}
onSubmit={async (
vals: ComAtprotoAdminEmitModerationEvent.InputSchema,
vals: ToolsOzoneModerationEmitEvent.InputSchema,
) => {
await emitEvent(vals)
}}
Expand Down
24 changes: 12 additions & 12 deletions app/reports/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
import { useInfiniteQuery } from '@tanstack/react-query'
import {
AtUri,
ComAtprotoAdminDefs,
ComAtprotoAdminEmitModerationEvent,
ComAtprotoAdminQueryModerationStatuses,
ToolsOzoneModerationDefs,
ToolsOzoneModerationEmitEvent,
ToolsOzoneModerationQueryStatuses
} from '@atproto/api'
import { SectionHeader } from '../../components/SectionHeader'
import { ModActionIcon } from '@/common/ModActionIcon'
Expand All @@ -32,21 +32,21 @@ const TABS = [
key: 'unresolved',
name: 'Unresolved',
href: `/reports?reviewState=${encodeURIComponent(
ComAtprotoAdminDefs.REVIEWOPEN,
ToolsOzoneModerationDefs.REVIEWOPEN,
)}`,
},
{
key: 'escalated',
name: 'Escalated',
href: `/reports?reviewState=${encodeURIComponent(
ComAtprotoAdminDefs.REVIEWESCALATED,
ToolsOzoneModerationDefs.REVIEWESCALATED,
)}`,
},
{
key: 'resolved',
name: 'Resolved',
href: `/reports?reviewState=${encodeURIComponent(
ComAtprotoAdminDefs.REVIEWCLOSED,
ToolsOzoneModerationDefs.REVIEWCLOSED,
)}`,
},
{ key: 'all', name: 'All', href: '/reports' },
Expand Down Expand Up @@ -290,7 +290,7 @@ export const ReportsPageContent = () => {
subjectOptions={subjectOptions}
isInitialLoading={isInitialLoading}
onSubmit={async (
vals: ComAtprotoAdminEmitModerationEvent.InputSchema,
vals: ToolsOzoneModerationEmitEvent.InputSchema,
) => {
await emitEvent(vals)
refetch()
Expand All @@ -302,9 +302,9 @@ export const ReportsPageContent = () => {

function getTabFromParams({ reviewState }: { reviewState?: string | null }) {
const reviewStateMap = {
[ComAtprotoAdminDefs.REVIEWESCALATED]: 'escalated',
[ComAtprotoAdminDefs.REVIEWCLOSED]: 'resolved',
[ComAtprotoAdminDefs.REVIEWOPEN]: 'unresolved',
[ToolsOzoneModerationDefs.REVIEWESCALATED]: 'escalated',
[ToolsOzoneModerationDefs.REVIEWCLOSED]: 'resolved',
[ToolsOzoneModerationDefs.REVIEWOPEN]: 'unresolved',
}

if (reviewState) {
Expand All @@ -315,10 +315,10 @@ function getTabFromParams({ reviewState }: { reviewState?: string | null }) {
}

async function getModerationQueue(
opts: ComAtprotoAdminQueryModerationStatuses.QueryParams = {},
opts: ToolsOzoneModerationQueryStatuses.QueryParams = {},
queueName: string | null,
) {
const { data } = await client.api.com.atproto.admin.queryModerationStatuses(
const { data } = await client.api.tools.ozone.moderation.queryStatuses(
{
limit: 50,
includeMuted: true,
Expand Down
6 changes: 3 additions & 3 deletions app/repositories/[id]/[...record]/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useQuery } from '@tanstack/react-query'
import {
AppBskyFeedGetPostThread as GetPostThread,
ComAtprotoAdminEmitModerationEvent,
ToolsOzoneModerationEmitEvent,
} from '@atproto/api'
import { ReportPanel } from '@/reports/ReportPanel'
import { RecordView } from '@/repositories/RecordView'
Expand Down Expand Up @@ -75,7 +75,7 @@ export default function RecordViewPageContent({

const uri = createAtUri({ did, collection, rkey })
const getRecord = async () => {
const { data: record } = await client.api.com.atproto.admin.getRecord(
const { data: record } = await client.api.tools.ozone.moderation.getRecord(
{ uri },
{ headers: client.proxyHeaders() },
)
Expand Down Expand Up @@ -171,7 +171,7 @@ export default function RecordViewPageContent({
subjectOptions={[quickOpenParam]}
isInitialLoading={isInitialLoading}
onSubmit={async (
vals: ComAtprotoAdminEmitModerationEvent.InputSchema,
vals: ToolsOzoneModerationEmitEvent.InputSchema,
) => {
await emitEvent(vals)
refetch()
Expand Down
4 changes: 2 additions & 2 deletions app/repositories/[id]/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { AccountView } from '@/repositories/AccountView'
import { createReport } from '@/repositories/createReport'
import { useRepoAndProfile } from '@/repositories/useRepoAndProfile'
import { ComAtprotoAdminEmitModerationEvent } from '@atproto/api'
import { ToolsOzoneModerationEmitEvent } from '@atproto/api'
import { ModActionPanelQuick } from 'app/actions/ModActionPanel/QuickAction'
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { emitEvent } from '@/mod-event/helpers/emitEvent'
Expand Down Expand Up @@ -67,7 +67,7 @@ export function RepositoryViewPageContent({ id }: { id: string }) {
subjectOptions={[quickOpenParam]}
isInitialLoading={isInitialLoading}
onSubmit={async (
vals: ComAtprotoAdminEmitModerationEvent.InputSchema,
vals: ToolsOzoneModerationEmitEvent.InputSchema,
) => {
await emitEvent(vals)
refetch()
Expand Down
2 changes: 1 addition & 1 deletion app/repositories/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function RepositoriesListPage() {
const { data, fetchNextPage, hasNextPage } = useInfiniteQuery({
queryKey: ['repositories', { term }],
queryFn: async ({ pageParam }) => {
const { data } = await client.api.com.atproto.admin.searchRepos(
const { data } = await client.api.tools.ozone.moderation.searchRepos(
{
term,
limit: 25,
Expand Down
2 changes: 1 addition & 1 deletion app/subject-status/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function SubjectStatus() {
queryFn: async () => {
if (!subject) return null
const { data } =
await client.api.com.atproto.admin.queryModerationStatuses(
await client.api.tools.ozone.moderation.queryStatuses(
{ subject, limit: 1 },
{ headers: client.proxyHeaders() },
)
Expand Down
10 changes: 5 additions & 5 deletions components/common/RecordCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useQuery } from '@tanstack/react-query'
import { AppBskyFeedDefs, ComAtprotoAdminDefs } from '@atproto/api'
import { AppBskyFeedDefs, ToolsOzoneModerationDefs } from '@atproto/api'
import { buildBlueSkyAppUrl, parseAtUri } from '@/lib/util'
import client from '@/lib/client'
import { PostAsCard } from './posts/PostsFeed'
Expand Down Expand Up @@ -84,14 +84,14 @@ function PostCard(props: { uri: string; showLabels?: boolean }) {

function BaseRecordCard(props: {
uri: string
renderRecord: (record: ComAtprotoAdminDefs.RecordViewDetail) => JSX.Element
renderRecord: (record: ToolsOzoneModerationDefs.RecordViewDetail) => JSX.Element
}) {
const { uri, renderRecord } = props
const { data: record, error } = useQuery({
retry: false,
queryKey: ['recordCard', { uri }],
queryFn: async () => {
const { data } = await client.api.com.atproto.admin.getRecord(
const { data } = await client.api.tools.ozone.moderation.getRecord(
{ uri },
{ headers: client.proxyHeaders() },
)
Expand All @@ -118,7 +118,7 @@ function GenericRecordCard({
record,
did,
}: {
record: ComAtprotoAdminDefs.RecordViewDetail
record: ToolsOzoneModerationDefs.RecordViewDetail
did?: string
}) {
return (
Expand All @@ -138,7 +138,7 @@ const useRepoAndProfile = ({ did }: { did: string }) => {
queryFn: async () => {
// @TODO when unifying admin auth, ensure admin can see taken-down profiles
const getRepo = async () => {
const { data: repo } = await client.api.com.atproto.admin.getRepo(
const { data: repo } = await client.api.tools.ozone.moderation.getRepo(
{ did },
{ headers: client.proxyHeaders() },
)
Expand Down
Loading

0 comments on commit 4c83d5d

Please sign in to comment.