diff --git a/src/components/__tests__/post-community-address-compat.test.tsx b/src/components/__tests__/post-community-address-compat.test.tsx index b189f141..c5f9a251 100644 --- a/src/components/__tests__/post-community-address-compat.test.tsx +++ b/src/components/__tests__/post-community-address-compat.test.tsx @@ -19,6 +19,7 @@ type TestComment = { communityAddress?: string; content?: string; deleted?: boolean; + flairs?: Array<{ code?: string; text?: string; type?: string }>; index?: number; link?: string; linkHeight?: number; @@ -48,6 +49,7 @@ type TestComment = { const testState = vi.hoisted(() => ({ addChallengeMock: vi.fn(), accountCommentsByCid: {} as Record, + directoryEntryByAddress: {} as Record; title?: string } | undefined>, hasMoreReplies: false, openReplyModalMock: vi.fn(), pseudonymityMode: 'none', @@ -212,6 +214,10 @@ vi.mock('../../hooks/use-directories', () => ({ useDirectories: () => [{ address: 'music-posting.eth', title: '/mu/ - Music' }], })); +vi.mock('../../hooks/use-directory-entry', () => ({ + useDirectoryEntry: (address?: string) => (address ? testState.directoryEntryByAddress[address] : undefined), +})); + vi.mock('../../lib/utils/route-utils', () => ({ getBoardPath: (address?: string) => (address ? 'mu' : undefined), })); @@ -458,6 +464,9 @@ describe('post community address compatibility', () => { beforeEach(() => { vi.clearAllMocks(); testState.accountCommentsByCid = {}; + testState.directoryEntryByAddress = { + 'music-posting.eth': { address: 'music-posting.eth', features: {} }, + }; testState.hasMoreReplies = false; testState.pseudonymityMode = 'none'; testState.replyComments = []; @@ -533,6 +542,26 @@ describe('post community address compatibility', () => { expect(container.querySelector('.capcodeAdminIcon')).toBeTruthy(); }); + it('renders author flags for raw-address posts on non-primary directory candidate boards', async () => { + testState.directoryEntryByAddress['nothing-is-beyond-our-reach.bso'] = { + address: 'nothing-is-beyond-our-reach.bso', + directoryCode: 'pol', + features: { hasFlags: true }, + title: '/pol/ - Politically Incorrect', + }; + const post = { + ...makeLegacyThreadWithoutReplies(), + communityAddress: 'nothing-is-beyond-our-reach.bso', + flairs: [{ text: 'flag:pol:AC' }], + }; + + await renderWithRoute(createElement(PostDesktop, { post } as any), '/nothing-is-beyond-our-reach.bso/thread/post-1'); + expect(container.querySelector('img[title="Anarcho-Capitalist"]')).toBeTruthy(); + + await renderWithRoute(createElement(PostMobile, { post } as any), '/nothing-is-beyond-our-reach.bso/thread/post-1'); + expect(container.querySelector('img[title="Anarcho-Capitalist"]')).toBeTruthy(); + }); + it('falls back to author shortAddress when the full author address cannot be shortened', async () => { testState.pseudonymityMode = 'per-post'; const post = { diff --git a/src/components/post-desktop/post-desktop.tsx b/src/components/post-desktop/post-desktop.tsx index 26e4a798..89ece100 100644 --- a/src/components/post-desktop/post-desktop.tsx +++ b/src/components/post-desktop/post-desktop.tsx @@ -14,6 +14,7 @@ import { isAllView, isModQueueView, isModView, isPendingPostView, isPostPageView import { formatUserIDForDisplay, truncateWithEllipsisInMiddle } from '../../lib/utils/string-utils'; import useModQueueStore from '../../stores/use-mod-queue-store'; import { findDirectoryByAddress, useDirectories } from '../../hooks/use-directories'; +import { useDirectoryEntry } from '../../hooks/use-directory-entry'; import { getBoardPath } from '../../lib/utils/route-utils'; import useAuthorAddressClick from '../../hooks/use-author-address-click'; import { useCommentMediaInfo } from '../../hooks/use-comment-media-info'; @@ -173,8 +174,8 @@ const PostInfo = ({ const isReply = parentCid; const { showOmittedReplies } = useShowOmittedReplies(); const directories = useDirectories(); - const directoryEntry = communityAddress ? findDirectoryByAddress(directories, communityAddress) : undefined; const boardPath = communityAddress ? getBoardPath(communityAddress, directories) : undefined; + const directoryEntry = useDirectoryEntry(communityAddress); const showAuthorFlags = hasCommentFlagsForDirectory(directoryEntry) && !(deleted || removed || purged); const postMenuProps = selectPostMenuProps(post); diff --git a/src/components/post-mobile/post-mobile.tsx b/src/components/post-mobile/post-mobile.tsx index f401dde1..be5d60cd 100644 --- a/src/components/post-mobile/post-mobile.tsx +++ b/src/components/post-mobile/post-mobile.tsx @@ -14,6 +14,7 @@ import { isAllView, isModQueueView, isModView, isPendingPostView, isPostPageView import { formatUserIDForDisplay } from '../../lib/utils/string-utils'; import useModQueueStore from '../../stores/use-mod-queue-store'; import { findDirectoryByAddress, useDirectories } from '../../hooks/use-directories'; +import { useDirectoryEntry } from '../../hooks/use-directory-entry'; import { getBoardPath } from '../../lib/utils/route-utils'; import useAuthorAddressClick from '../../hooks/use-author-address-click'; import { useCommentMediaInfo } from '../../hooks/use-comment-media-info'; @@ -88,7 +89,7 @@ const PostInfoAndMedia = ({ const archived = isCommentArchived(resolvedPost); const purged = resolvedPost?.commentModeration?.purged; const boardPath = communityAddress ? getBoardPath(communityAddress, directories) : undefined; - const directoryEntry = communityAddress ? findDirectoryByAddress(directories, communityAddress) : undefined; + const directoryEntry = useDirectoryEntry(communityAddress); const showAuthorFlags = hasCommentFlagsForDirectory(directoryEntry) && !(deleted || removed || purged); const displayBoardPath = boardPath && communityAddress