diff --git a/src/components/PostControls/index.tsx b/src/components/PostControls/index.tsx index d055418f8..97d55337f 100644 --- a/src/components/PostControls/index.tsx +++ b/src/components/PostControls/index.tsx @@ -256,14 +256,16 @@ let PostControls = ({ - void onRepost()} - onQuote={onQuote} - big={big} - embeddingDisabled={Boolean(post.viewer?.embeddingDisabled)} - /> + {post.uri.includes('community.blacksky.feed.post') ? null : ( + void onRepost()} + onQuote={onQuote} + big={big} + embeddingDisabled={Boolean(post.viewer?.embeddingDisabled)} + /> + )} + p.embed.quote?.uri?.includes(COMMUNITY_POST_COLLECTION), + ) - if (thread.blackskyOnly || isReplyToCommunityPost) { + if (thread.blackskyOnly || isReplyToCommunityPost || isQuoteOfCommunityPost) { return postCommunity(agent, queryClient, opts) } diff --git a/src/state/persisted/schema.ts b/src/state/persisted/schema.ts index f63479efb..47d8e0bb0 100644 --- a/src/state/persisted/schema.ts +++ b/src/state/persisted/schema.ts @@ -136,6 +136,7 @@ const schema = z.object({ repostCarouselEnabled: z.boolean().optional(), hideFollowNotifications: z.boolean().optional(), showLinkInHandle: z.boolean().optional(), + blackskyOnlyDefault: z.boolean().optional(), /** @deprecated */ mutedThreads: z.array(z.string()), diff --git a/src/state/preferences/blacksky-only-default.tsx b/src/state/preferences/blacksky-only-default.tsx new file mode 100644 index 000000000..02b76d2d7 --- /dev/null +++ b/src/state/preferences/blacksky-only-default.tsx @@ -0,0 +1,47 @@ +import { + createContext, + useCallback, + useContext, + useEffect, + useState, +} from 'react' + +import * as persisted from '#/state/persisted' + +type StateContext = boolean +type SetContext = (v: boolean) => void + +const stateContext = createContext( + Boolean(persisted.defaults.blackskyOnlyDefault), +) +stateContext.displayName = 'BlackskyOnlyDefaultStateContext' +const setContext = createContext((_: boolean) => {}) +setContext.displayName = 'BlackskyOnlyDefaultSetContext' + +export function Provider({children}: {children: React.ReactNode}) { + const [state, setState] = useState( + Boolean(persisted.get('blackskyOnlyDefault')), + ) + + const setStateWrapped = useCallback((v: boolean) => { + setState(v) + persisted.write('blackskyOnlyDefault', v) + }, []) + + useEffect(() => { + return persisted.onUpdate('blackskyOnlyDefault', next => { + setState(Boolean(next)) + }) + }, []) + + return ( + + + {children} + + + ) +} + +export const useBlackskyOnlyDefault = () => useContext(stateContext) +export const useSetBlackskyOnlyDefault = () => useContext(setContext) diff --git a/src/state/preferences/index.tsx b/src/state/preferences/index.tsx index 0f20953b7..37e08f149 100644 --- a/src/state/preferences/index.tsx +++ b/src/state/preferences/index.tsx @@ -1,5 +1,6 @@ import {Provider as AltTextRequiredProvider} from './alt-text-required' import {Provider as AutoplayProvider} from './autoplay' +import {Provider as BlackskyOnlyDefaultProvider} from './blacksky-only-default' import {Provider as DisableHapticsProvider} from './disable-haptics' import {Provider as ExternalEmbedsProvider} from './external-embeds-prefs' import {Provider as HiddenPostsProvider} from './hidden-posts' @@ -16,6 +17,10 @@ export { useSetRequireAltTextEnabled, } from './alt-text-required' export {useAutoplayDisabled, useSetAutoplayDisabled} from './autoplay' +export { + useBlackskyOnlyDefault, + useSetBlackskyOnlyDefault, +} from './blacksky-only-default' export {useHapticsDisabled, useSetHapticsDisabled} from './disable-haptics' export { useExternalEmbedsPrefs, @@ -39,7 +44,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) { - {children} + + {children} + diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 76ff92868..3343c6d9e 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -86,7 +86,11 @@ import { createComposerImage, pasteImage, } from '#/state/gallery' -import {useRequireAltTextEnabled} from '#/state/preferences' +import { + useBlackskyOnlyDefault, + useRequireAltTextEnabled, + useSetBlackskyOnlyDefault, +} from '#/state/preferences' import { fromPostLanguages, toPostLanguages, @@ -351,6 +355,15 @@ export const ComposePost = ({ setLanguageNudgeAt(prev => (now - prev > 10_000 ? now : prev)) } + const blackskyOnlyDefault = useBlackskyOnlyDefault() + const setBlackskyOnlyDefault = useSetBlackskyOnlyDefault() + + // Force Blacksky-Only when the thread targets a community post — replies + // and quotes of a community post can only land in the community. + const isForcedBlackskyOnly = + (!!replyTo?.uri && replyTo.uri.includes('community.blacksky.feed.post')) || + (!!initQuote?.uri && initQuote.uri.includes('community.blacksky.feed.post')) + const [composerState, composerDispatch] = useReducer( composerReducer, { @@ -359,6 +372,7 @@ export const ComposePost = ({ initText, initMention, initInteractionSettings: preferences?.postInteractionSettings, + initBlackskyOnly: isForcedBlackskyOnly || blackskyOnlyDefault, }, createComposerState, ) @@ -2001,13 +2015,15 @@ function ComposerPills({ style={bottomBarAnimatedStyle} /> )} - {isReply ? null : ( + {isReply || isForcedBlackskyOnly ? null : ( { + const next = !thread.blackskyOnly dispatch({type: 'toggle_blacksky_only'}) + setBlackskyOnlyDefault(next) }} style={[a.flex_row, a.align_center, a.gap_xs]}> diff --git a/src/view/com/composer/state/composer.ts b/src/view/com/composer/state/composer.ts index 1ec21e025..b1a64ae71 100644 --- a/src/view/com/composer/state/composer.ts +++ b/src/view/com/composer/state/composer.ts @@ -630,6 +630,7 @@ export function createComposerState({ initImageUris, initQuoteUri, initInteractionSettings, + initBlackskyOnly, }: { initText: string | undefined initMention: string | undefined @@ -638,6 +639,7 @@ export function createComposerState({ initInteractionSettings: | AppBskyActorDefs.PostInteractionSettingsPref | undefined + initBlackskyOnly?: boolean }): ComposerState { let media: ImagesMedia | GalleryMedia | undefined if (initImageUris?.length) { @@ -758,7 +760,7 @@ export function createComposerState({ createdAt: new Date().toString(), allow: initInteractionSettings?.threadgateAllowRules, }), - blackskyOnly: false, + blackskyOnly: !!initBlackskyOnly, }, } }