From 7318af16b17dacc5d73fd9b1401e492645a7ea50 Mon Sep 17 00:00:00 2001 From: Timothy Quilling Date: Thu, 9 Oct 2025 11:00:21 -0400 Subject: [PATCH] feat: substitute header for preferences calls; workaround until POST supported for putPreferences --- src/env/common.ts | 4 ++ src/lib/constants.ts | 11 ++++- src/state/queries/notifications/settings.ts | 5 +++ src/state/queries/preferences/index.ts | 48 ++++++++++++++++++++- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/env/common.ts b/src/env/common.ts index da738f5fc..9ae9f9c89 100644 --- a/src/env/common.ts +++ b/src/env/common.ts @@ -67,6 +67,10 @@ export const LOG_DEBUG: string = process.env.EXPO_PUBLIC_LOG_DEBUG || '' */ export const BLUESKY_PROXY_DID: Did = process.env.EXPO_PUBLIC_BLUESKY_PROXY_DID || 'did:web:api.shatteredsky.net' +/** + * The DID of the PBLLC Bluesky appview to proxy to + */ +export const PBLLC_BLUESKY_PROXY_DID: Did = 'did:web:api.bsky.app' /** * The DID of the chat service to proxy to diff --git a/src/lib/constants.ts b/src/lib/constants.ts index d4ad27938..e1a761b21 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -2,7 +2,7 @@ import {type Insets, Platform} from 'react-native' import {type AppBskyActorDefs, BSKY_LABELER_DID} from '@atproto/api' import {type ProxyHeaderValue} from '#/state/session/agent' -import {BLUESKY_PROXY_DID, CHAT_PROXY_DID} from '#/env' +import {BLUESKY_PROXY_DID, CHAT_PROXY_DID, PBLLC_BLUESKY_PROXY_DID} from '#/env' export const LOCAL_DEV_SERVICE = Platform.OS === 'android' ? 'http://10.0.2.2:2583' : 'http://localhost:2583' @@ -213,6 +213,15 @@ export const BLUESKY_PROXY_HEADER = { this.value = value }, } +export const PBLLC_BLUESKY_PROXY_HEADER = { + value: `${PBLLC_BLUESKY_PROXY_DID}#bsky_appview`, + get() { + return this.value as ProxyHeaderValue + }, + set(value: string) { + this.value = value + }, +} export const DM_SERVICE_HEADERS = { 'atproto-proxy': `${CHAT_PROXY_DID}#bsky_chat`, diff --git a/src/state/queries/notifications/settings.ts b/src/state/queries/notifications/settings.ts index 02c0fe23b..073971037 100644 --- a/src/state/queries/notifications/settings.ts +++ b/src/state/queries/notifications/settings.ts @@ -7,6 +7,7 @@ import { useQueryClient, } from '@tanstack/react-query' +import {BLUESKY_PROXY_HEADER, PBLLC_BLUESKY_PROXY_HEADER} from '#/lib/constants' import {logger} from '#/logger' import {useAgent} from '#/state/session' import * as Toast from '#/view/com/util/Toast' @@ -22,7 +23,9 @@ export function useNotificationSettingsQuery({ return useQuery({ queryKey: RQKEY, queryFn: async () => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) const response = await agent.app.bsky.notification.getPreferences() + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) return response.data.preferences }, enabled, @@ -36,8 +39,10 @@ export function useNotificationSettingsUpdateMutation() { mutationFn: async ( update: Partial, ) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) const response = await agent.app.bsky.notification.putPreferencesV2(update) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) return response.data.preferences }, onMutate: update => { diff --git a/src/state/queries/preferences/index.ts b/src/state/queries/preferences/index.ts index d644f4193..867700f27 100644 --- a/src/state/queries/preferences/index.ts +++ b/src/state/queries/preferences/index.ts @@ -6,7 +6,11 @@ import { } from '@atproto/api' import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query' -import {PROD_DEFAULT_FEED} from '#/lib/constants' +import { + BLUESKY_PROXY_HEADER, + PBLLC_BLUESKY_PROXY_HEADER, + PROD_DEFAULT_FEED, +} from '#/lib/constants' import {replaceEqualDeep} from '#/lib/functions' import {getAge} from '#/lib/strings/time' import {logger} from '#/logger' @@ -45,7 +49,9 @@ export function usePreferencesQuery() { if (!agent.did) { return DEFAULT_LOGGED_OUT_PREFERENCES } else { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) const res = await agent.getPreferences() + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // save to local storage to ensure there are labels on initial requests saveLabelers( @@ -97,7 +103,9 @@ export function useClearPreferencesMutation() { return useMutation({ mutationFn: async () => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.app.bsky.actor.putPreferences({preferences: []}) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -116,7 +124,9 @@ export function usePreferencesSetContentLabelMutation() { {label: string; visibility: LabelPreference; labelerDid: string | undefined} >({ mutationFn: async ({label, visibility, labelerDid}) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.setContentLabelPref(label, visibility, labelerDid) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) logger.metric( 'moderation:changeLabelPreference', {preference: visibility}, @@ -144,7 +154,9 @@ export function useSetContentLabelMutation() { visibility: LabelPreference labelerDid?: string }) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.setContentLabelPref(label, visibility, labelerDid) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -159,7 +171,9 @@ export function usePreferencesSetAdultContentMutation() { return useMutation({ mutationFn: async ({enabled}) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.setAdultContentEnabled(enabled) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -174,7 +188,9 @@ export function usePreferencesSetBirthDateMutation() { return useMutation({ mutationFn: async ({birthDate}: {birthDate: Date}) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.setPersonalDetails({birthDate: birthDate.toISOString()}) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -193,7 +209,9 @@ export function useSetFeedViewPreferencesMutation() { * special handling here, merged into `feedViewPrefs` above, since * following was previously called `home` */ + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.setFeedViewPrefs('home', prefs) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -208,7 +226,9 @@ export function useSetThreadViewPreferencesMutation() { return useMutation>({ mutationFn: async prefs => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.setThreadViewPrefs(prefs) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -223,7 +243,9 @@ export function useOverwriteSavedFeedsMutation() { return useMutation({ mutationFn: async savedFeeds => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.overwriteSavedFeeds(savedFeeds) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -242,7 +264,9 @@ export function useAddSavedFeedsMutation() { Pick[] >({ mutationFn: async savedFeeds => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.addSavedFeeds(savedFeeds) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -257,7 +281,9 @@ export function useRemoveFeedMutation() { return useMutation>({ mutationFn: async savedFeed => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.removeSavedFeeds([savedFeed.id]) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -278,6 +304,7 @@ export function useReplaceForYouWithDiscoverFeedMutation() { forYouFeedConfig: AppBskyActorDefs.SavedFeed | undefined discoverFeedConfig: AppBskyActorDefs.SavedFeed | undefined }) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) if (forYouFeedConfig) { await agent.removeSavedFeeds([forYouFeedConfig.id]) } @@ -297,6 +324,7 @@ export function useReplaceForYouWithDiscoverFeedMutation() { }, ]) } + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -311,7 +339,9 @@ export function useUpdateSavedFeedsMutation() { return useMutation({ mutationFn: async feeds => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.updateSavedFeeds(feeds) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ @@ -327,7 +357,9 @@ export function useUpsertMutedWordsMutation() { return useMutation({ mutationFn: async (mutedWords: AppBskyActorDefs.MutedWord[]) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.upsertMutedWords(mutedWords) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -342,7 +374,9 @@ export function useUpdateMutedWordMutation() { return useMutation({ mutationFn: async (mutedWord: AppBskyActorDefs.MutedWord) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.updateMutedWord(mutedWord) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -357,7 +391,9 @@ export function useRemoveMutedWordMutation() { return useMutation({ mutationFn: async (mutedWord: AppBskyActorDefs.MutedWord) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.removeMutedWord(mutedWord) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -372,7 +408,9 @@ export function useRemoveMutedWordsMutation() { return useMutation({ mutationFn: async (mutedWords: AppBskyActorDefs.MutedWord[]) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.removeMutedWords(mutedWords) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -387,7 +425,9 @@ export function useQueueNudgesMutation() { return useMutation({ mutationFn: async (nudges: string | string[]) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.bskyAppQueueNudges(nudges) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -402,7 +442,9 @@ export function useDismissNudgesMutation() { return useMutation({ mutationFn: async (nudges: string | string[]) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.bskyAppDismissNudges(nudges) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -419,7 +461,9 @@ export function useSetActiveProgressGuideMutation() { mutationFn: async ( guide: AppBskyActorDefs.BskyAppProgressGuide | undefined, ) => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.bskyAppSetActiveProgressGuide(guide) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) // triggers a refetch await queryClient.invalidateQueries({ queryKey: preferencesQueryKey, @@ -434,7 +478,9 @@ export function useSetVerificationPrefsMutation() { return useMutation({ mutationFn: async prefs => { + agent.configureProxy(PBLLC_BLUESKY_PROXY_HEADER.get()) await agent.setVerificationPrefs(prefs) + agent.configureProxy(BLUESKY_PROXY_HEADER.get()) if (prefs.hideBadges) { logger.metric('verification:settings:hideBadges', {}, {statsig: true}) } else { -- 2.51.2