about summary refs log tree commit diff
path: root/src/components/moderation/ReportDialog/action.ts
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2025-02-28 17:14:02 -0600
committerGitHub <noreply@github.com>2025-02-28 17:14:02 -0600
commit3be9dde92d64ec540a9097f369d64580fae75fa0 (patch)
tree49fa640a660af26a51ffa9b3aab2d1b169210048 /src/components/moderation/ReportDialog/action.ts
parent96f4f6359add6a4f2a37df8f17cf3f2f59f0a2a6 (diff)
downloadvoidsky-3be9dde92d64ec540a9097f369d64580fae75fa0.tar.zst
New reporting flow (#7832)
* Add option to align web dialogs to top

* Add new wait util

* Pipe through feed view to feed components

* Reset unneeded change to main

* Copy over fresh report dialog based on old

* Hack in temp testing data

* Swap in new dialog in all cases but chat

* Cleanup

* Add load and initial error state

* Fill in states

* Add copyright link

* Handle single labeler case

* Comment out debug code

* Improve centering of type in circles

* Open details if Other is selected

* Remove debug code

* Tweak colors

* Bump SDK

* Tweak Admonition for better x-platform styles

* Add retry button

* Add close button

* Remove todo not covered in this PR

* Translate Retry
Diffstat (limited to 'src/components/moderation/ReportDialog/action.ts')
-rw-r--r--src/components/moderation/ReportDialog/action.ts99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/components/moderation/ReportDialog/action.ts b/src/components/moderation/ReportDialog/action.ts
new file mode 100644
index 000000000..fde2c7898
--- /dev/null
+++ b/src/components/moderation/ReportDialog/action.ts
@@ -0,0 +1,99 @@
+import {
+  $Typed,
+  ChatBskyConvoDefs,
+  ComAtprotoModerationCreateReport,
+} from '@atproto/api'
+import {msg} from '@lingui/macro'
+import {useLingui} from '@lingui/react'
+import {useMutation} from '@tanstack/react-query'
+
+import {logger} from '#/logger'
+import {useAgent} from '#/state/session'
+import {ReportState} from './state'
+import {ParsedReportSubject} from './types'
+
+export function useSubmitReportMutation() {
+  const {_} = useLingui()
+  const agent = useAgent()
+
+  return useMutation({
+    async mutationFn({
+      subject,
+      state,
+    }: {
+      subject: ParsedReportSubject
+      state: ReportState
+    }) {
+      if (!state.selectedOption) {
+        throw new Error(_(msg`Please select a reason for this report`))
+      }
+      if (!state.selectedLabeler) {
+        throw new Error(_(msg`Please select a moderation service`))
+      }
+
+      let report:
+        | ComAtprotoModerationCreateReport.InputSchema
+        | (Omit<ComAtprotoModerationCreateReport.InputSchema, 'subject'> & {
+            subject: $Typed<ChatBskyConvoDefs.MessageRef>
+          })
+
+      switch (subject.type) {
+        case 'account': {
+          report = {
+            reasonType: state.selectedOption.reason,
+            reason: state.details,
+            subject: {
+              $type: 'com.atproto.admin.defs#repoRef',
+              did: subject.did,
+            },
+          }
+          break
+        }
+        case 'post':
+        case 'list':
+        case 'feed':
+        case 'starterPack': {
+          report = {
+            reasonType: state.selectedOption.reason,
+            reason: state.details,
+            subject: {
+              $type: 'com.atproto.repo.strongRef',
+              uri: subject.uri,
+              cid: subject.cid,
+            },
+          }
+          break
+        }
+        case 'chatMessage': {
+          report = {
+            reasonType: state.selectedOption.reason,
+            reason: state.details,
+            subject: {
+              $type: 'chat.bsky.convo.defs#messageRef',
+              messageId: subject.message.id,
+              convoId: subject.convoId,
+              did: subject.message.sender.did,
+            },
+          }
+          break
+        }
+      }
+
+      if (__DEV__) {
+        logger.info('Submitting report', {
+          labeler: {
+            handle: state.selectedLabeler.creator.handle,
+          },
+          report,
+        })
+      } else {
+        await agent.createModerationReport(report, {
+          encoding: 'application/json',
+          headers: {
+            'atproto-proxy': `${state.selectedLabeler.creator.did}#atproto_labeler`,
+          },
+        })
+      }
+    },
+  })
+}