From 2037376e6e699cc39eecd03e79e08ea40a058a95 Mon Sep 17 00:00:00 2001 From: Rudy Fraser Date: Thu, 2 Jul 2026 19:01:46 -0400 Subject: [PATCH] fix(community-posts): hide Community tab and composer toggle from non-members The Community pinned-feed stub was injected for every session; members of the gate are now checked via community.blacksky.actor.checkMembership before injection, so non-members (and logged-out users, already excluded) never see the tab. The Blacksky-only composer toggle is likewise hidden and never defaults on for non-members. Also fixes Mask/G elements in the tech-support badge card. --- src/components/badges/art.tsx | 10 +++--- src/state/queries/community-membership.ts | 37 +++++++++++++++++++++++ src/state/queries/feed.ts | 10 ++++-- src/view/com/composer/Composer.tsx | 10 ++++-- 4 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 src/state/queries/community-membership.ts diff --git a/src/components/badges/art.tsx b/src/components/badges/art.tsx index bae770cab..dcec8861d 100644 --- a/src/components/badges/art.tsx +++ b/src/components/badges/art.tsx @@ -1,5 +1,5 @@ // Generated from Blacksky Branding/Badges/Light Purple/SVG — do not hand-edit shapes. -import Svg, {Defs, LinearGradient, Path, Rect, Stop} from 'react-native-svg' +import Svg, {Defs, G, LinearGradient, Mask, Path, Rect, Stop} from 'react-native-svg' export type BadgeCardProps = {width: number} @@ -115,10 +115,10 @@ export function TechSupportCard({width}: BadgeCardProps) { - + - - + + @@ -127,7 +127,7 @@ export function TechSupportCard({width}: BadgeCardProps) { - + diff --git a/src/state/queries/community-membership.ts b/src/state/queries/community-membership.ts new file mode 100644 index 000000000..1974843c0 --- /dev/null +++ b/src/state/queries/community-membership.ts @@ -0,0 +1,37 @@ +import {type BskyAgent} from '@atproto/api' +import {useQuery} from '@tanstack/react-query' + +import {communityXrpc} from '#/lib/api/community' +import {useAgent, useSession} from '#/state/session' + +const CHECK_MEMBERSHIP_METHOD = 'community.blacksky.actor.checkMembership' + +const RQKEY_ROOT = 'community-membership' +export const communityMembershipRQKey = (did: string | undefined) => [ + RQKEY_ROOT, + did ?? '', +] + +export async function fetchCommunityMembership( + agent: BskyAgent, +): Promise { + try { + const res = await communityXrpc(agent, CHECK_MEMBERSHIP_METHOD) + if (!res.ok) return false + const data = (await res.json()) as {isMember?: boolean} + return !!data.isMember + } catch { + return false + } +} + +export function useCommunityMembership() { + const agent = useAgent() + const {currentAccount} = useSession() + return useQuery({ + queryKey: communityMembershipRQKey(currentAccount?.did), + enabled: !!currentAccount?.did, + staleTime: 5 * 60 * 1000, + queryFn: () => fetchCommunityMembership(agent), + }) +} diff --git a/src/state/queries/feed.ts b/src/state/queries/feed.ts index c55fd7d0e..f1e811ed0 100644 --- a/src/state/queries/feed.ts +++ b/src/state/queries/feed.ts @@ -27,6 +27,7 @@ import {sanitizeDisplayName} from '#/lib/strings/display-names' import {sanitizeHandle} from '#/lib/strings/handles' import {GCTIME, STALE} from '#/state/queries' import {RQKEY as listQueryKey} from '#/state/queries/list' +import {fetchCommunityMembership} from '#/state/queries/community-membership' import {usePreferencesQuery} from '#/state/queries/preferences' import {createQueryKey} from '#/state/queries/util' import {useAgent, useSession} from '#/state/session' @@ -661,9 +662,12 @@ export function usePinnedFeedsInfos() { }) } } - // Inject Community feed after the first item (Following) - const insertIndex = Math.min(1, result.length) - result.splice(insertIndex, 0, COMMUNITY_FEED_STUB) + // Inject Community feed after the first item (Following), members only + const isMember = await fetchCommunityMembership(agent) + if (isMember) { + const insertIndex = Math.min(1, result.length) + result.splice(insertIndex, 0, COMMUNITY_FEED_STUB) + } return result }, }) diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 2e33811b0..1eacac28c 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -100,6 +100,7 @@ import { import {usePreferencesQuery} from '#/state/queries/preferences' import {useProfileQuery} from '#/state/queries/profile' import {resolveLinkQueryOptions} from '#/state/queries/resolve-link' +import {useCommunityMembership} from '#/state/queries/community-membership' import {useAgent, useSession} from '#/state/session' import {useComposerControls} from '#/state/shell/composer' import {type ComposerOpts, type OnPostSuccessData} from '#/state/shell/composer' @@ -358,6 +359,7 @@ export const ComposePost = ({ const blackskyOnlyDefault = useBlackskyOnlyDefault() const setBlackskyOnlyDefault = useSetBlackskyOnlyDefault() + const {data: isCommunityMember = false} = useCommunityMembership() // Force Blacksky-Only when the thread targets a community post — replies // and quotes of a community post can only land in the community. @@ -375,9 +377,10 @@ export const ComposePost = ({ initInteractionSettings: preferences?.postInteractionSettings, // Replies inherit their parent's audience: forced on for community // parents, forced off for public parents. The sticky default only - // applies to top-level posts. + // applies to top-level posts, and only for community members. initBlackskyOnly: - isForcedBlackskyOnly || (!replyTo && blackskyOnlyDefault), + isForcedBlackskyOnly || + (!replyTo && isCommunityMember && blackskyOnlyDefault), }, createComposerState, ) @@ -1987,6 +1990,7 @@ function ComposerPills({ }) { const t = useTheme() const {t: l} = useLingui() + const {data: isCommunityMember = false} = useCommunityMembership() const media = post.embed.media const hasMedia = media?.type === 'images' || @@ -2025,7 +2029,7 @@ function ComposerPills({ style={bottomBarAnimatedStyle} /> )} - {isReply && !isForcedBlackskyOnly ? null : ( + {!isCommunityMember || (isReply && !isForcedBlackskyOnly) ? null : (