Composer blocks (#5040)

* Move i18n provider up the stack

* Protect composer opening for a blocked post

* Protect ctrls from interacting with blocked user
This commit is contained in:
Eric Bailey 2024-08-30 12:26:40 -05:00 committed by GitHub
parent dbbbba1d32
commit c60e8d0772
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 93 additions and 45 deletions

View file

@ -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(() => {