about summary refs log tree commit diff
path: root/src/lib/moderation.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/moderation.ts')
-rw-r--r--src/lib/moderation.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/moderation.ts b/src/lib/moderation.ts
index 3c96deecb..59d88023b 100644
--- a/src/lib/moderation.ts
+++ b/src/lib/moderation.ts
@@ -1,6 +1,8 @@
+import React from 'react'
 import {
   AppBskyLabelerDefs,
   BskyAgent,
+  ComAtprotoLabelDefs,
   InterpretedLabelValueDefinition,
   LABELS,
   ModerationCause,
@@ -82,3 +84,34 @@ export function isLabelerSubscribed(
   }
   return modOpts.prefs.labelers.find(l => l.did === labeler)
 }
+
+export type Subject =
+  | {
+      uri: string
+      cid: string
+    }
+  | {
+      did: string
+    }
+
+export function useLabelSubject({label}: {label: ComAtprotoLabelDefs.Label}): {
+  subject: Subject
+} {
+  return React.useMemo(() => {
+    const {cid, uri} = label
+    if (cid) {
+      return {
+        subject: {
+          uri,
+          cid,
+        },
+      }
+    } else {
+      return {
+        subject: {
+          did: uri,
+        },
+      }
+    }
+  }, [label])
+}