Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(console): New chat visibly answers when it reuses an empty chat

raullopez-sandboxa1cd5e9f8a50
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-row.tsx b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-row.tsx
index 81e39b618..746f6123c 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-row.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/components/chat-row.tsx
@@ -8,9 +8,11 @@ import {
DropdownMenuTrigger,
} from '@renderer/lib/ui/dropdown-menu';
import { RelativeTime } from '@renderer/lib/ui/relative-time';
+import { cn } from '@renderer/utils/utils';
import type { ChatSummary } from '@shared/core/chats/chats';
import { agentActivities } from '../stores/activities';
import { chatsStore } from '../stores/chats';
+import { reuseFlash } from '../stores/reuse-flash';
import { ChatActionItems, chatActions } from './chat-actions';
import { UnreadBadge } from './unread-badge';
@@ -38,9 +40,19 @@ export const ChatRow = observer(function ChatRow({
}) {
const [menuOpen, setMenuOpen] = useState(false);
const busy = chatBusy(serverId, chat);
+ const reused = reuseFlash.roomId === chat.roomId;
const actions = chatActions(serverId, chat);
return (
- <SidebarMenuRow className="group/row justify-between" isActive={isActive} onClick={onOpen}>
+ <SidebarMenuRow
+ className={cn(
+ 'group/row justify-between transition-colors duration-500',
+ // New chat reused this empty chat rather than making another: it says so.
+ reused && 'bg-[var(--sel-soft)] ring-1 ring-[var(--sel)]'
+ )}
+ data-reused={reused || undefined}
+ isActive={isActive}
+ onClick={onOpen}
+ >
<div className="flex h-6 min-w-0 flex-1 items-center gap-1">
<span className="flex size-6 shrink-0 items-center justify-center">
<MessageSquare className="size-4 text-foreground-muted" />
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/start-direct-chat.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/start-direct-chat.ts
index 9e267d8f7..cb7a7ae68 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/chats/start-direct-chat.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/start-direct-chat.ts
@@ -5,6 +5,7 @@ import { focusComposerWhenOpened } from './components/chat-composer';
import { chatsStore, chatTitler } from './stores/chats';
import { DirectChatStarter } from './stores/direct-chat-starter';
import { EmptyChatFinder } from './stores/empty-chat-finder';
+import { reuseFlash } from './stores/reuse-flash';
const emptyChatFinder = new EmptyChatFinder({
chatsOfAgent: (agentId) => chatsStore.chatsOfAgent(agentId),
@@ -25,6 +26,7 @@ export const directChats = new DirectChatStarter({
},
opened: (chat) => {
focusComposerWhenOpened(chat.roomId);
+ reuseFlash.flash(chat.roomId);
},
warm: (serverId, agentId, roomId) =>
void rpc.chats
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/reuse-flash.test.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/reuse-flash.test.ts
new file mode 100644
index 000000000..460693053
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/reuse-flash.test.ts
@@ -0,0 +1,19 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { REUSE_FLASH_MS, ReuseFlash } from './reuse-flash';
+
+afterEach(() => vi.useRealTimers());
+
+describe('ReuseFlash', () => {
+ it('marks the reused chat for a moment, the latest one only', () => {
+ vi.useFakeTimers();
+ const flash = new ReuseFlash();
+ flash.flash('r1');
+ expect(flash.roomId).toBe('r1');
+ vi.advanceTimersByTime(REUSE_FLASH_MS / 2);
+ flash.flash('r2');
+ vi.advanceTimersByTime(REUSE_FLASH_MS / 2);
+ expect(flash.roomId).toBe('r2');
+ vi.advanceTimersByTime(REUSE_FLASH_MS);
+ expect(flash.roomId).toBeNull();
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/chats/stores/reuse-flash.ts b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/reuse-flash.ts
new file mode 100644
index 000000000..a2b82a036
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/chats/stores/reuse-flash.ts
@@ -0,0 +1,31 @@
+import { makeAutoObservable } from 'mobx';
+
+/** How long a chat New chat reused stands out, so the click visibly did something. */
+export const REUSE_FLASH_MS = 1_500;
+
+/**
+ * The chat New chat just reused instead of making another: the same empty chat
+ * is shown again, often the one already open, and without a sign the click
+ * looks like it did nothing.
+ */
+export class ReuseFlash {
+ roomId: string | null = null;
+ private timer: ReturnType<typeof setTimeout> | null = null;
+
+ constructor() {
+ makeAutoObservable<ReuseFlash, 'timer'>(this, { timer: false });
+ }
+
+ flash(roomId: string): void {
+ this.roomId = roomId;
+ if (this.timer) clearTimeout(this.timer);
+ this.timer = setTimeout(() => this.clear(roomId), REUSE_FLASH_MS);
+ }
+
+ private clear(roomId: string): void {
+ if (this.roomId === roomId) this.roomId = null;
+ this.timer = null;
+ }
+}
+
+export const reuseFlash = new ReuseFlash();
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-row-reused.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-row-reused.test.tsx
new file mode 100644
index 000000000..88a0153b3
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/chat-row-reused.test.tsx
@@ -0,0 +1,43 @@
+/** A chat New chat reused stands out in the list for a moment, so the click visibly did something. */
+import { act } from 'react';
+import { createRoot } from 'react-dom/client';
+import { expect, it, vi } from 'vitest';
+import { ChatRow } from '@renderer/features/chats/components/chat-row';
+import { REUSE_FLASH_MS, reuseFlash } from '@renderer/features/chats/stores/reuse-flash';
+import type { ChatSummary } from '@shared/core/chats/chats';
+
+const chat = {
+ roomId: 'r1',
+ name: 'New Chat',
+ channelType: 'direct',
+ bridgeType: null,
+ channelName: null,
+ agents: [],
+ canManage: true,
+ ownsAgent: true,
+ memberUserIds: [],
+ memberCount: 1,
+ unreadCount: 0,
+ lastMessage: null,
+} as unknown as ChatSummary;
+
+it('highlights the reused chat, then lets it go', async () => {
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
+ const container = document.createElement('div');
+ document.body.appendChild(container);
+ const root = createRoot(container);
+ await act(async () =>
+ root.render(<ChatRow serverId="s" chat={chat} isActive onOpen={() => {}} />)
+ );
+ const row = () => container.querySelector('[data-reused]');
+ expect(row()).toBeNull();
+
+ await act(async () => reuseFlash.flash('r1'));
+ expect(row()).not.toBeNull();
+ await act(async () => vi.advanceTimersByTime(REUSE_FLASH_MS + 10));
+ expect(row()).toBeNull();
+
+ vi.useRealTimers();
+ await act(async () => root.unmount());
+ container.remove();
+});