APP-2977: Handle AppView polling errors (#11590)
This commit is contained in:
@@ -152,9 +152,9 @@ export function useListMetadataMutation() {
|
||||
|
||||
// wait for the appview to update
|
||||
await whenAppViewReady(appviewClient, res.uri, v => {
|
||||
const list = v.list
|
||||
const list = v?.list
|
||||
return (
|
||||
list.name === record.name && list.description === record.description
|
||||
list?.name === record.name && list.description === record.description
|
||||
)
|
||||
})
|
||||
return res
|
||||
@@ -228,14 +228,10 @@ export function useListDeleteMutation() {
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait for the appview to update. Once the list is deleted `getList`
|
||||
* throws, `until` catches it and passes `undefined` here, so an absent
|
||||
* body signals a completed delete - the old check read `!v.success` on
|
||||
* the legacy response envelope, which lex does not expose.
|
||||
* Once the deletion is indexed, `getList` throws and `until` passes the
|
||||
* error to this predicate with an undefined response.
|
||||
*/
|
||||
await whenAppViewReady(appviewClient, uri, v => {
|
||||
return !v
|
||||
})
|
||||
await whenAppViewReady(appviewClient, uri, v => !v)
|
||||
},
|
||||
onSuccess() {
|
||||
invalidateMyLists(queryClient)
|
||||
@@ -299,7 +295,10 @@ export function useListBlockMutation() {
|
||||
async function whenAppViewReady(
|
||||
client: Client,
|
||||
uri: string,
|
||||
fn: (res: app.bsky.graph.getList.$OutputBody) => boolean,
|
||||
fn: (
|
||||
res: app.bsky.graph.getList.$OutputBody | undefined,
|
||||
err: unknown,
|
||||
) => boolean,
|
||||
) {
|
||||
await until(
|
||||
5, // 5 tries
|
||||
|
||||
@@ -79,10 +79,12 @@ export function usePinnedPostMutation() {
|
||||
: undefined
|
||||
return existing
|
||||
},
|
||||
checkCommitted: profile =>
|
||||
pinCurrentPost
|
||||
checkCommitted: profile => {
|
||||
if (!profile) return false
|
||||
return pinCurrentPost
|
||||
? profile.pinnedPost?.uri === postUri
|
||||
: !profile.pinnedPost,
|
||||
: !profile.pinnedPost
|
||||
},
|
||||
})
|
||||
|
||||
if (pinCurrentPost) {
|
||||
|
||||
@@ -146,7 +146,10 @@ interface ProfileUpdateParams {
|
||||
) => Un$Typed<app.bsky.actor.profile.Main>)
|
||||
newUserAvatar?: ImageMeta | undefined | null
|
||||
newUserBanner?: ImageMeta | undefined | null
|
||||
checkCommitted?: (profile: app.bsky.actor.getProfile.$OutputBody) => boolean
|
||||
checkCommitted?: (
|
||||
profile: app.bsky.actor.getProfile.$OutputBody | undefined,
|
||||
err: unknown,
|
||||
) => boolean
|
||||
}
|
||||
export function useProfileUpdateMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
@@ -207,6 +210,7 @@ export function useProfileUpdateMutation() {
|
||||
profile.did,
|
||||
checkCommitted ||
|
||||
(fresh => {
|
||||
if (!fresh) return false
|
||||
if (typeof newUserAvatar !== 'undefined') {
|
||||
if (newUserAvatar === null && fresh.avatar) {
|
||||
// url hasn't cleared yet
|
||||
@@ -678,7 +682,10 @@ function useProfileUnblockMutation() {
|
||||
async function whenAppViewReady(
|
||||
client: Client,
|
||||
actor: string,
|
||||
fn: (profile: app.bsky.actor.getProfile.$OutputBody) => boolean,
|
||||
fn: (
|
||||
profile: app.bsky.actor.getProfile.$OutputBody | undefined,
|
||||
err: unknown,
|
||||
) => boolean,
|
||||
) {
|
||||
await until(
|
||||
5, // 5 tries
|
||||
|
||||
@@ -325,9 +325,12 @@ export function useDeleteStarterPackMutation({
|
||||
})
|
||||
|
||||
if (uri) {
|
||||
await whenAppViewReady(appviewClient, uri, v => {
|
||||
return Boolean(v?.starterPack) === false
|
||||
})
|
||||
/* Once the deletion is indexed, `getStarterPack` throws. */
|
||||
await whenAppViewReady(
|
||||
appviewClient,
|
||||
uri,
|
||||
v => Boolean(v?.starterPack) === false,
|
||||
)
|
||||
}
|
||||
|
||||
if (listUri) {
|
||||
@@ -353,7 +356,10 @@ export function useDeleteStarterPackMutation({
|
||||
async function whenAppViewReady(
|
||||
client: Client,
|
||||
uri: string,
|
||||
fn: (res?: app.bsky.graph.getStarterPack.$OutputBody) => boolean,
|
||||
fn: (
|
||||
res: app.bsky.graph.getStarterPack.$OutputBody | undefined,
|
||||
err: unknown,
|
||||
) => boolean,
|
||||
) {
|
||||
await until(
|
||||
5, // 5 tries
|
||||
|
||||
@@ -31,7 +31,8 @@ export function useVerificationCreateMutation() {
|
||||
await until(
|
||||
5,
|
||||
1e3,
|
||||
(profile: app.bsky.actor.getProfile.$OutputBody) => {
|
||||
profile => {
|
||||
if (!profile) return false
|
||||
if (
|
||||
profile.verification &&
|
||||
profile.verification.verifications.find(v => v.uri === uri)
|
||||
|
||||
@@ -40,7 +40,8 @@ export function useVerificationsRemoveMutation() {
|
||||
await until(
|
||||
5,
|
||||
1e3,
|
||||
(profile: app.bsky.actor.getProfile.$OutputBody) => {
|
||||
profile => {
|
||||
if (!profile) return false
|
||||
if (
|
||||
!profile.verification?.verifications.some(v => uris.includes(v.uri))
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user