Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

💄 style(channel): show a direct conversation as a 1:1 chat (#22331)

Arvin Xu3d9fb21438a1
diff --git a/locales/en-US/channel.json b/locales/en-US/channel.json
index 18159a4152c..13aa64b7565 100644
--- a/locales/en-US/channel.json
+++ b/locales/en-US/channel.json
@@ -47,6 +47,7 @@
"deleteThreadSuccess": "Thread moved to trash",
"deletedMember": "Former member",
"deviceRequired": "Choose an online device and a working directory for each coding Agent.",
+ "directComposer": "Message {{name}}",
"directoryRequired": "Choose a working directory for each device.",
"environment.agentUnavailable": "This Agent is no longer available. Remove it and choose another.",
"environment.checkingDevice": "Checking status",
diff --git a/locales/zh-CN/channel.json b/locales/zh-CN/channel.json
index 414f579c3ed..6054e14ac58 100644
--- a/locales/zh-CN/channel.json
+++ b/locales/zh-CN/channel.json
@@ -47,6 +47,7 @@
"deleteThreadSuccess": "线程已移至回收站",
"deletedMember": "已离开的成员",
"deviceRequired": "请为编程 Agent 选择在线设备和工作目录。",
+ "directComposer": "发消息给 {{name}}",
"directoryRequired": "请为每台设备选择工作目录。",
"environment.agentUnavailable": "此 Agent 已不可用,请移除后选择其他 Agent。",
"environment.checkingDevice": "正在确认状态",
diff --git a/packages/locales/src/default/channel.ts b/packages/locales/src/default/channel.ts
index 3906af016c7..acf09144c79 100644
--- a/packages/locales/src/default/channel.ts
+++ b/packages/locales/src/default/channel.ts
@@ -92,6 +92,7 @@ export default {
'send': 'Send',
'sendFailed': 'Message was not sent. Your draft is preserved; try again.',
'composer': 'Message #{{name}}',
+ 'directComposer': 'Message {{name}}',
'threadComposer': 'Reply in thread',
'stopReply': 'Stop reply',
'main': 'Channel conversation',
diff --git a/src/features/Channels/ChannelConversation.tsx b/src/features/Channels/ChannelConversation.tsx
index 6c787874dd8..eb690c18419 100644
--- a/src/features/Channels/ChannelConversation.tsx
+++ b/src/features/Channels/ChannelConversation.tsx
@@ -109,11 +109,13 @@ const Timeline = ({
if (!sending.current) reply.select(message);
};
const channelArchived = detail?.channel.status === 'archived';
- // Join lines belong to the main conversation; a thread starts from its root message.
+ const direct = !!detail?.channel.agentId;
+ // Join lines belong to the main conversation; a thread starts from its root message. A direct
+ // conversation reads like a chat with its Agent, so it has no "invited" lines at all.
const timeline = detail
? channelTimeline(
detail.messages,
- threadId ? [] : channelJoinEvents(detail.members),
+ threadId || direct ? [] : channelJoinEvents(detail.members),
!detail.hasMore && before === undefined,
)
: [];
@@ -187,10 +189,11 @@ const Timeline = ({
}
/>
)}
+ {/* A new direct conversation starts blank, like an IM chat. */}
{!timeline.length &&
(threadId ? (
<p {...stylex.props(styles.muted)}>{t('threadEmpty')}</p>
- ) : (
+ ) : direct ? null : (
<Empty icon={MessageSquare} title={t('conversationEmpty')} />
))}
{presentChannelTimeline(timeline).map(({ item, date, startsDay, continuation }) => (
@@ -239,7 +242,9 @@ const Timeline = ({
replyTarget={reply.target}
threadId={threadId}
placeholder={
- threadId ? t('threadComposer') : t('composer', { name: detail.channel.title })
+ threadId
+ ? t('threadComposer')
+ : t(direct ? 'directComposer' : 'composer', { name: detail.channel.title })
}
onCancelReply={() => reply.clear()}
onSend={async (content, mentions, requestKey, fileIds, replyToId) => {
diff --git a/src/features/Channels/Composer.tsx b/src/features/Channels/Composer.tsx
index e22999ba543..17d3ece1096 100644
--- a/src/features/Channels/Composer.tsx
+++ b/src/features/Channels/Composer.tsx
@@ -8,10 +8,10 @@ import {
ReactMentionPlugin,
} from '@lobehub/editor';
import { ChatInput, Editor, SendButton, useEditor } from '@lobehub/editor/react';
-import { ActionIcon, Flexbox, Text, Upload } from '@lobehub/ui';
+import { ActionIcon, cssVar, Flexbox, Text, Upload } from '@lobehub/ui';
import * as stylex from '@stylexjs/stylex';
import { $getSelection, $isRangeSelection } from 'lexical';
-import { Paperclip, Reply, X } from 'lucide-react';
+import { CirclePlus, Reply, X } from 'lucide-react';
import type { ReactNode } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -48,6 +48,14 @@ import type { ChannelReplyTarget } from './useReplyTarget';
const plugins = [ReactCodePlugin, ReactListPlugin, ReactLinkHighlightPlugin, ReactMentionPlugin];
+/** A flat filled bar, like an IM message box, instead of the chat page's raised card. */
+const inputShell = {
+ backgroundColor: cssVar.colorFillTertiary,
+ borderColor: 'transparent',
+ borderRadius: 12,
+ boxShadow: 'none',
+};
+
export function Composer({
activity,
channel,
@@ -176,6 +184,7 @@ export function Composer({
maxHeight={480}
minHeight={0}
resize={false}
+ style={inputShell}
styles={{ body: { overflow: 'visible', padding: 0 } }}
header={
replyTarget || preview ? (
@@ -223,8 +232,8 @@ export function Composer({
<ActionIcon
aria-label={t('attachments.upload')}
disabled={busy || !canUpload}
- icon={Paperclip}
- size={{ blockSize: 28, size: 16 }}
+ icon={CirclePlus}
+ size={{ blockSize: 28, size: 20 }}
title={reason || t('attachments.upload')}
/>
</Upload>
@@ -321,15 +330,17 @@ export function Composer({
/>
</div>
{/* Replies run asynchronously, so Send never turns into Stop; each reply stops from the activity line. */}
- {/* An empty composer keeps Send as a quiet icon, like an IM; it fills once there is a draft. */}
- <SendButton
- aria-label={t('send')}
- disabled={busy || !hasDraft || attachments.blocked}
- loading={busy}
- size={28}
- type={hasDraft ? 'primary' : 'text'}
- onSend={() => void send()}
- />
+ {/* Enter sends; like an IM, the button only appears once there is something to send. */}
+ {(hasDraft || busy) && (
+ <SendButton
+ aria-label={t('send')}
+ disabled={busy || attachments.blocked}
+ loading={busy}
+ size={28}
+ type="primary"
+ onSend={() => void send()}
+ />
+ )}
</div>
</ChatInput>
{(error || invites.error) && (
diff --git a/src/features/Channels/MemberStatus.test.tsx b/src/features/Channels/MemberStatus.test.tsx
new file mode 100644
index 00000000000..9b9b2bc2d3d
--- /dev/null
+++ b/src/features/Channels/MemberStatus.test.tsx
@@ -0,0 +1,90 @@
+/**
+ * @vitest-environment happy-dom
+ */
+import { fireEvent, render, screen } from '@testing-library/react';
+import { createElement } from 'react';
+import { describe, expect, it, vi } from 'vitest';
+
+import { MemberStatus } from './MemberStatus';
+
+const { openEnvironment } = vi.hoisted(() => ({ openEnvironment: vi.fn() }));
+
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+vi.mock('@lobehub/ui', () => ({
+ ActionIcon: ({ title }: { title?: string }) => createElement('button', {}, title),
+ Button: () => null,
+ // Lists the menu flat so each action can be read and clicked.
+ DropdownMenu: ({ items }: { items: any[] }) =>
+ createElement(
+ 'ul',
+ {},
+ items
+ .filter((item) => item.key)
+ .map((item) => createElement('li', { key: item.key, onClick: item.onClick }, item.key)),
+ ),
+ Flexbox: ({ children }: { children?: unknown }) => createElement('div', {}, children as never),
+ Popover: () => null,
+ Text: () => null,
+}));
+vi.mock('@/features/Workspace/useWorkspaceAwareNavigate', () => ({
+ useWorkspaceAwareNavigate: () => () => {},
+}));
+vi.mock('@/hooks/useCloseOnNavigate', () => ({ useCloseOnNavigate: () => 0 }));
+vi.mock('./AgentEnvironment', () => ({ openChannelAgentEnvironment: openEnvironment }));
+vi.mock('./CreateChannel', () => ({ openInviteMembers: () => {} }));
+vi.mock('./FailureIndicator', () => ({ FailureIndicator: () => null }));
+vi.mock('./MemberList', () => ({
+ MemberList: () => null,
+ StatusAvatar: () => null,
+ useMemberEntries: ({ members }: { members: any[] }) =>
+ members.map((member) => ({ member, name: member.name })),
+}));
+vi.mock('./useChannelMenu', () => ({
+ useChannelMenu: () => () => [
+ { key: 'rename' },
+ { key: 'copyId' },
+ { key: 'archive' },
+ { type: 'divider' },
+ { key: 'delete' },
+ ],
+}));
+
+const cook = { agentId: 'agt_cook', id: 'mem_cook', name: 'Cook', status: 'active' };
+const detail = (channel: Record<string, unknown> = {}, member: Record<string, unknown> = {}) =>
+ ({
+ channel: {
+ agentId: 'agt_cook',
+ canDelete: true,
+ id: 'chn_cook',
+ status: 'active',
+ workspaceId: null,
+ ...channel,
+ },
+ members: [{ ...cook, ...member }],
+ }) as never;
+
+const menuKeys = () => screen.getAllByRole('listitem').map((item) => item.textContent);
+
+describe('MemberStatus in a direct conversation', () => {
+ // The roster is hidden in a direct conversation, and it held the only way to set up a coding
+ // Agent's device and working directory for the Channel.
+ it('keeps the Agent environment setup in the menu', () => {
+ render(createElement(MemberStatus, { detail: detail() }));
+
+ expect(menuKeys()).toEqual(['openAgent', 'environment', 'copyId', 'archive', 'delete']);
+ fireEvent.click(screen.getByText('environment'));
+ expect(openEnvironment).toHaveBeenCalledWith('chn_cook', expect.objectContaining(cook));
+ });
+
+ it('offers no environment setup once the conversation is archived', () => {
+ render(createElement(MemberStatus, { detail: detail({ status: 'archived' }) }));
+
+ expect(menuKeys()).not.toContain('environment');
+ });
+
+ it('offers no environment setup when the Agent has left', () => {
+ render(createElement(MemberStatus, { detail: detail({}, { status: 'removed' }) }));
+
+ expect(menuKeys()).not.toContain('environment');
+ });
+});
diff --git a/src/features/Channels/MemberStatus.tsx b/src/features/Channels/MemberStatus.tsx
index e3b519227db..a8bd20a4d67 100644
--- a/src/features/Channels/MemberStatus.tsx
+++ b/src/features/Channels/MemberStatus.tsx
@@ -1,23 +1,28 @@
import { CHANNEL_URL } from '@lobechat/const';
import type { ChannelDetail } from '@lobechat/types';
-import { ActionIcon, Button, Flexbox, Popover, Text } from '@lobehub/ui';
+import { ActionIcon, Button, DropdownMenu, Flexbox, Popover, Text } from '@lobehub/ui';
import * as stylex from '@stylexjs/stylex';
-import { UserPlus, Users } from 'lucide-react';
+import { Bot, FolderCog, MoreHorizontal, UserPlus, Users } from 'lucide-react';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
import { useCloseOnNavigate } from '@/hooks/useCloseOnNavigate';
+import { openChannelAgentEnvironment } from './AgentEnvironment';
import { canInviteMembers } from './channelAccess';
import { openInviteMembers } from './CreateChannel';
import { FailureIndicator } from './FailureIndicator';
import { MemberList, StatusAvatar, useMemberEntries } from './MemberList';
import { statusStyles, styles } from './styles';
+import { useChannelMenu } from './useChannelMenu';
/** Header avatars before the rest fold into a count; the list shows everyone. */
const MAX_VISIBLE = 5;
+/** Channel actions a direct conversation keeps; renaming would drift from the Agent's name. */
+const DIRECT_MENU_KEYS = new Set(['copyId', 'archive', 'unarchive', 'delete']);
+
/**
* Members as avatars with live status dots. One click lists everyone by name, because
* Agents often share the default avatar and a long roster would not fit the header.
@@ -38,13 +43,47 @@ export function MemberStatus({
const directAgent = channel.agentId
? entries.find((entry) => entry.member.agentId === channel.agentId)
: undefined;
+ const channelMenu = useChannelMenu();
const overflow = entries.length - MAX_VISIBLE;
const title = t('membersCount', { count: entries.length });
+ const direct = !!channel.agentId;
+ const inviteSize = direct ? undefined : 'small';
+ // A direct conversation is a chat with one Agent: no roster to show, only its actions, like an
+ // IM header. Its title is the Agent's name, so it cannot be renamed here.
+ const directMenu = () => [
+ ...(directAgent
+ ? [
+ {
+ icon: Bot,
+ key: 'openAgent',
+ label: t('openAgentNamed', { name: directAgent.name }),
+ onClick: () => navigate(`/agent/${channel.agentId}`),
+ },
+ // The member list is hidden here, so its device and directory setup lives in this menu.
+ ...(directAgent.member.status === 'active' &&
+ channel.canDelete &&
+ channel.status !== 'archived'
+ ? [
+ {
+ icon: FolderCog,
+ key: 'environment',
+ label: t('environment.title'),
+ onClick: () => openChannelAgentEnvironment(channel.id, directAgent.member),
+ },
+ ]
+ : []),
+ { type: 'divider' as const },
+ ]
+ : []),
+ ...channelMenu(channel).filter(
+ (item) => !('key' in item) || DIRECT_MENU_KEYS.has(String(item.key)),
+ ),
+ ];
return (
<Flexbox horizontal align="center" gap={4}>
<FailureIndicator detail={detail} />
- {memberPanel ? (
+ {direct ? null : memberPanel ? (
<ActionIcon
active={memberPanel.open}
aria-controls={memberPanel.open ? memberPanel.id : undefined}
@@ -87,7 +126,7 @@ export function MemberStatus({
<ActionIcon
aria-label={t('invite.title')}
icon={UserPlus}
- size="small"
+ size={inviteSize}
title={t('invite.title')}
onClick={() =>
openInviteMembers(
@@ -105,6 +144,15 @@ export function MemberStatus({
}
/>
)}
+ {direct && (
+ <DropdownMenu items={directMenu()}>
+ <ActionIcon
+ aria-label={t('more', { ns: 'common' })}
+ icon={MoreHorizontal}
+ title={t('more', { ns: 'common' })}
+ />
+ </DropdownMenu>
+ )}
</Flexbox>
);
}
diff --git a/src/features/Channels/index.tsx b/src/features/Channels/index.tsx
index de727f37428..1ca5ff30cb3 100644
--- a/src/features/Channels/index.tsx
+++ b/src/features/Channels/index.tsx
@@ -14,6 +14,7 @@ import { serverConfigSelectors, useServerConfigStore } from '@/store/serverConfi
import { visibleChannelDetail } from './channelAccess';
import { ChannelConversation } from './ChannelConversation';
+import { MemberAvatar } from './MemberAvatar';
import { MEMBER_FLOAT_BREAKPOINT, MemberPanel } from './MemberPanel';
import { MemberStatus } from './MemberStatus';
import { styles } from './styles';
@@ -33,6 +34,10 @@ function EnabledChannelPage() {
const view = { channelId: channelId ?? '', threadId: null };
const sync = channelActions.useFetchDetail(channelId ? view : null);
const detail = visibleChannelDetail(useChannelStore(channelSelectors.detail(view)), sync.error);
+ // A direct conversation is titled by its Agent, so it shows the Agent rather than a `#`.
+ const directAgent = detail?.channel.agentId
+ ? detail.members.find((member) => member.agentId === detail.channel.agentId)
+ : undefined;
const membersOpen =
!!detail?.channel.workspaceId &&
membersChannelId === channelId &&
@@ -45,7 +50,7 @@ function EnabledChannelPage() {
<NavHeader
left={
<Flexbox horizontal align="center" gap={8}>
- <Hash size={18} />
+ {directAgent ? <MemberAvatar member={directAgent} size={24} /> : <Hash size={18} />}
<Text ellipsis weight={500}>
{detail?.channel.title || t('title')}
</Text>
diff --git a/src/features/Channels/styles.ts b/src/features/Channels/styles.ts
index 8b962217f72..8019a58ea69 100644
--- a/src/features/Channels/styles.ts
+++ b/src/features/Channels/styles.ts
@@ -190,16 +190,17 @@ export const styles = stylex.create({
composerRow: {
display: 'flex',
alignItems: 'flex-end',
- gap: 4,
- paddingBlock: 4,
- paddingInline: 4,
+ gap: 8,
+ minHeight: 44,
+ paddingBlock: 8,
+ paddingInline: 8,
},
composerEditor: {
overflowY: 'auto',
flex: '1',
minWidth: 0,
maxHeight: 240,
- paddingBlock: 0,
+ paddingBlock: 2,
},
/** Takes the composer's place while the channel or thread is archived. */
archivedNotice: {
diff --git a/src/features/MessageList/AgentConversation.tsx b/src/features/MessageList/AgentConversation.tsx
index 9653f254a3a..5820d4020be 100644
--- a/src/features/MessageList/AgentConversation.tsx
+++ b/src/features/MessageList/AgentConversation.tsx
@@ -89,6 +89,7 @@ const AgentConversation = memo<AgentConversationProps>(({ active, conversation }
return (
<ConversationRow
+ closeOnReselect
active={active}
activeAt={activeAt}
contextMenuItems={menuItems}
diff --git a/src/features/MessageList/ChannelConversation.tsx b/src/features/MessageList/ChannelConversation.tsx
index 6658a1177f4..6a327293ada 100644
--- a/src/features/MessageList/ChannelConversation.tsx
+++ b/src/features/MessageList/ChannelConversation.tsx
@@ -25,6 +25,7 @@ const ChannelConversation = memo<ChannelConversationProps>(({ active, activeAt,
return (
<ConversationRow
+ closeOnReselect
active={active}
activeAt={activeAt}
contextMenuItems={menuItems(channel)}
diff --git a/src/features/MessageList/ConversationRow.test.tsx b/src/features/MessageList/ConversationRow.test.tsx
new file mode 100644
index 00000000000..53d3e579f34
--- /dev/null
+++ b/src/features/MessageList/ConversationRow.test.tsx
@@ -0,0 +1,74 @@
+/**
+ * @vitest-environment happy-dom
+ */
+import { fireEvent, render, screen } from '@testing-library/react';
+import { createElement } from 'react';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import ConversationRow from './ConversationRow';
+
+const navigate = vi.fn();
+
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+vi.mock('@/features/Workspace/useWorkspaceAwareNavigate', () => ({
+ useWorkspaceAwareNavigate: () => navigate,
+}));
+vi.mock('@/features/Workspace/WorkspaceLink', () => ({
+ default: ({ to, ...rest }: { to: string }) => createElement('a', { href: to, ...rest }),
+}));
+
+const renderRow = (active: boolean, onClick = vi.fn(), closeOnReselect = true) => {
+ render(
+ createElement(ConversationRow, {
+ active,
+ avatar: null,
+ closeOnReselect,
+ onClick,
+ title: 'Dario',
+ url: '/channels/chn_dario',
+ }),
+ );
+ return { onClick, row: screen.getByRole('link', { name: 'Dario' }) };
+};
+
+describe('ConversationRow', () => {
+ beforeEach(() => navigate.mockClear());
+
+ it('closes the open conversation when it is clicked again', () => {
+ const { onClick, row } = renderRow(true);
+
+ const event = new MouseEvent('click', { bubbles: true, button: 0, cancelable: true });
+ fireEvent(row, event);
+
+ expect(event.defaultPrevented).toBe(true);
+ expect(navigate).toHaveBeenCalledWith('/');
+ expect(onClick).not.toHaveBeenCalled();
+ });
+
+ it('opens an inactive conversation through its own click handling', () => {
+ const { onClick, row } = renderRow(false);
+
+ fireEvent.click(row);
+
+ expect(navigate).not.toHaveBeenCalled();
+ expect(onClick).toHaveBeenCalledTimes(1);
+ });
+
+ // Directory rows (the contacts tab) open a profile, so a second click must not leave it.
+ it('keeps the open row selected when it does not close on reselect', () => {
+ const { onClick, row } = renderRow(true, vi.fn(), false);
+
+ fireEvent.click(row);
+
+ expect(navigate).not.toHaveBeenCalled();
+ expect(onClick).toHaveBeenCalledTimes(1);
+ });
+
+ it('leaves a modified click on the open conversation to the link', () => {
+ const { row } = renderRow(true);
+
+ fireEvent.click(row, { metaKey: true });
+
+ expect(navigate).not.toHaveBeenCalled();
+ });
+});
diff --git a/src/features/MessageList/ConversationRow.tsx b/src/features/MessageList/ConversationRow.tsx
index a759f8b346f..99b8b6d6512 100644
--- a/src/features/MessageList/ConversationRow.tsx
+++ b/src/features/MessageList/ConversationRow.tsx
@@ -5,15 +5,21 @@ import * as stylex from '@stylexjs/stylex';
import { type ComponentProps, memo, type MouseEvent, type ReactNode, type Ref } from 'react';
import { useTranslation } from 'react-i18next';
-import WorkspaceLink from '@/features/Workspace/WorkspaceLink';
+import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
+import WorkspaceLink, { type WorkspaceLinkProps } from '@/features/Workspace/WorkspaceLink';
-import { formatConversationTime } from './conversations';
+import { formatConversationTime, isPlainClick } from './conversations';
import { styles } from './style';
export interface ConversationRowProps {
active?: boolean;
activeAt?: Date;
avatar: ReactNode;
+ /**
+ * Clicking the open conversation again closes it, back to the Messages home with no row
+ * selected. Off for directory lists, whose rows open a profile rather than a conversation.
+ */
+ closeOnReselect?: boolean;
contextMenuItems?: ComponentProps<typeof ContextMenuTrigger>['items'];
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
onMouseEnter?: () => void;
@@ -30,9 +36,32 @@ export interface ConversationRowProps {
url: string;
}
+/** A row link that leaves the conversation when it is already open. Modified clicks keep the link. */
+const CloseOnReselectLink = ({
+ active,
+ onClick,
+ ...rest
+}: WorkspaceLinkProps & { active?: boolean }) => {
+ const navigate = useWorkspaceAwareNavigate();
+ return (
+ <WorkspaceLink
+ {...rest}
+ onClick={(event) => {
+ if (active && isPlainClick(event)) {
+ event.preventDefault();
+ navigate('/');
+ return;
+ }
+ onClick?.(event);
+ }}
+ />
+ );
+};
+
const ConversationRow = memo<ConversationRowProps>(
({
active,
+ closeOnReselect,
activeAt,
avatar,
contextMenuItems,
@@ -48,17 +77,18 @@ const ConversationRow = memo<ConversationRowProps>(
url,
}) => {
const { t } = useTranslation('common');
+ const link: WorkspaceLinkProps = {
+ 'aria-current': active ? 'page' : undefined,
+ 'aria-label': title,
+ ref,
+ ...stylex.props(styles.row, pinned && styles.rowPinned, active && styles.rowActive),
+ 'to': url,
+ onClick,
+ onMouseEnter,
+ };
- const row = (
- <WorkspaceLink
- aria-current={active ? 'page' : undefined}
- aria-label={title}
- ref={ref}
- {...stylex.props(styles.row, pinned && styles.rowPinned, active && styles.rowActive)}
- to={url}
- onClick={onClick}
- onMouseEnter={onMouseEnter}
- >
+ const content = (
+ <>
<span {...stylex.props(styles.avatar)}>
{avatar}
{!!unread && unread > 0 && (
@@ -90,7 +120,14 @@ const ConversationRow = memo<ConversationRowProps>(
</Flexbox>
)}
</Flexbox>
- </WorkspaceLink>
+ </>
+ );
+ const row = closeOnReselect ? (
+ <CloseOnReselectLink {...link} active={active}>
+ {content}
+ </CloseOnReselectLink>
+ ) : (
+ <WorkspaceLink {...link}>{content}</WorkspaceLink>
);
return contextMenuItems ? (
diff --git a/src/features/MessageList/GroupConversation.test.tsx b/src/features/MessageList/GroupConversation.test.tsx
index f98c5803741..8af75dd856f 100644
--- a/src/features/MessageList/GroupConversation.test.tsx
+++ b/src/features/MessageList/GroupConversation.test.tsx
@@ -17,6 +17,9 @@ vi.mock('@/features/HomeSidebar/Body/Agent/List/AgentGroupItem/useDropdownMenu',
return () => [];
},
}));
+vi.mock('@/features/Workspace/useWorkspaceAwareNavigate', () => ({
+ useWorkspaceAwareNavigate: () => () => {},
+}));
vi.mock('@/features/Workspace/WorkspaceLink', () => ({
default: ({ ref, to: _to, ...rest }: { ref?: (el: HTMLElement | null) => void; to: string }) =>
createElement('a', { ...rest, ref }),
diff --git a/src/features/MessageList/GroupConversation.tsx b/src/features/MessageList/GroupConversation.tsx
index 46411ae8654..e8db16458a9 100644
--- a/src/features/MessageList/GroupConversation.tsx
+++ b/src/features/MessageList/GroupConversation.tsx
@@ -40,6 +40,7 @@ const GroupConversation = memo<GroupConversationProps>(({ active, conversation }
return (
<ConversationRow
+ closeOnReselect
active={active}
activeAt={activeAt}
contextMenuItems={contextMenuItems}
diff --git a/src/features/MessageList/InboxConversation.tsx b/src/features/MessageList/InboxConversation.tsx
index 64b0e70a0c6..1acff8fc7b5 100644
--- a/src/features/MessageList/InboxConversation.tsx
+++ b/src/features/MessageList/InboxConversation.tsx
@@ -32,6 +32,7 @@ const InboxConversation = memo<{ activeRouteId?: string; preview?: string }>(
return (
<ConversationRow
+ closeOnReselect
active={active}
preview={preview || meta.description || undefined}
running={running}
diff --git a/src/features/MessageList/conversations.ts b/src/features/MessageList/conversations.ts
index 6d9fede8455..e408e0f48ee 100644
--- a/src/features/MessageList/conversations.ts
+++ b/src/features/MessageList/conversations.ts
@@ -2,6 +2,11 @@ import type { ChannelListItem, RecentItem, SidebarAgentItem } from '@lobechat/ty
import { markdownToTxt } from '@/utils/markdownToTxt';
+/** A plain left click; modified clicks keep the browser's own handling of the link. */
+export const isPlainClick = (
+ event: Pick<MouseEvent, 'altKey' | 'button' | 'ctrlKey' | 'metaKey' | 'shiftKey'>,
+) => event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
+
export interface Conversation {
/** Latest activity: the newer of the item itself and its latest topic. */
activeAt: Date;
diff --git a/src/features/MessageList/useAgentConversationLink.ts b/src/features/MessageList/useAgentConversationLink.ts
index 4341556e3cd..8e9a2f1cbba 100644
--- a/src/features/MessageList/useAgentConversationLink.ts
+++ b/src/features/MessageList/useAgentConversationLink.ts
@@ -8,9 +8,7 @@ import { useActiveLocation } from '@/hooks/useActiveLocation';
import { cacheScope } from '@/libs/replica';
import { channelActions, channelSelectors, useChannelStore } from '@/store/channel';
-/** A plain left click; modified clicks keep the browser's own handling of the link. */
-const isPlainClick = (event: MouseEvent) =>
- event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey;
+import { isPlainClick } from './conversations';
/**
* With Channels on, an agent row opens the person's direct Channel with the Agent. An Agent made