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): Your Rooms lists your rooms, with All rooms for those who can read more

raullopez-sandbox7b2782d6cc07
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.ts
index d39129234..197defb32 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-filters.ts
@@ -60,3 +60,19 @@ export function withConsoleGroupChats(
if (added.length === 0) return rooms;
return [...rooms, ...added].sort((a, b) => a.name.localeCompare(b.name));
}
+
+/**
+ * Your rooms, then every other room you can read except Switch Console chats you
+ * are not in: the server will not open those to a non-member, admin or not.
+ */
+export function allReadableRooms(
+ yours: RemoteRoomSummary[],
+ readable: RemoteRoomSummary[]
+): RemoteRoomSummary[] {
+ const listed = new Set(yours.map((room) => room.id));
+ const more = readable.filter(
+ (room) => !listed.has(room.id) && (room.bridgeType !== null || room.viewerIsMember)
+ );
+ if (more.length === 0) return yours;
+ return [...yours, ...more].sort((a, b) => a.name.localeCompare(b.name));
+}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/server-rooms-view.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/server-rooms-view.tsx
index 901374821..ef8e94031 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/server-rooms-view.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/server-rooms-view.tsx
@@ -15,15 +15,17 @@ import { useShowModal } from '@renderer/lib/modal/modal-provider';
import { useWorkspaceAgents } from '@renderer/lib/stores/use-workspace-agents';
import { Button } from '@renderer/lib/ui/button';
import { SearchInput } from '@renderer/lib/ui/search-input';
+import { ToggleGroup, ToggleGroupItem } from '@renderer/lib/ui/toggle-group';
import { Tooltip, TooltipContent, TooltipTrigger } from '@renderer/lib/ui/tooltip';
import { cn } from '@renderer/utils/utils';
import type { RemoteRoomSummary } from '@shared/core/switch-servers/switch-servers';
+import { allReadableRooms } from './room-filters';
import { groupByMessagingApp, type RoomGroup } from './rooms-by-messaging-app';
import { ServerPage, ServerTableEmpty } from './server-page';
import { ServerSectionTitlebar } from './server-section-titlebar';
import { switchRoomsStore } from './switch-rooms-store';
import { switchServersStore } from './switch-servers-store';
-import { useReadableRoomsInWorkspace } from './use-listed-rooms';
+import { useListedRoomsInWorkspace, useReadableRoomsInWorkspace } from './use-listed-rooms';
function useServerId(): string {
return useParams('serverRooms').params.serverId;
@@ -44,7 +46,12 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
}, [serverId]);
const workspaceId = workspacesStore.idOnServerInScope(serverId);
- const rooms = useReadableRoomsInWorkspace(workspaceId);
+ const yours = useListedRoomsInWorkspace(workspaceId);
+ const all = allReadableRooms(yours, useReadableRoomsInWorkspace(workspaceId));
+ // Only someone who can read more than their own (an admin, or public rooms) gets the choice.
+ const [showAll, setShowAll] = useState(false);
+ const canShowAll = all.length > yours.length;
+ const rooms = showAll && canShowAll ? all : yours;
const signedOut = switchRoomsStore.workspacesNotSignedIn.some((w) => w.id === workspaceId);
const failed = switchRoomsStore.workspacesThatFailedToLoad.some((w) => w.id === workspaceId);
@@ -83,24 +90,41 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
<ServerTableEmpty>
This server&apos;s room list could not be read. Refresh from Home to try again.
</ServerTableEmpty>
- ) : rooms.length === 0 ? (
+ ) : all.length === 0 ? (
<ServerTableEmpty>
No rooms here yet. Create one to give your agents somewhere to work.
</ServerTableEmpty>
) : (
<div className="flex flex-col gap-6">
- <SearchInput
- value={filter}
- onChange={(e) => setFilter(e.target.value)}
- placeholder="Filter rooms by name…"
- aria-label="Filter rooms by name"
- />
+ <div className="flex items-center gap-2">
+ {canShowAll && (
+ <ToggleGroup
+ multiple={false}
+ value={[showAll ? 'all' : 'yours']}
+ onValueChange={([value]) => {
+ if (value) setShowAll(value === 'all');
+ }}
+ >
+ <ToggleGroupItem value="yours">Your rooms</ToggleGroupItem>
+ <ToggleGroupItem value="all">All rooms</ToggleGroupItem>
+ </ToggleGroup>
+ )}
+ <SearchInput
+ containerClassName="flex-1"
+ value={filter}
+ onChange={(e) => setFilter(e.target.value)}
+ placeholder="Filter rooms by name…"
+ aria-label="Filter rooms by name"
+ />
+ </div>
{/* The filter finding nothing is not the same as the server having no
rooms, and the empty state above answers a question this user is not
asking. */}
{groups.length === 0 ? (
<p className="py-2 text-sm text-foreground-muted">
- No room here matches “{filter.trim()}”.
+ {query === ''
+ ? 'You are in none of these rooms yet. Choose All rooms to see the rest.'
+ : `No room here matches “${filter.trim()}”.`}
</p>
) : (
groups.map((group) => (
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/server-stat-tiles.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/server-stat-tiles.tsx
index 34649b9f6..3b286cf2c 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/server-stat-tiles.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/server-stat-tiles.tsx
@@ -8,7 +8,7 @@ import {
} from '@renderer/features/managed-agents/use-managed-agents';
import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';
import { rpc } from '@renderer/lib/ipc';
-import { useReadableRoomsInWorkspace } from './use-listed-rooms';
+import { useListedRoomsInWorkspace } from './use-listed-rooms';
/**
* How much of this server Switch Console is holding: the agents onboarded
@@ -42,7 +42,7 @@ export const ServerStatTiles = observer(function ServerStatTiles({
// Counted the way the Your Agents page lists them: this Console's agents,
// less the ones the server runs, plus every agent the server runs.
const managed = useManagedAgents(serverId);
- const rooms = useReadableRoomsInWorkspace(workspaceId);
+ const rooms = useListedRoomsInWorkspace(workspaceId);
const agentCount =
!agentsStore.loaded || managed.isLoading
? null
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/use-listed-rooms.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/use-listed-rooms.ts
index 2aa2399fd..885b1f2b4 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/use-listed-rooms.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/use-listed-rooms.ts
@@ -37,13 +37,22 @@ export function useListedRoomsInActiveScope(): RemoteRoomSummary[] {
* chats follow.
*/
export function useReadableRoomsInWorkspace(workspaceId: string | null): RemoteRoomSummary[] {
+ return useRoomsInWorkspace(workspaceId, (id) => switchRoomsStore.readableRoomsInWorkspace(id));
+}
+
+/** {@link useReadableRoomsInWorkspace}, narrowed to the rooms the sidebar lists: yours. */
+export function useListedRoomsInWorkspace(workspaceId: string | null): RemoteRoomSummary[] {
+ return useRoomsInWorkspace(workspaceId, (id) => switchRoomsStore.listedRoomsInWorkspace(id));
+}
+
+function useRoomsInWorkspace(
+ workspaceId: string | null,
+ rooms: (workspaceId: string) => RemoteRoomSummary[]
+): RemoteRoomSummary[] {
const flags = useFeatureFlags(workspaceId && workspacesStore.serverIdFor(workspaceId));
if (workspaceId === null) return [];
return withConsoleGroupChats(
- filterConsoleDirectChats(
- switchRoomsStore.readableRoomsInWorkspace(workspaceId),
- flags.agent_chats
- ),
+ filterConsoleDirectChats(rooms(workspaceId), flags.agent_chats),
flags.agent_chats && workspaceId === workspacesStore.activeId ? chatsStore.chats.values() : []
);
}
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/server-stat-tiles.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/server-stat-tiles.test.tsx
index d4f62f60a..5ba59878f 100644
--- a/console/apps/switch-console-desktop/src/renderer/tests/browser/server-stat-tiles.test.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/server-stat-tiles.test.tsx
@@ -39,7 +39,7 @@ vi.mock('@renderer/features/managed-agents/use-managed-agents', async (importOri
const roomsData = vi.hoisted(() => ({ rooms: [] as unknown[] }));
vi.mock('@renderer/features/switch-servers/switch-rooms-store', () => ({
- switchRoomsStore: { workspacesNotSignedIn: [], readableRoomsInWorkspace: () => roomsData.rooms },
+ switchRoomsStore: { workspacesNotSignedIn: [], listedRoomsInWorkspace: () => roomsData.rooms },
}));
vi.mock('@renderer/features/workspaces/workspaces-store', () => ({
diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/your-rooms-view.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/your-rooms-view.test.tsx
new file mode 100644
index 000000000..9d486524e
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/your-rooms-view.test.tsx
@@ -0,0 +1,135 @@
+import { observable, runInAction } from 'mobx';
+/**
+ * Your Rooms lists the rooms the sidebar lists. Someone who can read more (an
+ * admin, or public rooms) can switch to All rooms, which never offers a Switch
+ * Console chat they are not in: the server would not open it.
+ */
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+import type { RemoteRoomSummary } from '@shared/core/switch-servers/switch-servers';
+
+vi.hoisted(() => {
+ window.electronAPI ??= {
+ invoke: () => Promise.resolve(undefined),
+ eventOn: () => () => {},
+ eventSend: () => {},
+ } as unknown as typeof window.electronAPI;
+});
+
+const rooms = vi.hoisted(() => ({ list: null as unknown as { all: RemoteRoomSummary[] } }));
+
+vi.mock('@renderer/lib/ipc', () => ({ events: { on: () => () => {} }, rpc: {} }));
+vi.mock('@renderer/lib/layout/navigation-provider', () => ({
+ useParams: () => ({ params: { serverId: 'srv' } }),
+}));
+vi.mock('@renderer/lib/modal/modal-provider', () => ({ useShowModal: () => () => {} }));
+vi.mock('@renderer/features/sidebar/sidebar-tree-data', () => ({
+ refreshSidebarRoomState: async () => {},
+ refreshSidebarRoomStateAfterOnboarding: async () => {},
+}));
+vi.mock('@renderer/features/switch-rooms/open-room', () => ({ openRoom: async () => {} }));
+vi.mock('@renderer/features/chats/components/unread-badge', () => ({ UnreadBadge: () => null }));
+vi.mock('@renderer/features/chats/stores/chats', () => ({ chatsStore: { chats: new Map() } }));
+vi.mock('@renderer/lib/stores/use-workspace-agents', () => ({
+ useWorkspaceAgents: () => ({ data: [] }),
+}));
+vi.mock('@renderer/features/locations/stores/agents-store', () => ({
+ agentsStore: { agentsOnServer: () => [] },
+}));
+vi.mock('@renderer/lib/hooks/useFeatureFlags', () => ({
+ useFeatureFlags: () => ({ agent_chats: true, group_chats: true }),
+}));
+vi.mock('@renderer/features/workspaces/workspaces-store', () => ({
+ workspacesStore: {
+ idOnServerInScope: () => 'ws',
+ serverIdFor: () => 'srv',
+ activeId: 'other',
+ },
+}));
+vi.mock('@renderer/features/switch-servers/switch-servers-store', () => ({
+ switchServersStore: { servers: [{ id: 'srv', name: 'Server' }] },
+}));
+// The store's own rule for "yours": owned, a member, or an agent of yours inside.
+vi.mock('@renderer/features/switch-servers/switch-rooms-store', () => ({
+ switchRoomsStore: {
+ workspacesNotSignedIn: [],
+ workspacesThatFailedToLoad: [],
+ localMemberIds: () => [],
+ listedRoomsInWorkspace: () =>
+ rooms.list.all.filter((room) => room.ownerId === 'me' || room.viewerIsMember),
+ readableRoomsInWorkspace: () => rooms.list.all,
+ },
+}));
+
+import { serverRoomsView } from '@renderer/features/switch-servers/server-rooms-view';
+
+function room(id: string, extra: Partial<RemoteRoomSummary>): RemoteRoomSummary {
+ return {
+ id,
+ name: id,
+ description: '',
+ channelType: 'group',
+ agentCount: 2,
+ bridgeDisplayName: null,
+ bridgeType: null,
+ externalChannelUrl: null,
+ ownerId: 'bob',
+ viewerIsMember: false,
+ archived: false,
+ createdAt: '',
+ ...extra,
+ };
+}
+
+let container: HTMLDivElement;
+let root: Root;
+
+beforeEach(() => {
+ rooms.list = observable({
+ all: [
+ room('bobs-chat', { viewerIsMember: true }),
+ room('strangers-chat', {}),
+ room('public-slack', { bridgeType: 'slack', bridgeDisplayName: 'Slack' }),
+ ],
+ });
+});
+
+afterEach(async () => {
+ await act(async () => root.unmount());
+ container.remove();
+});
+
+async function render(): Promise<void> {
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+ const Panel = serverRoomsView.MainPanel;
+ await act(async () => root.render(<Panel />));
+}
+
+const names = () =>
+ [...container.querySelectorAll('button.group\\/room span.truncate')].map((s) => s.textContent);
+const toggle = (label: string) =>
+ [...container.querySelectorAll('button')].find((b) => b.textContent === label);
+
+it('lists your rooms by default, and drops a chat once you are removed from it', async () => {
+ await render();
+ expect(names()).toEqual(['bobs-chat']);
+ await act(async () => runInAction(() => (rooms.list.all[0].viewerIsMember = false)));
+ expect(names()).toEqual([]);
+});
+
+it('offers All rooms to someone who can read more: bridged rooms, never chats they are not in', async () => {
+ await render();
+ await act(async () => toggle('All rooms')!.click());
+ expect(names()).toEqual(['#public-slack', 'bobs-chat']);
+ await act(async () => runInAction(() => (rooms.list.all[0].viewerIsMember = false)));
+ expect(names()).toEqual(['#public-slack']);
+});
+
+it('offers no choice to someone who can read only their own rooms', async () => {
+ rooms.list.all = [room('bobs-chat', { viewerIsMember: true })];
+ await render();
+ expect(toggle('All rooms')).toBeUndefined();
+});