From c60e8d0772d93fb3b0eca00b5fb1de9e110df320 Mon Sep 17 00:00:00 2001
From: Eric Bailey <git@esb.lol>
Date: Fri, 30 Aug 2024 12:26:40 -0500
Subject: Composer blocks (#5040)

* Move i18n provider up the stack

* Protect composer opening for a blocked post

* Protect ctrls from interacting with blocked user
---
 src/state/shell/composer.tsx | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

(limited to 'src/state/shell/composer.tsx')

diff --git a/src/state/shell/composer.tsx b/src/state/shell/composer.tsx
index c99005489..74802a993 100644
--- a/src/state/shell/composer.tsx
+++ b/src/state/shell/composer.tsx
@@ -5,8 +5,11 @@ import {
   AppBskyRichtextFacet,
   ModerationDecision,
 } from '@atproto/api'
+import {msg} from '@lingui/macro'
+import {useLingui} from '@lingui/react'
 
 import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
+import * as Toast from '#/view/com/util/Toast'
 
 export interface ComposerOptsPostRef {
   uri: string
@@ -22,12 +25,7 @@ export interface ComposerOptsQuote {
   text: string
   facets?: AppBskyRichtextFacet.Main[]
   indexedAt: string
-  author: {
-    did: string
-    handle: string
-    displayName?: string
-    avatar?: string
-  }
+  author: AppBskyActorDefs.ProfileViewBasic
   embeds?: AppBskyEmbedRecord.ViewRecord['embeds']
 }
 export interface ComposerOpts {
@@ -56,10 +54,25 @@ const controlsContext = React.createContext<ControlsContext>({
 })
 
 export function Provider({children}: React.PropsWithChildren<{}>) {
+  const {_} = useLingui()
   const [state, setState] = React.useState<StateContext>()
 
   const openComposer = useNonReactiveCallback((opts: ComposerOpts) => {
-    setState(opts)
+    const author = opts.replyTo?.author || opts.quote?.author
+    const isBlocked = Boolean(
+      author &&
+        (author.viewer?.blocking ||
+          author.viewer?.blockedBy ||
+          author.viewer?.blockingByList),
+    )
+    if (isBlocked) {
+      Toast.show(
+        _(msg`Cannot interact with a blocked user`),
+        'exclamation-circle',
+      )
+    } else {
+      setState(opts)
+    }
   })
 
   const closeComposer = useNonReactiveCallback(() => {
-- 
cgit 1.4.1

