From 3a7400e4a8c0a6ec095042ea9f54dd4a47056444 Mon Sep 17 00:00:00 2001 From: Tommaso Casaburi Date: Mon, 16 Mar 2026 14:26:08 +0800 Subject: [PATCH] fix(reply-quote-preview): restore `(You)` for pseudonymous quotes (#1084) * fix(reply-quote-preview): restore (You) for pseudonymous quotes * test(reply-quote-preview): mock account comments hook --- .../__tests__/reply-quote-preview.test.tsx | 3 +++ .../reply-quote-preview/reply-quote-preview.tsx | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/reply-quote-preview/__tests__/reply-quote-preview.test.tsx b/src/components/reply-quote-preview/__tests__/reply-quote-preview.test.tsx index e2fd5b0d..ad7420e2 100644 --- a/src/components/reply-quote-preview/__tests__/reply-quote-preview.test.tsx +++ b/src/components/reply-quote-preview/__tests__/reply-quote-preview.test.tsx @@ -23,6 +23,7 @@ const testState = vi.hoisted(() => ({ address: '0xme', }, }, + accountComments: [] as Array<{ cid?: string }>, directories: [{ address: 'music-posting.eth', title: '/mu/ - Music' }] as Array<{ address: string; title?: string }>, isMobile: false, locationPath: '/mu/thread/thread-cid', @@ -58,6 +59,7 @@ vi.mock('react-router-dom', async () => { vi.mock('@bitsocialnet/bitsocial-react-hooks', () => ({ useAccount: () => testState.account, + useAccountComments: () => ({ accountComments: testState.accountComments }), })); vi.mock('@floating-ui/react', () => ({ @@ -173,6 +175,7 @@ describe('ReplyQuotePreview', () => { address: '0xme', }, }; + testState.accountComments = []; testState.directories = [{ address: 'music-posting.eth', title: '/mu/ - Music' }]; testState.isMobile = false; testState.locationPath = '/mu/thread/thread-cid'; diff --git a/src/components/reply-quote-preview/reply-quote-preview.tsx b/src/components/reply-quote-preview/reply-quote-preview.tsx index cb9d376b..b33afcea 100644 --- a/src/components/reply-quote-preview/reply-quote-preview.tsx +++ b/src/components/reply-quote-preview/reply-quote-preview.tsx @@ -1,7 +1,7 @@ import { useEffect, useRef, useState } from 'react'; import { createPortal } from 'react-dom'; import { Link, useLocation, useNavigate } from 'react-router-dom'; -import { Comment, useAccount } from '@bitsocialnet/bitsocial-react-hooks'; +import { Comment, useAccount, useAccountComments } from '@bitsocialnet/bitsocial-react-hooks'; import { useFloating, offset, shift, size, autoUpdate, Placement } from '@floating-ui/react'; import { useDirectories } from '../../hooks/use-directories'; import { getBoardPath } from '../../lib/utils/route-utils'; @@ -206,6 +206,7 @@ const DesktopQuotePreview = ({ ); const account = useAccount(); + const { accountComments } = useAccountComments(); const resolvedQuotelinkNumber = normalizedQuotelinkReply?.number ?? quotelinkNumber; const resolvedQuotelinkCid = normalizedQuotelinkReply?.cid; @@ -226,11 +227,14 @@ const DesktopQuotePreview = ({ quoteCid: resolvedQuotelinkCid, isUnavailable: quotelinkUnavailable, }); + const isOwnQuotelink = + (resolvedQuotelinkCid ? accountComments.some((comment) => comment.cid === resolvedQuotelinkCid) : false) || + normalizedQuotelinkReply?.author?.address === account?.author?.address; const quotelinkLabel = ( <> {formatQuoteNumber(resolvedQuotelinkNumber)} {isOP && ' (OP)'} - {normalizedQuotelinkReply?.author?.address === account?.author?.address && ' (You)'} + {isOwnQuotelink && ' (You)'} ); @@ -372,6 +376,7 @@ const MobileQuotePreview = ({ ); const account = useAccount(); + const { accountComments } = useAccountComments(); const resolvedQuotelinkNumber = normalizedQuotelinkReply?.number ?? quotelinkNumber; const resolvedQuotelinkCid = normalizedQuotelinkReply?.cid; const resolvedQuotelinkCommunityAddress = getCommentCommunityAddress(normalizedQuotelinkReply); @@ -385,6 +390,9 @@ const MobileQuotePreview = ({ quoteCid: resolvedQuotelinkCid, isUnavailable: quotelinkUnavailable, }); + const isOwnQuotelink = + (resolvedQuotelinkCid ? accountComments.some((comment) => comment.cid === resolvedQuotelinkCid) : false) || + normalizedQuotelinkReply?.author?.address === account?.author?.address; const replyQuotelink = ( <> @@ -396,7 +404,7 @@ const MobileQuotePreview = ({ > {formatQuoteNumber(resolvedQuotelinkNumber)} {isOP && ' (OP)'} - {normalizedQuotelinkReply?.author?.address === account?.author?.address && ' (You)'} + {isOwnQuotelink && ' (You)'} {!quotelinkUnavailable && !quotelinkPendingResolution &&