about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/api/hack-add-deleted-embed.ts24
-rw-r--r--src/lib/moderation.ts77
-rw-r--r--src/lib/strings/display-names.ts11
3 files changed, 111 insertions, 1 deletions
diff --git a/src/lib/api/hack-add-deleted-embed.ts b/src/lib/api/hack-add-deleted-embed.ts
new file mode 100644
index 000000000..59aad21a2
--- /dev/null
+++ b/src/lib/api/hack-add-deleted-embed.ts
@@ -0,0 +1,24 @@
+import {
+  AppBskyFeedDefs,
+  AppBskyFeedPost,
+  ComAtprotoRepoStrongRef,
+} from '@atproto/api'
+
+/**
+ * HACK
+ * The server doesnt seem to be correctly giving the notFound view yet
+ * so I'm adding it manually for now
+ * -prf
+ */
+export function hackAddDeletedEmbed(post: AppBskyFeedDefs.PostView) {
+  const record = post.record as AppBskyFeedPost.Record
+  if (record.embed?.$type === 'app.bsky.embed.record' && !post.embed) {
+    post.embed = {
+      $type: 'app.bsky.embed.record#view',
+      record: {
+        $type: 'app.bsky.embed.record#viewNotFound',
+        uri: (record.embed.record as ComAtprotoRepoStrongRef.Main).uri,
+      },
+    }
+  }
+}
diff --git a/src/lib/moderation.ts b/src/lib/moderation.ts
new file mode 100644
index 000000000..758e3de3a
--- /dev/null
+++ b/src/lib/moderation.ts
@@ -0,0 +1,77 @@
+import {ModerationCause, ProfileModeration} from '@atproto/api'
+
+export interface ModerationCauseDescription {
+  name: string
+  description: string
+}
+
+export function describeModerationCause(
+  cause: ModerationCause | undefined,
+  context: 'account' | 'content',
+): ModerationCauseDescription {
+  if (!cause) {
+    return {
+      name: 'Content Warning',
+      description:
+        'Moderator has chosen to set a general warning on the content.',
+    }
+  }
+  if (cause.type === 'blocking') {
+    return {
+      name: 'Blocked User',
+      description: 'You have blocked this user. You cannot view their content.',
+    }
+  }
+  if (cause.type === 'blocked-by') {
+    return {
+      name: 'Blocking You',
+      description: 'This user has blocked you. You cannot view their content.',
+    }
+  }
+  if (cause.type === 'muted') {
+    if (cause.source.type === 'user') {
+      return {
+        name: context === 'account' ? 'Muted User' : 'Post by muted user',
+        description: 'You have muted this user',
+      }
+    } else {
+      return {
+        name:
+          context === 'account'
+            ? `Muted by "${cause.source.list.name}"`
+            : `Post by muted user ("${cause.source.list.name}")`,
+        description: 'You have muted this user',
+      }
+    }
+  }
+  return cause.labelDef.strings[context].en
+}
+
+export function getProfileModerationCauses(
+  moderation: ProfileModeration,
+): ModerationCause[] {
+  /*
+  Gather everything on profile and account that blurs or alerts
+  */
+  return [
+    moderation.decisions.profile.cause,
+    ...moderation.decisions.profile.additionalCauses,
+    moderation.decisions.account.cause,
+    ...moderation.decisions.account.additionalCauses,
+  ].filter(cause => {
+    if (!cause) {
+      return false
+    }
+    if (cause?.type === 'label') {
+      if (
+        cause.labelDef.onwarn === 'blur' ||
+        cause.labelDef.onwarn === 'alert'
+      ) {
+        return true
+      } else {
+        return false
+      }
+    }
+    return true
+  }) as ModerationCause[]
+}
diff --git a/src/lib/strings/display-names.ts b/src/lib/strings/display-names.ts
index b98153732..29b7c3b50 100644
--- a/src/lib/strings/display-names.ts
+++ b/src/lib/strings/display-names.ts
@@ -1,10 +1,19 @@
+import {ModerationUI} from '@atproto/api'
+import {describeModerationCause} from '../moderation'
+
 // \u2705 = ✅
 // \u2713 = ✓
 // \u2714 = ✔
 // \u2611 = ☑
 const CHECK_MARKS_RE = /[\u2705\u2713\u2714\u2611]/gu
 
-export function sanitizeDisplayName(str: string): string {
+export function sanitizeDisplayName(
+  str: string,
+  moderation?: ModerationUI,
+): string {
+  if (moderation?.blur) {
+    return `⚠${describeModerationCause(moderation.cause, 'account').name}`
+  }
   if (typeof str === 'string') {
     return str.replace(CHECK_MARKS_RE, '').trim()
   }