about summary refs log tree commit diff
path: root/src/components/moderation/ReportDialog/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/moderation/ReportDialog/utils')
-rw-r--r--src/components/moderation/ReportDialog/utils/parseReportSubject.ts91
-rw-r--r--src/components/moderation/ReportDialog/utils/useReportOptions.ts121
2 files changed, 212 insertions, 0 deletions
diff --git a/src/components/moderation/ReportDialog/utils/parseReportSubject.ts b/src/components/moderation/ReportDialog/utils/parseReportSubject.ts
new file mode 100644
index 000000000..b79e49695
--- /dev/null
+++ b/src/components/moderation/ReportDialog/utils/parseReportSubject.ts
@@ -0,0 +1,91 @@
+import {
+  AppBskyActorDefs,
+  AppBskyFeedDefs,
+  AppBskyFeedPost,
+  AppBskyGraphDefs,
+} from '@atproto/api'
+
+import {
+  ParsedReportSubject,
+  ReportSubject,
+} from '#/components/moderation/ReportDialog/types'
+import * as bsky from '#/types/bsky'
+
+export function parseReportSubject(
+  subject: ReportSubject,
+): ParsedReportSubject | undefined {
+  if (!subject) return
+
+  if ('convoId' in subject) {
+    return {
+      type: 'chatMessage',
+      ...subject,
+    }
+  }
+
+  if (
+    AppBskyActorDefs.isProfileViewBasic(subject) ||
+    AppBskyActorDefs.isProfileView(subject) ||
+    AppBskyActorDefs.isProfileViewDetailed(subject)
+  ) {
+    return {
+      type: 'account',
+      did: subject.did,
+      nsid: 'app.bsky.actor.profile',
+    }
+  } else if (AppBskyGraphDefs.isListView(subject)) {
+    return {
+      type: 'list',
+      uri: subject.uri,
+      cid: subject.cid,
+      nsid: 'app.bsky.graph.list',
+    }
+  } else if (AppBskyFeedDefs.isGeneratorView(subject)) {
+    return {
+      type: 'feed',
+      uri: subject.uri,
+      cid: subject.cid,
+      nsid: 'app.bsky.feed.generator',
+    }
+  } else if (AppBskyGraphDefs.isStarterPackView(subject)) {
+    return {
+      type: 'starterPack',
+      uri: subject.uri,
+      cid: subject.cid,
+      nsid: 'app.bsky.graph.starterPack',
+    }
+  } else if (AppBskyFeedDefs.isPostView(subject)) {
+    const record = subject.record
+    const embed = bsky.post.parseEmbed(subject.embed)
+    if (
+      bsky.dangerousIsType<AppBskyFeedPost.Record>(
+        record,
+        AppBskyFeedPost.isRecord,
+      )
+    ) {
+      return {
+        type: 'post',
+        uri: subject.uri,
+        cid: subject.cid,
+        nsid: 'app.bsky.feed.post',
+        attributes: {
+          reply: !!record.reply,
+          image:
+            embed.type === 'images' ||
+            (embed.type === 'post_with_media' && embed.media.type === 'images'),
+          video:
+            embed.type === 'video' ||
+            (embed.type === 'post_with_media' && embed.media.type === 'video'),
+          link:
+            embed.type === 'link' ||
+            (embed.type === 'post_with_media' && embed.media.type === 'link'),
+          quote:
+            embed.type === 'post' ||
+            (embed.type === 'post_with_media' &&
+              (embed.view.type === 'post' ||
+                embed.view.type === 'post_with_media')),
+        },
+      }
+    }
+  }
+}
diff --git a/src/components/moderation/ReportDialog/utils/useReportOptions.ts b/src/components/moderation/ReportDialog/utils/useReportOptions.ts
new file mode 100644
index 000000000..38888d51a
--- /dev/null
+++ b/src/components/moderation/ReportDialog/utils/useReportOptions.ts
@@ -0,0 +1,121 @@
+import {useMemo} from 'react'
+import {ComAtprotoModerationDefs} from '@atproto/api'
+import {msg} from '@lingui/macro'
+import {useLingui} from '@lingui/react'
+
+export interface ReportOption {
+  reason: string
+  title: string
+  description: string
+}
+
+interface ReportOptions {
+  account: ReportOption[]
+  post: ReportOption[]
+  list: ReportOption[]
+  starterPack: ReportOption[]
+  feed: ReportOption[]
+  chatMessage: ReportOption[]
+}
+
+export function useReportOptions(): ReportOptions {
+  const {_} = useLingui()
+
+  return useMemo(() => {
+    const other = {
+      reason: ComAtprotoModerationDefs.REASONOTHER,
+      title: _(msg`Other`),
+      description: _(msg`An issue not included in these options`),
+    }
+    const common = [
+      {
+        reason: ComAtprotoModerationDefs.REASONRUDE,
+        title: _(msg`Anti-Social Behavior`),
+        description: _(msg`Harassment, trolling, or intolerance`),
+      },
+      {
+        reason: ComAtprotoModerationDefs.REASONVIOLATION,
+        title: _(msg`Illegal and Urgent`),
+        description: _(msg`Glaring violations of law or terms of service`),
+      },
+      other,
+    ]
+    return {
+      account: [
+        {
+          reason: ComAtprotoModerationDefs.REASONMISLEADING,
+          title: _(msg`Misleading Account`),
+          description: _(
+            msg`Impersonation or false claims about identity or affiliation`,
+          ),
+        },
+        {
+          reason: ComAtprotoModerationDefs.REASONSPAM,
+          title: _(msg`Frequently Posts Unwanted Content`),
+          description: _(msg`Spam; excessive mentions or replies`),
+        },
+        {
+          reason: ComAtprotoModerationDefs.REASONVIOLATION,
+          title: _(msg`Name or Description Violates Community Standards`),
+          description: _(msg`Terms used violate community standards`),
+        },
+        other,
+      ],
+      post: [
+        {
+          reason: ComAtprotoModerationDefs.REASONMISLEADING,
+          title: _(msg`Misleading Post`),
+          description: _(msg`Impersonation, misinformation, or false claims`),
+        },
+        {
+          reason: ComAtprotoModerationDefs.REASONSPAM,
+          title: _(msg`Spam`),
+          description: _(msg`Excessive mentions or replies`),
+        },
+        {
+          reason: ComAtprotoModerationDefs.REASONSEXUAL,
+          title: _(msg`Unwanted Sexual Content`),
+          description: _(msg`Nudity or adult content not labeled as such`),
+        },
+        ...common,
+      ],
+      chatMessage: [
+        {
+          reason: ComAtprotoModerationDefs.REASONSPAM,
+          title: _(msg`Spam`),
+          description: _(msg`Excessive or unwanted messages`),
+        },
+        {
+          reason: ComAtprotoModerationDefs.REASONSEXUAL,
+          title: _(msg`Unwanted Sexual Content`),
+          description: _(msg`Inappropriate messages or explicit links`),
+        },
+        ...common,
+      ],
+      list: [
+        {
+          reason: ComAtprotoModerationDefs.REASONVIOLATION,
+          title: _(msg`Name or Description Violates Community Standards`),
+          description: _(msg`Terms used violate community standards`),
+        },
+        ...common,
+      ],
+      starterPack: [
+        {
+          reason: ComAtprotoModerationDefs.REASONVIOLATION,
+          title: _(msg`Name or Description Violates Community Standards`),
+          description: _(msg`Terms used violate community standards`),
+        },
+        ...common,
+      ],
+      feed: [
+        {
+          reason: ComAtprotoModerationDefs.REASONVIOLATION,
+          title: _(msg`Name or Description Violates Community Standards`),
+          description: _(msg`Terms used violate community standards`),
+        },
+        ...common,
+      ],
+    }
+  }, [_])
+}