Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(bots): exclude thread previews and controls from shared images

Dash42cc421eb8b7
diff --git a/apps/desktop/src/renderer/features/bots/BotGroupThreadViews.tsx b/apps/desktop/src/renderer/features/bots/BotGroupThreadViews.tsx
index a82b043418..b8e8625e5d 100644
--- a/apps/desktop/src/renderer/features/bots/BotGroupThreadViews.tsx
+++ b/apps/desktop/src/renderer/features/bots/BotGroupThreadViews.tsx
@@ -9,7 +9,7 @@ import { useTranslation } from 'react-i18next';
import { MarkdownRenderer } from '@/components/chat/MarkdownRenderer';
import { CHAT_BODY_CLASS } from '@/components/chat/chatChrome';
import { formatAbsolute, useRelativeTime } from '@/hooks/useRelativeTime';
-import { SHARE_MESSAGE_ATTR } from '@/lib/shareConversationImage';
+import { SHARE_EXCLUDE_ATTR, SHARE_MESSAGE_ATTR } from '@/lib/shareConversationImage';
import { cn } from '@/lib/utils';
import type {
BotGroupMemberView,
@@ -65,7 +65,7 @@ export function BotGroupThreadPreview({ message, members, align, onOpen }: {
const relative = useRelativeTime(latestAt, { hovered });
if (count <= 0) return null;
return (
- <button type="button" data-thread-preview={message.id}
+ <button type="button" data-thread-preview={message.id} {...{ [SHARE_EXCLUDE_ATTR]: '' }}
aria-label={t(key('open'), { count })} aria-describedby={replies.length ? linesId : undefined}
onClick={onOpen} onPointerEnter={() => setHovered(true)} onPointerLeave={() => setHovered(false)}
className={cn('group/thread flex w-full min-w-0 max-w-[520px] select-none flex-col gap-1.5 rounded-xl border border-[var(--border-default)] px-3 py-2 text-left transition-colors duration-[var(--motion-fast)] hover:bg-[var(--surface-hover)]',
@@ -139,7 +139,7 @@ export function BotGroupThreadShareQuote({ share, members, attachments, onOpenTh
</p>
)}
{/* Only a verified share leads anywhere: the card's own thread ID is not trusted. */}
- {onOpenThread && available ? <button type="button" onClick={onOpenThread}
+ {onOpenThread && available ? <button type="button" onClick={onOpenThread} {...{ [SHARE_EXCLUDE_ATTR]: '' }}
className={cn('-ml-1.5 inline-flex min-h-6 w-fit select-none items-center gap-1 rounded-full px-1.5 text-12 text-[var(--text-secondary)] transition-colors duration-[var(--motion-fast)] hover:bg-[var(--surface-hover)] hover:text-[var(--text-primary)]', FOCUS)}>
<CornerDownRight size={12} aria-hidden />
{t(key('viewThread'))}
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
index 849304d177..0a737a14ed 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/BotGroupChatView.test.tsx
@@ -5,7 +5,7 @@ import { Tooltip } from '@/components/ui/tooltip';
import userEvent from '@testing-library/user-event';
import { shareSelectionStore } from '@/components/chat/shareSelectionStore';
import { MarkdownMermaidBlock } from '@/components/chat/MarkdownMermaidBlock';
-import { queryShareableMessageIds } from '@/lib/shareConversationImage';
+import { prepareShareMessageClone, queryShareableMessageIds } from '@/lib/shareConversationImage';
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import { clearDraft, getDraft } from '@/lib/composerDraftStore';
@@ -2296,6 +2296,12 @@ describe('thread previews and posting to the main chat', () => {
// An attachment-only reply still says what it carried.
expect(card.textContent).toContain(t('attachmentsSummary'));
expect(card.textContent).toContain('bots.groupChat.server.replyCount');
+ // Export the selected root, without its independently selectable thread replies.
+ const exported = prepareShareMessageClone(card.closest('article')!)!;
+ expect(exported.textContent).toContain('去哪玩');
+ expect(exported.textContent).not.toContain('爬山吧,带上相机');
+ expect(exported.textContent).not.toContain('map.png');
+ expect(exported.querySelector('[data-thread-preview]')).toBeNull();
// The count lives in the preview; the toolbar keeps a plain reply icon.
const toolbarReply = screen.getByRole('button', { name: 'bots.groupChat.server.openTopic' });
expect(toolbarReply.textContent).toBe('');
@@ -2319,6 +2325,12 @@ describe('thread previews and posting to the main chat', () => {
expect(within(other).getByText('Alice')).toBeTruthy();
expect(within(other).getByText('原话:@咪咪 周六见')).toBeTruthy();
expect(within(other).queryByText('↪ 小满: fallback')).toBeNull();
+ // A selected share keeps the quoted reply and authors, but not navigation controls.
+ const exported = prepareShareMessageClone(other)!;
+ expect(exported.textContent).toContain('Alice');
+ expect(exported.textContent).toContain('小满');
+ expect(exported.textContent).toContain('原话:@咪咪 周六见');
+ expect(exported.textContent).not.toContain(t('viewThread'));
const own = screen.getByText(t('alsoSent')).closest('article')!;
expect(within(own).getByText('我自己的回复')).toBeTruthy();
expect(screen.getByText(t('sourceUnavailable'))).toBeTruthy();