about summary refs log tree commit diff
path: root/src/components/dms/util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/dms/util.ts')
-rw-r--r--src/components/dms/util.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/components/dms/util.ts b/src/components/dms/util.ts
new file mode 100644
index 000000000..5952b9acf
--- /dev/null
+++ b/src/components/dms/util.ts
@@ -0,0 +1,18 @@
+import {AppBskyActorDefs} from '@atproto/api'
+
+export function canBeMessaged(profile: AppBskyActorDefs.ProfileView) {
+  switch (profile.associated?.chat?.allowIncoming) {
+    case 'none':
+      return false
+    case 'all':
+      return true
+    // if unset, treat as following
+    case 'following':
+    case undefined:
+      return Boolean(profile.viewer?.followedBy)
+    // any other values are invalid according to the lexicon, so
+    // let's treat as false to be safe
+    default:
+      return false
+  }
+}