From 47b0d36b7393442857d3f4cfafd88c43defe6b6c Mon Sep 17 00:00:00 2001
From: Eric Bailey <git@esb.lol>
Date: Thu, 30 Nov 2023 15:40:01 -0600
Subject: [PATCH] Hide normal mute if muted by list, and invalidate profile
 query upon list mute (#2048)

* Hide normal mute if muted by list, and invalidate profile query upon list mute

* Prevent profile flashing
---
 src/view/com/profile/ProfileHeader.tsx | 46 +++++++++++++++++---------
 src/view/screens/Profile.tsx           |  6 ++--
 2 files changed, 33 insertions(+), 19 deletions(-)

diff --git a/src/view/com/profile/ProfileHeader.tsx b/src/view/com/profile/ProfileHeader.tsx
index 30446fba..ca71e8eb 100644
--- a/src/view/com/profile/ProfileHeader.tsx
+++ b/src/view/com/profile/ProfileHeader.tsx
@@ -7,6 +7,7 @@ import {
 } from 'react-native'
 import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
 import {useNavigation} from '@react-navigation/native'
+import {useQueryClient} from '@tanstack/react-query'
 import {
   AppBskyActorDefs,
   ProfileModeration,
@@ -32,6 +33,7 @@ import {ProfileHeaderSuggestedFollows} from './ProfileHeaderSuggestedFollows'
 import {useModalControls} from '#/state/modals'
 import {useLightboxControls, ProfileImageLightbox} from '#/state/lightbox'
 import {
+  RQKEY as profileQueryKey,
   useProfileMuteMutationQueue,
   useProfileBlockMutationQueue,
   useProfileFollowMutationQueue,
@@ -134,6 +136,13 @@ let ProfileHeaderLoaded = ({
   const [queueFollow, queueUnfollow] = useProfileFollowMutationQueue(profile)
   const [queueMute, queueUnmute] = useProfileMuteMutationQueue(profile)
   const [queueBlock, queueUnblock] = useProfileBlockMutationQueue(profile)
+  const queryClient = useQueryClient()
+
+  const invalidateProfileQuery = React.useCallback(() => {
+    queryClient.invalidateQueries({
+      queryKey: profileQueryKey(profile.did),
+    })
+  }, [queryClient, profile.did])
 
   const onPressBack = React.useCallback(() => {
     if (navigation.canGoBack()) {
@@ -209,8 +218,10 @@ let ProfileHeaderLoaded = ({
       name: 'user-add-remove-lists',
       subject: profile.did,
       displayName: profile.displayName || profile.handle,
+      onAdd: invalidateProfileQuery,
+      onRemove: invalidateProfileQuery,
     })
-  }, [track, profile, openModal])
+  }, [track, profile, openModal, invalidateProfileQuery])
 
   const onPressMuteAccount = React.useCallback(async () => {
     track('ProfileHeader:MuteAccountButtonClicked')
@@ -325,22 +336,24 @@ let ProfileHeaderLoaded = ({
       })
       if (!isMe) {
         if (!profile.viewer?.blocking) {
-          items.push({
-            testID: 'profileHeaderDropdownMuteBtn',
-            label: profile.viewer?.muted
-              ? _(msg`Unmute Account`)
-              : _(msg`Mute Account`),
-            onPress: profile.viewer?.muted
-              ? onPressUnmuteAccount
-              : onPressMuteAccount,
-            icon: {
-              ios: {
-                name: 'speaker.slash',
+          if (!profile.viewer?.mutedByList) {
+            items.push({
+              testID: 'profileHeaderDropdownMuteBtn',
+              label: profile.viewer?.muted
+                ? _(msg`Unmute Account`)
+                : _(msg`Mute Account`),
+              onPress: profile.viewer?.muted
+                ? onPressUnmuteAccount
+                : onPressMuteAccount,
+              icon: {
+                ios: {
+                  name: 'speaker.slash',
+                },
+                android: 'ic_lock_silent_mode',
+                web: 'comment-slash',
               },
-              android: 'ic_lock_silent_mode',
-              web: 'comment-slash',
-            },
-          })
+            })
+          }
         }
         if (!profile.viewer?.blockingByList) {
           items.push({
@@ -379,6 +392,7 @@ let ProfileHeaderLoaded = ({
     isMe,
     hasSession,
     profile.viewer?.muted,
+    profile.viewer?.mutedByList,
     profile.viewer?.blocking,
     profile.viewer?.blockingByList,
     onPressShare,
diff --git a/src/view/screens/Profile.tsx b/src/view/screens/Profile.tsx
index 3e9a5992..8b4107ac 100644
--- a/src/view/screens/Profile.tsx
+++ b/src/view/screens/Profile.tsx
@@ -50,13 +50,13 @@ export function ProfileScreen({route}: Props) {
     data: resolvedDid,
     error: resolveError,
     refetch: refetchDid,
-    isFetching: isFetchingDid,
+    isInitialLoading: isInitialLoadingDid,
   } = useResolveDidQuery(name)
   const {
     data: profile,
     error: profileError,
     refetch: refetchProfile,
-    isFetching: isFetchingProfile,
+    isInitialLoading: isInitialLoadingProfile,
   } = useProfileQuery({
     did: resolvedDid,
   })
@@ -69,7 +69,7 @@ export function ProfileScreen({route}: Props) {
     }
   }, [resolveError, refetchDid, refetchProfile])
 
-  if (isFetchingDid || isFetchingProfile || !moderationOpts) {
+  if (isInitialLoadingDid || isInitialLoadingProfile || !moderationOpts) {
     return (
       <CenteredView>
         <ProfileHeader