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
This commit is contained in:
Tommaso Casaburi
2026-03-16 14:26:08 +08:00
committed by GitHub
parent 6f1305c2ad
commit 3a7400e4a8
2 changed files with 14 additions and 3 deletions
@@ -23,6 +23,7 @@ const testState = vi.hoisted(() => ({
address: '0xme', address: '0xme',
}, },
}, },
accountComments: [] as Array<{ cid?: string }>,
directories: [{ address: 'music-posting.eth', title: '/mu/ - Music' }] as Array<{ address: string; title?: string }>, directories: [{ address: 'music-posting.eth', title: '/mu/ - Music' }] as Array<{ address: string; title?: string }>,
isMobile: false, isMobile: false,
locationPath: '/mu/thread/thread-cid', locationPath: '/mu/thread/thread-cid',
@@ -58,6 +59,7 @@ vi.mock('react-router-dom', async () => {
vi.mock('@bitsocialnet/bitsocial-react-hooks', () => ({ vi.mock('@bitsocialnet/bitsocial-react-hooks', () => ({
useAccount: () => testState.account, useAccount: () => testState.account,
useAccountComments: () => ({ accountComments: testState.accountComments }),
})); }));
vi.mock('@floating-ui/react', () => ({ vi.mock('@floating-ui/react', () => ({
@@ -173,6 +175,7 @@ describe('ReplyQuotePreview', () => {
address: '0xme', address: '0xme',
}, },
}; };
testState.accountComments = [];
testState.directories = [{ address: 'music-posting.eth', title: '/mu/ - Music' }]; testState.directories = [{ address: 'music-posting.eth', title: '/mu/ - Music' }];
testState.isMobile = false; testState.isMobile = false;
testState.locationPath = '/mu/thread/thread-cid'; testState.locationPath = '/mu/thread/thread-cid';
@@ -1,7 +1,7 @@
import { useEffect, useRef, useState } from 'react'; import { useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom'; import { createPortal } from 'react-dom';
import { Link, useLocation, useNavigate } from 'react-router-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 { useFloating, offset, shift, size, autoUpdate, Placement } from '@floating-ui/react';
import { useDirectories } from '../../hooks/use-directories'; import { useDirectories } from '../../hooks/use-directories';
import { getBoardPath } from '../../lib/utils/route-utils'; import { getBoardPath } from '../../lib/utils/route-utils';
@@ -206,6 +206,7 @@ const DesktopQuotePreview = ({
); );
const account = useAccount(); const account = useAccount();
const { accountComments } = useAccountComments();
const resolvedQuotelinkNumber = normalizedQuotelinkReply?.number ?? quotelinkNumber; const resolvedQuotelinkNumber = normalizedQuotelinkReply?.number ?? quotelinkNumber;
const resolvedQuotelinkCid = normalizedQuotelinkReply?.cid; const resolvedQuotelinkCid = normalizedQuotelinkReply?.cid;
@@ -226,11 +227,14 @@ const DesktopQuotePreview = ({
quoteCid: resolvedQuotelinkCid, quoteCid: resolvedQuotelinkCid,
isUnavailable: quotelinkUnavailable, isUnavailable: quotelinkUnavailable,
}); });
const isOwnQuotelink =
(resolvedQuotelinkCid ? accountComments.some((comment) => comment.cid === resolvedQuotelinkCid) : false) ||
normalizedQuotelinkReply?.author?.address === account?.author?.address;
const quotelinkLabel = ( const quotelinkLabel = (
<> <>
{formatQuoteNumber(resolvedQuotelinkNumber)} {formatQuoteNumber(resolvedQuotelinkNumber)}
{isOP && ' (OP)'} {isOP && ' (OP)'}
{normalizedQuotelinkReply?.author?.address === account?.author?.address && ' (You)'} {isOwnQuotelink && ' (You)'}
</> </>
); );
@@ -372,6 +376,7 @@ const MobileQuotePreview = ({
); );
const account = useAccount(); const account = useAccount();
const { accountComments } = useAccountComments();
const resolvedQuotelinkNumber = normalizedQuotelinkReply?.number ?? quotelinkNumber; const resolvedQuotelinkNumber = normalizedQuotelinkReply?.number ?? quotelinkNumber;
const resolvedQuotelinkCid = normalizedQuotelinkReply?.cid; const resolvedQuotelinkCid = normalizedQuotelinkReply?.cid;
const resolvedQuotelinkCommunityAddress = getCommentCommunityAddress(normalizedQuotelinkReply); const resolvedQuotelinkCommunityAddress = getCommentCommunityAddress(normalizedQuotelinkReply);
@@ -385,6 +390,9 @@ const MobileQuotePreview = ({
quoteCid: resolvedQuotelinkCid, quoteCid: resolvedQuotelinkCid,
isUnavailable: quotelinkUnavailable, isUnavailable: quotelinkUnavailable,
}); });
const isOwnQuotelink =
(resolvedQuotelinkCid ? accountComments.some((comment) => comment.cid === resolvedQuotelinkCid) : false) ||
normalizedQuotelinkReply?.author?.address === account?.author?.address;
const replyQuotelink = ( const replyQuotelink = (
<> <>
@@ -396,7 +404,7 @@ const MobileQuotePreview = ({
> >
{formatQuoteNumber(resolvedQuotelinkNumber)} {formatQuoteNumber(resolvedQuotelinkNumber)}
{isOP && ' (OP)'} {isOP && ' (OP)'}
{normalizedQuotelinkReply?.author?.address === account?.author?.address && ' (You)'} {isOwnQuotelink && ' (You)'}
</span> </span>
{!quotelinkUnavailable && {!quotelinkUnavailable &&
!quotelinkPendingResolution && !quotelinkPendingResolution &&