route appview state and facet resolution off the pds client
Audit of usePdsClient call sites: the PDS client is for com.atproto.* account/repo operations. Appview-private state (actor/list/thread mutes, notification seen-state) and mention/facet resolution now use the appview-routed client. useRichText also regains logged-out mention resolution via useLexClient's public fallback (usePdsClient throws when logged out, silently leaving mentions unresolved on StarterPackLanding and web ProfileHoverCard). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Vendored
+4
-4
@@ -9,7 +9,7 @@ import {type AtUriString} from '@atproto/syntax'
|
||||
|
||||
import * as persisted from '#/state/persisted'
|
||||
import {app} from '#/lexicons'
|
||||
import {usePdsClient, useSession} from '../session'
|
||||
import {useAppviewClient, useSession} from '../session'
|
||||
|
||||
type StateContext = Map<string, boolean>
|
||||
type SetStateContext = (uri: string, value: boolean) => void
|
||||
@@ -58,7 +58,7 @@ export function useSetThreadMute() {
|
||||
}
|
||||
|
||||
function useMigrateMutes(setThreadMute: SetStateContext) {
|
||||
const pdsClient = usePdsClient()
|
||||
const appviewClient = useAppviewClient()
|
||||
const {currentAccount} = useSession()
|
||||
|
||||
useEffect(() => {
|
||||
@@ -89,7 +89,7 @@ function useMigrateMutes(setThreadMute: SetStateContext) {
|
||||
|
||||
setThreadMute(root, true)
|
||||
|
||||
await pdsClient
|
||||
await appviewClient
|
||||
.call(app.bsky.graph.muteThread, {root: root as AtUriString})
|
||||
// not a big deal if this fails, since the post might have been deleted
|
||||
.catch(console.error)
|
||||
@@ -102,5 +102,5 @@ function useMigrateMutes(setThreadMute: SetStateContext) {
|
||||
cancelled = true
|
||||
}
|
||||
}
|
||||
}, [pdsClient, currentAccount, setThreadMute])
|
||||
}, [appviewClient, currentAccount, setThreadMute])
|
||||
}
|
||||
|
||||
@@ -253,13 +253,12 @@ export function useListDeleteMutation() {
|
||||
export function useListMuteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const appviewClient = useAppviewClient()
|
||||
const pdsClient = usePdsClient()
|
||||
return useMutation<void, Error, {uri: string; mute: boolean}>({
|
||||
mutationFn: async ({uri, mute}) => {
|
||||
if (mute) {
|
||||
await pdsClient.call(muteActorList, {list: uri as AtUriString})
|
||||
await appviewClient.call(muteActorList, {list: uri as AtUriString})
|
||||
} else {
|
||||
await pdsClient.call(unmuteActorList, {list: uri as AtUriString})
|
||||
await appviewClient.call(unmuteActorList, {list: uri as AtUriString})
|
||||
}
|
||||
|
||||
await whenAppViewReady(appviewClient, uri, v => {
|
||||
|
||||
@@ -20,7 +20,7 @@ import BroadcastChannel from '#/lib/broadcast'
|
||||
import {resetBadgeCount} from '#/lib/notifications/notifications'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {truncateAndInvalidate} from '#/state/queries/util'
|
||||
import {useAppviewClient, usePdsClient, useSession} from '#/state/session'
|
||||
import {useAppviewClient, useSession} from '#/state/session'
|
||||
import {RQKEY as RQKEY_NOTIFS} from './feed'
|
||||
import {type CachedFeedPage, type FeedPage} from './types'
|
||||
import {fetchPage} from './util'
|
||||
@@ -55,7 +55,6 @@ apiContext.displayName = 'NotificationsUnreadApiContext'
|
||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const {hasSession} = useSession()
|
||||
const appviewClient = useAppviewClient()
|
||||
const pdsClient = usePdsClient()
|
||||
const queryClient = useQueryClient()
|
||||
const moderationOpts = useModerationOpts()
|
||||
|
||||
@@ -123,7 +122,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
return {
|
||||
async markAllRead() {
|
||||
// update server
|
||||
await pdsClient.call(
|
||||
await appviewClient.call(
|
||||
updateSeenNotifications,
|
||||
// toISOString() always yields a valid datetime string
|
||||
cacheRef.current.syncedAt.toISOString() as DatetimeString,
|
||||
@@ -212,14 +211,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
}
|
||||
},
|
||||
}
|
||||
}, [
|
||||
setNumUnread,
|
||||
queryClient,
|
||||
moderationOpts,
|
||||
appviewClient,
|
||||
pdsClient,
|
||||
hasSession,
|
||||
])
|
||||
}, [setNumUnread, queryClient, moderationOpts, appviewClient, hasSession])
|
||||
checkUnreadRef.current = api.checkUnread
|
||||
|
||||
return (
|
||||
|
||||
@@ -414,14 +414,14 @@ export function useThreadMuteMutationQueue(
|
||||
}
|
||||
|
||||
function useThreadMuteMutation() {
|
||||
const pdsClient = usePdsClient()
|
||||
const appviewClient = useAppviewClient()
|
||||
return useMutation<
|
||||
{},
|
||||
Error,
|
||||
{uri: string} // the root post's uri
|
||||
>({
|
||||
mutationFn: async ({uri}) => {
|
||||
await pdsClient.call(app.bsky.graph.muteThread, {
|
||||
await appviewClient.call(app.bsky.graph.muteThread, {
|
||||
root: uri as AtUriString,
|
||||
})
|
||||
return {}
|
||||
@@ -430,10 +430,10 @@ function useThreadMuteMutation() {
|
||||
}
|
||||
|
||||
function useThreadUnmuteMutation() {
|
||||
const pdsClient = usePdsClient()
|
||||
const appviewClient = useAppviewClient()
|
||||
return useMutation<{}, Error, {uri: string}>({
|
||||
mutationFn: async ({uri}) => {
|
||||
await pdsClient.call(app.bsky.graph.unmuteThread, {
|
||||
await appviewClient.call(app.bsky.graph.unmuteThread, {
|
||||
root: uri as AtUriString,
|
||||
})
|
||||
return {}
|
||||
|
||||
@@ -474,10 +474,10 @@ export function useProfileMuteMutationQueue(
|
||||
|
||||
function useProfileMuteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const pdsClient = usePdsClient()
|
||||
const appviewClient = useAppviewClient()
|
||||
return useMutation<void, Error, {did: string}>({
|
||||
mutationFn: async ({did}) => {
|
||||
await pdsClient.call(muteActor, {actor: did as AtIdentifierString})
|
||||
await appviewClient.call(muteActor, {actor: did as AtIdentifierString})
|
||||
},
|
||||
onSuccess() {
|
||||
void queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
|
||||
@@ -487,10 +487,10 @@ function useProfileMuteMutation() {
|
||||
|
||||
function useProfileUnmuteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const pdsClient = usePdsClient()
|
||||
const appviewClient = useAppviewClient()
|
||||
return useMutation<void, Error, {did: string}>({
|
||||
mutationFn: async ({did}) => {
|
||||
await pdsClient.call(unmuteActor, {actor: did as AtIdentifierString})
|
||||
await appviewClient.call(unmuteActor, {actor: did as AtIdentifierString})
|
||||
},
|
||||
onSuccess() {
|
||||
void queryClient.invalidateQueries({queryKey: RQKEY_MY_MUTED()})
|
||||
|
||||
@@ -110,7 +110,7 @@ export function useCreateStarterPackMutation({
|
||||
let descriptionFacets: app.bsky.richtext.facet.Main[] | undefined
|
||||
if (description) {
|
||||
const rt = new RichText({text: description})
|
||||
await rt.detectFacets(pdsClient)
|
||||
await rt.detectFacets(appviewClient)
|
||||
descriptionFacets = rt.facets
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ export function useEditStarterPackMutation({
|
||||
let descriptionFacets: app.bsky.richtext.facet.Main[] | undefined
|
||||
if (description) {
|
||||
const rt = new RichText({text: description})
|
||||
await rt.detectFacets(pdsClient)
|
||||
await rt.detectFacets(appviewClient)
|
||||
descriptionFacets = rt.facets
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user