about summary refs log tree commit diff
path: root/src/state/queries
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/queries')
-rw-r--r--src/state/queries/post-thread.ts5
-rw-r--r--src/state/queries/profile.ts80
2 files changed, 50 insertions, 35 deletions
diff --git a/src/state/queries/post-thread.ts b/src/state/queries/post-thread.ts
index 6e9cb28dd..28a466e38 100644
--- a/src/state/queries/post-thread.ts
+++ b/src/state/queries/post-thread.ts
@@ -34,7 +34,6 @@ export type ThreadPost = {
   record: AppBskyFeedPost.Record
   parent?: ThreadNode
   replies?: ThreadNode[]
-  viewer?: AppBskyFeedDefs.ViewerThreadState
   ctx: ThreadCtx
 }
 
@@ -188,7 +187,6 @@ function responseToThreadNodes(
               // do not show blocked posts in replies
               .filter(node => node.type !== 'blocked')
           : undefined,
-      viewer: node.viewer,
       ctx: {
         depth,
         isHighlightedPost: depth === 0,
@@ -276,7 +274,6 @@ function threadNodeToPlaceholderThread(
     record: node.record,
     parent: undefined,
     replies: undefined,
-    viewer: node.viewer,
     ctx: {
       depth: 0,
       isHighlightedPost: true,
@@ -300,7 +297,6 @@ function postViewToPlaceholderThread(
     record: post.record as AppBskyFeedPost.Record, // validated in notifs
     parent: undefined,
     replies: undefined,
-    viewer: post.viewer,
     ctx: {
       depth: 0,
       isHighlightedPost: true,
@@ -331,7 +327,6 @@ function embedViewRecordToPlaceholderThread(
     record: record.value as AppBskyFeedPost.Record, // validated in getEmbeddedPost
     parent: undefined,
     replies: undefined,
-    viewer: undefined, // not available
     ctx: {
       depth: 0,
       isHighlightedPost: true,
diff --git a/src/state/queries/profile.ts b/src/state/queries/profile.ts
index 21e519a0f..5fd0b4e34 100644
--- a/src/state/queries/profile.ts
+++ b/src/state/queries/profile.ts
@@ -49,18 +49,31 @@ export function useProfileQuery({did}: {did: string | undefined}) {
 
 interface ProfileUpdateParams {
   profile: AppBskyActorDefs.ProfileView
-  updates: AppBskyActorProfile.Record
-  newUserAvatar: RNImage | undefined | null
-  newUserBanner: RNImage | undefined | null
+  updates:
+    | AppBskyActorProfile.Record
+    | ((existing: AppBskyActorProfile.Record) => AppBskyActorProfile.Record)
+  newUserAvatar?: RNImage | undefined | null
+  newUserBanner?: RNImage | undefined | null
+  checkCommitted?: (res: AppBskyActorGetProfile.Response) => boolean
 }
 export function useProfileUpdateMutation() {
   const queryClient = useQueryClient()
   return useMutation<void, Error, ProfileUpdateParams>({
-    mutationFn: async ({profile, updates, newUserAvatar, newUserBanner}) => {
+    mutationFn: async ({
+      profile,
+      updates,
+      newUserAvatar,
+      newUserBanner,
+      checkCommitted,
+    }) => {
       await getAgent().upsertProfile(async existing => {
         existing = existing || {}
-        existing.displayName = updates.displayName
-        existing.description = updates.description
+        if (typeof updates === 'function') {
+          existing = updates(existing)
+        } else {
+          existing.displayName = updates.displayName
+          existing.description = updates.description
+        }
         if (newUserAvatar) {
           const res = await uploadBlob(
             getAgent(),
@@ -83,30 +96,37 @@ export function useProfileUpdateMutation() {
         }
         return existing
       })
-      await whenAppViewReady(profile.did, res => {
-        if (typeof newUserAvatar !== 'undefined') {
-          if (newUserAvatar === null && res.data.avatar) {
-            // url hasnt cleared yet
-            return false
-          } else if (res.data.avatar === profile.avatar) {
-            // url hasnt changed yet
-            return false
-          }
-        }
-        if (typeof newUserBanner !== 'undefined') {
-          if (newUserBanner === null && res.data.banner) {
-            // url hasnt cleared yet
-            return false
-          } else if (res.data.banner === profile.banner) {
-            // url hasnt changed yet
-            return false
-          }
-        }
-        return (
-          res.data.displayName === updates.displayName &&
-          res.data.description === updates.description
-        )
-      })
+      await whenAppViewReady(
+        profile.did,
+        checkCommitted ||
+          (res => {
+            if (typeof newUserAvatar !== 'undefined') {
+              if (newUserAvatar === null && res.data.avatar) {
+                // url hasnt cleared yet
+                return false
+              } else if (res.data.avatar === profile.avatar) {
+                // url hasnt changed yet
+                return false
+              }
+            }
+            if (typeof newUserBanner !== 'undefined') {
+              if (newUserBanner === null && res.data.banner) {
+                // url hasnt cleared yet
+                return false
+              } else if (res.data.banner === profile.banner) {
+                // url hasnt changed yet
+                return false
+              }
+            }
+            if (typeof updates === 'function') {
+              return true
+            }
+            return (
+              res.data.displayName === updates.displayName &&
+              res.data.description === updates.description
+            )
+          }),
+      )
     },
     onSuccess(data, variables) {
       // invalidate cache