Protect ctrls from interacting with blocked user

This commit is contained in:
Eric Bailey
2024-08-30 12:05:58 -05:00
parent e090cc6a1a
commit 510c1404b6
@@ -89,6 +89,11 @@ let PostCtrls = ({
const {captureAction} = useProgressGuideControls() const {captureAction} = useProgressGuideControls()
const playHaptic = useHaptics() const playHaptic = useHaptics()
const gate = useGate() const gate = useGate()
const isBlocked = Boolean(
post.author.viewer?.blocking ||
post.author.viewer?.blockedBy ||
post.author.viewer?.blockingByList,
)
const shouldShowLoggedOutWarning = React.useMemo(() => { const shouldShowLoggedOutWarning = React.useMemo(() => {
return ( return (
@@ -105,6 +110,14 @@ let PostCtrls = ({
) as StyleProp<ViewStyle> ) as StyleProp<ViewStyle>
const onPressToggleLike = React.useCallback(async () => { const onPressToggleLike = React.useCallback(async () => {
if (isBlocked) {
Toast.show(
_(msg`Cannot interact with a blocked user`),
'exclamation-circle',
)
return
}
try { try {
if (!post.viewer?.like) { if (!post.viewer?.like) {
playHaptic() playHaptic()
@@ -124,6 +137,7 @@ let PostCtrls = ({
} }
} }
}, [ }, [
_,
playHaptic, playHaptic,
post.uri, post.uri,
post.viewer?.like, post.viewer?.like,
@@ -132,9 +146,18 @@ let PostCtrls = ({
sendInteraction, sendInteraction,
captureAction, captureAction,
feedContext, feedContext,
isBlocked,
]) ])
const onRepost = useCallback(async () => { const onRepost = useCallback(async () => {
if (isBlocked) {
Toast.show(
_(msg`Cannot interact with a blocked user`),
'exclamation-circle',
)
return
}
try { try {
if (!post.viewer?.repost) { if (!post.viewer?.repost) {
sendInteraction({ sendInteraction({
@@ -152,15 +175,25 @@ let PostCtrls = ({
} }
} }
}, [ }, [
_,
post.uri, post.uri,
post.viewer?.repost, post.viewer?.repost,
queueRepost, queueRepost,
queueUnrepost, queueUnrepost,
sendInteraction, sendInteraction,
feedContext, feedContext,
isBlocked,
]) ])
const onQuote = useCallback(() => { const onQuote = useCallback(() => {
if (isBlocked) {
Toast.show(
_(msg`Cannot interact with a blocked user`),
'exclamation-circle',
)
return
}
sendInteraction({ sendInteraction({
item: post.uri, item: post.uri,
event: 'app.bsky.feed.defs#interactionQuote', event: 'app.bsky.feed.defs#interactionQuote',
@@ -178,6 +211,7 @@ let PostCtrls = ({
onPost: onPostReply, onPost: onPostReply,
}) })
}, [ }, [
_,
sendInteraction, sendInteraction,
post.uri, post.uri,
post.cid, post.cid,
@@ -188,6 +222,7 @@ let PostCtrls = ({
openComposer, openComposer,
record.text, record.text,
onPostReply, onPostReply,
isBlocked,
]) ])
const onShare = useCallback(() => { const onShare = useCallback(() => {