diff --git a/src/components/CommunityOnlyBadge.tsx b/src/components/CommunityOnlyBadge.tsx index 589945a87..e2e985a2d 100644 --- a/src/components/CommunityOnlyBadge.tsx +++ b/src/components/CommunityOnlyBadge.tsx @@ -11,12 +11,6 @@ import {Group3_Stroke2_Corner0_Rounded as GroupIcon} from '#/components/icons/Gr import * as Tooltip from '#/components/Tooltip' import {Text} from '#/components/Typography' -const COMMUNITY_POST_COLLECTION = 'community.blacksky.feed.post' - -export function isCommunityPostUri(uri: string | undefined): boolean { - return !!uri && uri.includes(COMMUNITY_POST_COLLECTION) -} - export function CommunityOnlyBadge({communityFeed}: {communityFeed?: string}) { const t = useTheme() const {_} = useLingui() diff --git a/src/components/PostControls/index.tsx b/src/components/PostControls/index.tsx index a2d446aaa..642d2a8c1 100644 --- a/src/components/PostControls/index.tsx +++ b/src/components/PostControls/index.tsx @@ -9,7 +9,8 @@ import { import {plural} from '@lingui/core/macro' import {useLingui} from '@lingui/react/macro' -import {getCommunityFeedUri} from '#/lib/api/community-post' +import {getCommunityFeedUri, isCommunityPostUri} from '#/lib/api/community-post' +import {isSpaceRecordUri} from '#/lib/api/space-uri' import {CountWheel} from '#/lib/custom-animations/CountWheel' import {AnimatedLikeIcon} from '#/lib/custom-animations/LikeIcon' import {useOpenComposer} from '#/lib/hooks/useOpenComposer' @@ -25,10 +26,7 @@ import { useProgressGuideControls, } from '#/state/shell/progress-guide' import {atoms as a, useBreakpoints, useTheme} from '#/alf' -import { - CommunityOnlyBadge, - isCommunityPostUri, -} from '#/components/CommunityOnlyBadge' +import {CommunityOnlyBadge} from '#/components/CommunityOnlyBadge' import {Reply as Bubble} from '#/components/icons/Reply' import {useFormatPostStatCount} from '#/components/PostControls/util' import * as Skele from '#/components/Skeleton' @@ -267,8 +265,11 @@ let PostControls = ({ onRepost={() => void onRepost()} onQuote={onQuote} big={big} - embeddingDisabled={Boolean(post.viewer?.embeddingDisabled)} - repostDisabled={post.uri.includes('community.blacksky.feed.post')} + embeddingDisabled={ + Boolean(post.viewer?.embeddingDisabled) || + isSpaceRecordUri(post.uri) + } + repostDisabled={isCommunityPostUri(post.uri)} /> diff --git a/src/components/__tests__/Typography.test.tsx b/src/components/__tests__/Typography.test.tsx deleted file mode 100644 index 83164009d..000000000 --- a/src/components/__tests__/Typography.test.tsx +++ /dev/null @@ -1,70 +0,0 @@ -import type * as ReactNative from 'react-native' -import {Text as RNText} from 'react-native' -import {render} from '@testing-library/react-native' - -import {Text} from '#/components/Typography' - -jest.mock('react-native', () => { - const actual = jest.requireActual('react-native') - - Object.defineProperty(actual.Platform, 'OS', { - value: 'ios', - configurable: true, - }) - Object.defineProperty(actual.Platform, 'Version', { - value: '17.0', - configurable: true, - }) - - return actual -}) - -jest.mock('react-native-uitextview', () => { - const React = require('react') - const {Text: RNText} = require('react-native') - - return { - UITextView: jest.fn(({children, ...props}) => ( - - {children} - - )), - } -}) - -describe('Text', () => { - it('renders non-selectable text without UITextView', () => { - const {getByText, queryByTestId} = render(Normal text) - - expect(getByText('Normal text')).toBeTruthy() - expect(queryByTestId('ui-text-view')).toBeNull() - }) - - it('uses UITextView for selectable iOS text', () => { - const {getByTestId} = render(Selectable text) - - expect(getByTestId('ui-text-view')).toBeTruthy() - }) - - it('does not nest UITextView inside selectable emoji text', () => { - const {getAllByTestId, getByText} = render( - - 😀 popular post - , - ) - - expect(getByText('😀 popular post')).toBeTruthy() - expect(getAllByTestId('ui-text-view')).toHaveLength(1) - }) - - it('still allows native Text children inside non-selectable text', () => { - const {getByText, queryByTestId} = render( - - Nested text - , - ) - - expect(getByText('Nested text')).toBeTruthy() - expect(queryByTestId('ui-text-view')).toBeNull() - }) -}) diff --git a/src/lib/api/__tests__/community-post-uri.test.ts b/src/lib/api/__tests__/community-post-uri.test.ts new file mode 100644 index 000000000..1b1176e78 --- /dev/null +++ b/src/lib/api/__tests__/community-post-uri.test.ts @@ -0,0 +1,20 @@ +import {isCommunityPostUri} from '../community-post' + +const SPACE = 'at://did:plc:community/space/community.blacksky.feed/private' + +describe(isCommunityPostUri, () => { + it.each([ + ['a stub post', 'at://did:plc:alice/community.blacksky.feed.post/3kabc'], + ['a space post', `${SPACE}/did:plc:alice/app.bsky.feed.post/3kabc`], + ['a space like', `${SPACE}/did:plc:alice/app.bsky.feed.like/3klike`], + ])('treats %s as community content', (_name, uri) => { + expect(isCommunityPostUri(uri)).toBe(true) + }) + + it.each([undefined, 'at://did:plc:alice/app.bsky.feed.post/3kabc', SPACE])( + 'leaves public content alone: %p', + uri => { + expect(isCommunityPostUri(uri)).toBe(false) + }, + ) +}) diff --git a/src/lib/api/community-post.ts b/src/lib/api/community-post.ts index 010e1743a..eb4e537b3 100644 --- a/src/lib/api/community-post.ts +++ b/src/lib/api/community-post.ts @@ -1,5 +1,20 @@ import {type AppBskyFeedDefs, AtUri} from '@atproto/api' +import {isSpaceRecordUri} from '#/lib/api/space-uri' + +const COMMUNITY_POST_COLLECTION = 'community.blacksky.feed.post' + +/** + * Whether this post is community content — the appview-stored stub, or a + * record living in a permissioned space. Keyed structurally rather than by + * collection, so a new kind of space record is covered the day it appears. + */ +export function isCommunityPostUri(uri: string | undefined): boolean { + return ( + !!uri && (uri.includes(COMMUNITY_POST_COLLECTION) || isSpaceRecordUri(uri)) + ) +} + export type CommunityPostView = AppBskyFeedDefs.PostView & { communityFeed?: string } diff --git a/src/lib/api/index.ts b/src/lib/api/index.ts index dd63988f7..5608945aa 100644 --- a/src/lib/api/index.ts +++ b/src/lib/api/index.ts @@ -32,6 +32,7 @@ import { isSpaceBackedFeed, } from '#/lib/api/community-feed' import {postToSpace} from '#/lib/api/space-post' +import {isSpaceRecordUri} from '#/lib/api/space-uri' import {IMAGE_SIZE_CONFIG_POSTS} from '#/lib/constants' import {isNetworkError} from '#/lib/strings/errors' import {shortenLinks, stripInvalidMentions} from '#/lib/strings/rich-text-manip' @@ -115,10 +116,14 @@ export async function post( // A public post must never carry a community post in its embed; the // routing above sends those to postCommunity, so reaching here with one - // is a bug we refuse rather than leak community content publicly. + // is a bug we refuse rather than leak community content publicly. A space + // record is refused for the same reason, and its URI would leak the space + // even if the appview declined to hydrate it. if ( - thread.posts.some(p => - p.embed.quote?.uri?.includes(COMMUNITY_POST_COLLECTION), + thread.posts.some( + p => + p.embed.quote?.uri?.includes(COMMUNITY_POST_COLLECTION) || + isSpaceRecordUri(p.embed.quote?.uri), ) ) { throw new Error('Public posts cannot embed a community post') diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index c97f25d5e..85d4ad17c 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -60,6 +60,7 @@ import {Trans, useLingui} from '@lingui/react/macro' import {useNavigation} from '@react-navigation/native' import {useQueries, useQueryClient} from '@tanstack/react-query' +import {isSpaceBackedFeed} from '#/lib/api/community-feed' import {getCommunityFeedUri} from '#/lib/api/community-post' import * as apilib from '#/lib/api/index' import {EmbeddingDisabledError} from '#/lib/api/resolve' @@ -2035,7 +2036,7 @@ function ComposerPills({ bounces={false} keyboardShouldPersistTaps="always" showsHorizontalScrollIndicator={false}> - {isReply ? null : ( + {isReply || isSpaceBackedFeed(thread.communityFeed?.config) ? null : ( {