Protect composer opening for a blocked post
This commit is contained in:
@@ -5,8 +5,11 @@ import {
|
|||||||
AppBskyRichtextFacet,
|
AppBskyRichtextFacet,
|
||||||
ModerationDecision,
|
ModerationDecision,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
|
import {msg} from '@lingui/macro'
|
||||||
|
import {useLingui} from '@lingui/react'
|
||||||
|
|
||||||
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
|
||||||
|
import * as Toast from '#/view/com/util/Toast'
|
||||||
|
|
||||||
export interface ComposerOptsPostRef {
|
export interface ComposerOptsPostRef {
|
||||||
uri: string
|
uri: string
|
||||||
@@ -22,12 +25,7 @@ export interface ComposerOptsQuote {
|
|||||||
text: string
|
text: string
|
||||||
facets?: AppBskyRichtextFacet.Main[]
|
facets?: AppBskyRichtextFacet.Main[]
|
||||||
indexedAt: string
|
indexedAt: string
|
||||||
author: {
|
author: AppBskyActorDefs.ProfileViewBasic
|
||||||
did: string
|
|
||||||
handle: string
|
|
||||||
displayName?: string
|
|
||||||
avatar?: string
|
|
||||||
}
|
|
||||||
embeds?: AppBskyEmbedRecord.ViewRecord['embeds']
|
embeds?: AppBskyEmbedRecord.ViewRecord['embeds']
|
||||||
}
|
}
|
||||||
export interface ComposerOpts {
|
export interface ComposerOpts {
|
||||||
@@ -56,10 +54,25 @@ const controlsContext = React.createContext<ControlsContext>({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
|
const {_} = useLingui()
|
||||||
const [state, setState] = React.useState<StateContext>()
|
const [state, setState] = React.useState<StateContext>()
|
||||||
|
|
||||||
const openComposer = useNonReactiveCallback((opts: ComposerOpts) => {
|
const openComposer = useNonReactiveCallback((opts: ComposerOpts) => {
|
||||||
|
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)
|
setState(opts)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const closeComposer = useNonReactiveCallback(() => {
|
const closeComposer = useNonReactiveCallback(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user