my fork of the bluesky client

Add ability to block account from post dropdown menu (#6091)

Co-authored-by: Hailey <me@haileyok.com>
Co-authored-by: Hailey <hailey@blueskyweb.xyz>

authored by

rshigg
Hailey
Hailey
and committed by
GitHub
ced67876 247bc100

+49 -9
+1 -1
src/state/queries/profile.ts
··· 409 409 } 410 410 411 411 export function useProfileBlockMutationQueue( 412 - profile: Shadow<AppBskyActorDefs.ProfileViewDetailed>, 412 + profile: Shadow<AppBskyActorDefs.ProfileViewBasic>, 413 413 ) { 414 414 const queryClient = useQueryClient() 415 415 const did = profile.did
+48 -8
src/view/com/util/forms/PostDropdownBtnMenuItems.tsx
··· 29 29 import {logger} from '#/logger' 30 30 import {isWeb} from '#/platform/detection' 31 31 import {Shadow} from '#/state/cache/post-shadow' 32 + import {useProfileShadow} from '#/state/cache/profile-shadow' 32 33 import {useFeedFeedbackContext} from '#/state/feed-feedback' 33 34 import {useLanguagePrefs} from '#/state/preferences' 34 35 import {useHiddenPosts, useHiddenPostsApi} from '#/state/preferences' ··· 39 40 } from '#/state/queries/post' 40 41 import {useToggleQuoteDetachmentMutation} from '#/state/queries/postgate' 41 42 import {getMaybeDetachedQuoteEmbed} from '#/state/queries/postgate/util' 43 + import {useProfileBlockMutationQueue} from '#/state/queries/profile' 42 44 import {useToggleReplyVisibilityMutation} from '#/state/queries/threadgate' 43 45 import {useSession} from '#/state/session' 44 46 import {useMergedThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies' ··· 64 66 import {Filter_Stroke2_Corner0_Rounded as Filter} from '#/components/icons/Filter' 65 67 import {Mute_Stroke2_Corner0_Rounded as Mute} from '#/components/icons/Mute' 66 68 import {PaperPlane_Stroke2_Corner0_Rounded as Send} from '#/components/icons/PaperPlane' 69 + import {PersonX_Stroke2_Corner0_Rounded as PersonX} from '#/components/icons/Person' 67 70 import {Pin_Stroke2_Corner0_Rounded as PinIcon} from '#/components/icons/Pin' 68 71 import {SettingsGear2_Stroke2_Corner0_Rounded as Gear} from '#/components/icons/SettingsGear2' 69 72 import {SpeakerVolumeFull_Stroke2_Corner0_Rounded as Unmute} from '#/components/icons/Speaker' ··· 107 110 const openLink = useOpenLink() 108 111 const navigation = useNavigation<NavigationProp>() 109 112 const {mutedWordsDialogControl} = useGlobalDialogsControlContext() 113 + const blockPromptControl = useDialogControl() 110 114 const reportDialogControl = useReportDialogControl() 111 115 const deletePromptControl = useDialogControl() 112 116 const hidePromptControl = useDialogControl() ··· 121 125 122 126 const postUri = post.uri 123 127 const postCid = post.cid 124 - const postAuthor = post.author 128 + const postAuthor = useProfileShadow(post.author) 125 129 const quoteEmbed = React.useMemo(() => { 126 130 if (!currentAccount || !post.embed) return 127 131 return getMaybeDetachedQuoteEmbed({ ··· 147 151 148 152 const {mutateAsync: toggleQuoteDetachment, isPending: isDetachPending} = 149 153 useToggleQuoteDetachmentMutation() 154 + 155 + const [queueBlock] = useProfileBlockMutationQueue(postAuthor) 150 156 151 157 const prefetchPostInteractionSettings = usePrefetchPostInteractionSettings({ 152 158 postUri: post.uri, ··· 348 354 }) 349 355 }, [isPinned, pinPostMutate, postCid, postUri]) 350 356 357 + const onBlockAuthor = useCallback(async () => { 358 + try { 359 + await queueBlock() 360 + Toast.show(_(msg`Account blocked`)) 361 + } catch (e: any) { 362 + if (e?.name !== 'AbortError') { 363 + logger.error('Failed to block account', {message: e}) 364 + Toast.show(_(msg`There was an issue! ${e.toString()}`), 'xmark') 365 + } 366 + } 367 + }, [_, queueBlock]) 368 + 351 369 return ( 352 370 <> 353 371 <Menu.Outer> ··· 578 596 <Menu.Divider /> 579 597 <Menu.Group> 580 598 {!isAuthor && ( 581 - <Menu.Item 582 - testID="postDropdownReportBtn" 583 - label={_(msg`Report post`)} 584 - onPress={() => reportDialogControl.open()}> 585 - <Menu.ItemText>{_(msg`Report post`)}</Menu.ItemText> 586 - <Menu.ItemIcon icon={Warning} position="right" /> 587 - </Menu.Item> 599 + <> 600 + {!postAuthor.viewer?.blocking && ( 601 + <Menu.Item 602 + testID="postDropdownBlockBtn" 603 + label={_(msg`Block account`)} 604 + onPress={() => blockPromptControl.open()}> 605 + <Menu.ItemText>{_(msg`Block account`)}</Menu.ItemText> 606 + <Menu.ItemIcon icon={PersonX} position="right" /> 607 + </Menu.Item> 608 + )} 609 + <Menu.Item 610 + testID="postDropdownReportBtn" 611 + label={_(msg`Report post`)} 612 + onPress={() => reportDialogControl.open()}> 613 + <Menu.ItemText>{_(msg`Report post`)}</Menu.ItemText> 614 + <Menu.ItemIcon icon={Warning} position="right" /> 615 + </Menu.Item> 616 + </> 588 617 )} 589 618 590 619 {isAuthor && ( ··· 703 732 )} 704 733 onConfirm={onToggleReplyVisibility} 705 734 confirmButtonCta={_(msg`Yes, hide`)} 735 + /> 736 + 737 + <Prompt.Basic 738 + control={blockPromptControl} 739 + title={_(msg`Block Account?`)} 740 + description={_( 741 + msg`Blocked accounts cannot reply in your threads, mention you, or otherwise interact with you.`, 742 + )} 743 + onConfirm={onBlockAuthor} 744 + confirmButtonCta={_(msg`Block`)} 745 + confirmButtonColor="negative" 706 746 /> 707 747 </> 708 748 )