Skip to content

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

Rooms: cards instead of a table; filter by app connection; archive from a card's menu

Simon Flack8874c75190ca
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
index d138db720..8fb71b227 100644
--- a/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/gateway-client.ts
@@ -3297,6 +3297,7 @@ type RoomSummaryJson = {
description: string;
channel_type: string | null;
agent_count: number;
+ bridge_id?: string | null;
bridge_display_name: string | null;
bridge_type?: string | null;
external_channel_url?: string | null;
@@ -3335,6 +3336,7 @@ function mapRoomSummary(r: RoomSummaryJson): RemoteRoomSummary {
// The same reading as a room's detail, so the list and the room page offer the same changes.
writeVisibility: visibilityOf(r.write_visibility),
...(r.read_visibility !== undefined ? { readVisibility: visibilityOf(r.read_visibility) } : {}),
+ ...(r.bridge_id !== undefined ? { bridgeId: r.bridge_id } : {}),
...(r.group_id !== undefined ? { groupId: r.group_id, groupName: r.group_name ?? null } : {}),
...(r.owner_name !== undefined ? { ownerName: r.owner_name } : {}),
...(r.connected_user_count !== undefined ? { connectedUserCount: r.connected_user_count } : {}),
diff --git a/console/apps/switch-console-desktop/src/main/core/switch-servers/room-summary.test.ts b/console/apps/switch-console-desktop/src/main/core/switch-servers/room-summary.test.ts
new file mode 100644
index 000000000..27bf48cbc
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/main/core/switch-servers/room-summary.test.ts
@@ -0,0 +1,122 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+
+const getSessionCookie = vi.hoisted(() => vi.fn());
+const refreshSession = vi.hoisted(() => vi.fn());
+const reauthenticateManagedServer = vi.hoisted(() => vi.fn());
+
+const managedServerHostBlocked = vi.hoisted(() => vi.fn(() => null));
+const managedServerStoppedPhase = vi.hoisted(() => vi.fn(() => null));
+const noteManagedServerUnanswered = vi.hoisted(() => vi.fn());
+
+vi.mock('@main/core/managed-switch-server/managed-server-status', () => ({
+ managedServerHostBlocked,
+ managedServerStoppedPhase,
+ noteManagedServerUnanswered,
+}));
+
+vi.mock('./servers-store', () => ({ getSessionCookie }));
+vi.mock('./auth', () => ({ refreshSession, reauthenticateManagedServer }));
+vi.mock('./console-identity', () => ({ consoleIdentityHeaders: async () => ({}) }));
+
+const { fetchRooms } = await import('./gateway-client');
+
+const SERVER = {
+ id: 'srv-1',
+ name: 'S',
+ url: 'https://switch.example.com',
+ managed: false,
+} as never;
+
+/** A far-from-expiry JWT, so no renewal path is exercised here. */
+function validJwt(): string {
+ const header = Buffer.from(JSON.stringify({ alg: 'HS256', typ: 'JWT' })).toString('base64url');
+ const exp = Math.floor(Date.now() / 1000) + 24 * 60 * 60;
+ const payload = Buffer.from(JSON.stringify({ sub: 'u1', exp })).toString('base64url');
+ return `${header}.${payload}.sig`;
+}
+
+function response(body: unknown): Response {
+ return {
+ status: 200,
+ ok: true,
+ json: async () => body,
+ headers: { get: () => null, getSetCookie: () => [] },
+ text: async () => JSON.stringify(body),
+ } as unknown as Response;
+}
+
+const BASE = {
+ id: 'room-1',
+ name: 'launch-review',
+ description: 'Launch checks',
+ channel_type: 'channel_private',
+ agent_count: 2,
+ bridge_display_name: 'Acme Slack',
+ bridge_type: 'slack',
+ archived: false,
+ created_at: '2026-01-01T00:00:00Z',
+};
+
+const fetchMock = vi.fn();
+
+describe('the room list as Console reads it', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ vi.stubGlobal('fetch', fetchMock);
+ getSessionCookie.mockResolvedValue(validJwt());
+ });
+
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ });
+
+ it('carries what the Rooms page shows: connection, group, owner, access and people', async () => {
+ fetchMock.mockResolvedValue(
+ response([
+ {
+ ...BASE,
+ bridge_id: 'b-acme',
+ group_id: 'g1',
+ group_name: 'Design',
+ owner_id: 'u2',
+ owner_name: 'Max Tam',
+ read_visibility: 'public',
+ write_visibility: 'private',
+ connected_user_count: 4,
+ viewer_is_member: true,
+ can_write: false,
+ can_manage: false,
+ },
+ ])
+ );
+
+ const [room] = await fetchRooms(SERVER);
+ expect(room).toMatchObject({
+ bridgeId: 'b-acme',
+ groupId: 'g1',
+ groupName: 'Design',
+ ownerName: 'Max Tam',
+ readVisibility: 'public',
+ writeVisibility: 'private',
+ connectedUserCount: 4,
+ viewerIsMember: true,
+ serverPermissions: { canWrite: false, canManage: false, canUnlink: false },
+ });
+ });
+
+ it('leaves out what an older server does not send, rather than inventing it', async () => {
+ fetchMock.mockResolvedValue(response([BASE]));
+
+ const [room] = await fetchRooms(SERVER);
+ for (const key of [
+ 'bridgeId',
+ 'groupId',
+ 'ownerName',
+ 'readVisibility',
+ 'connectedUserCount',
+ 'serverPermissions',
+ ])
+ expect(room).not.toHaveProperty(key);
+ expect(room.viewerIsMember).toBe(false);
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-card.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-card.tsx
new file mode 100644
index 000000000..b63fbb913
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-card.tsx
@@ -0,0 +1,154 @@
+import {
+ Archive,
+ ArchiveRestore,
+ Bot,
+ Lock,
+ MessagesSquare,
+ MoreVertical,
+ User,
+} from 'lucide-react';
+import { ACCESS_LABELS } from '@renderer/features/switch-rooms/room-settings-sections';
+import { BridgeIcon, hasBridgeIcon } from '@renderer/lib/components/bridge-icon';
+import { Badge } from '@renderer/lib/ui/badge';
+import { Button } from '@renderer/lib/ui/button';
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuTrigger,
+} from '@renderer/lib/ui/dropdown-menu';
+import { Tooltip, TooltipContent, TooltipTrigger } from '@renderer/lib/ui/tooltip';
+import { ACCESS_SHORT, countText, ownerText, type RoomCard as RoomCardData } from './room-list';
+
+/** The mark of an app connection: its platform's icon, or Switch Console's. */
+export function AppMark({ bridgeType, size = 14 }: { bridgeType: string | null; size?: number }) {
+ return hasBridgeIcon(bridgeType) ? (
+ <BridgeIcon bridgeType={bridgeType} size={size} className="shrink-0" />
+ ) : (
+ <MessagesSquare
+ className="shrink-0 text-foreground-muted"
+ style={{ width: size, height: size }}
+ />
+ );
+}
+
+/**
+ * One room on the Rooms page. The whole card opens it; the menu at its top
+ * right holds what can be done from here (archiving), and is there only when
+ * the server lets you.
+ */
+export function RoomCard({
+ card,
+ showYours,
+ onOpen,
+ onArchive,
+}: {
+ card: RoomCardData;
+ /** Marks your rooms "Yours": in All rooms, where they sit among everyone's. */
+ showYours: boolean;
+ onOpen: () => void;
+ /** Archives the room, or unarchives an archived one; null when you may not. */
+ onArchive: (() => void) | null;
+}) {
+ const owner = ownerText(card);
+ return (
+ <div
+ data-room-card={card.id}
+ className="group relative flex min-h-[168px] flex-col rounded-[11px] border border-border bg-background transition-colors hover:border-border-1"
+ >
+ <button
+ type="button"
+ aria-label={`Open ${card.name}`}
+ className="focus-visible:ring-ring absolute inset-0 cursor-pointer rounded-[11px] focus-visible:ring-2 focus-visible:outline-none"
+ onClick={onOpen}
+ />
+ <div className="pointer-events-none flex flex-1 flex-col gap-2 p-4">
+ <div className={`flex items-center gap-2${onArchive ? ' pr-8' : ''}`}>
+ <span className="relative flex shrink-0">
+ <AppMark bridgeType={card.bridgeType} size={18} />
+ {card.privateChannel && (
+ <span
+ role="img"
+ aria-label="Private"
+ title="Only the people in it can reach it"
+ className="absolute -right-1.5 -bottom-1.5 flex size-3.5 items-center justify-center rounded-full bg-background ring-1 ring-border"
+ >
+ <Lock className="size-2 text-foreground" />
+ </span>
+ )}
+ </span>
+ <h3 className="min-w-0 truncate font-medium text-foreground">{card.name}</h3>
+ {showYours && card.mine && <Badge variant="secondary">Yours</Badge>}
+ </div>
+ <p className="line-clamp-2 text-sm text-foreground-muted">
+ {card.description || <span className="italic">No description.</span>}
+ </p>
+ <p className="flex min-w-0 items-center gap-1 text-xs text-foreground-muted">
+ <AppMark bridgeType={card.bridgeType} size={12} />
+ <span className="truncate">
+ {[card.appLabel, card.groupName].filter(Boolean).join(' · ')}
+ </span>
+ {card.access && (
+ <>
+ <span aria-hidden>·</span>
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <span className="pointer-events-auto relative">
+ {ACCESS_SHORT[card.access]}
+ </span>
+ }
+ />
+ <TooltipContent>{ACCESS_LABELS[card.access]}</TooltipContent>
+ </Tooltip>
+ </>
+ )}
+ </p>
+ <div className="mt-auto flex flex-col gap-1.5 border-t border-border pt-2.5 text-xs text-foreground-muted">
+ {owner && <span className="truncate">{owner}</span>}
+ <span className="flex items-center gap-3">
+ <span className="flex items-center gap-1">
+ <Bot className="size-3.5" />
+ {countText(card.agentCount, 'agent', 'agents')}
+ </span>
+ {card.peopleCount !== null && (
+ <span className="flex items-center gap-1">
+ <User className="size-3.5" />
+ {countText(card.peopleCount, 'person', 'people')}
+ </span>
+ )}
+ </span>
+ </div>
+ </div>
+ {onArchive && (
+ <div className="absolute top-2.5 right-2.5">
+ <DropdownMenu>
+ <DropdownMenuTrigger
+ render={
+ <Button
+ variant="ghost"
+ size="sm"
+ className="size-7 p-0"
+ aria-label={`${card.name} actions`}
+ >
+ <MoreVertical className="size-4" />
+ </Button>
+ }
+ />
+ <DropdownMenuContent align="end">
+ <DropdownMenuItem onClick={onArchive}>
+ {card.archived ? (
+ <ArchiveRestore className="size-4" />
+ ) : (
+ <Archive className="size-4" />
+ )}
+ {/* The room is hidden for everyone, not just you. */}
+ {card.archived ? 'Unarchive' : 'Archive for everyone'}
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-list.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-list.test.ts
new file mode 100644
index 000000000..97ab45755
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-list.test.ts
@@ -0,0 +1,158 @@
+import { describe, expect, it } from 'vitest';
+import type { RemoteRoomSummary } from '@shared/core/switch-servers/switch-servers';
+import {
+ appOptions,
+ countText,
+ filterRoomCards,
+ groupOptions,
+ NO_FILTER,
+ offeredFilter,
+ ownerText,
+ roomCard,
+} from './room-list';
+
+function room(extra: Partial<RemoteRoomSummary>): RemoteRoomSummary {
+ return {
+ id: 'r',
+ name: 'room',
+ description: '',
+ channelType: 'channel_public',
+ agentCount: 1,
+ bridgeId: 'b-acme',
+ bridgeDisplayName: 'Acme Slack',
+ bridgeType: 'slack',
+ externalChannelUrl: null,
+ ownerId: 'u-2',
+ viewerIsMember: false,
+ isConsoleChat: false,
+ archived: false,
+ createdAt: '2026-10-01T09:00:00Z',
+ ...extra,
+ };
+}
+
+const VIEWER = { id: 'u-1' };
+
+describe('a room as the Rooms page shows it', () => {
+ it('names its app, group, owner and access, and counts its agents and people', () => {
+ const card = roomCard(
+ room({
+ description: 'Launch checks',
+ groupId: 'g1',
+ groupName: 'Design',
+ ownerName: 'Max Tam',
+ readVisibility: 'public',
+ writeVisibility: 'private',
+ connectedUserCount: 6,
+ }),
+ VIEWER
+ );
+ expect(card).toMatchObject({
+ description: 'Launch checks',
+ appKey: 'b-acme',
+ appLabel: 'Acme Slack',
+ groupName: 'Design',
+ access: 'read_only',
+ agentCount: 1,
+ peopleCount: 6,
+ privateChannel: false,
+ });
+ expect(ownerText(card)).toBe('Owned by Max Tam');
+ });
+
+ it('says who owns it in words, you included, and nothing when the server does not say', () => {
+ expect(ownerText(roomCard(room({ ownerId: 'u-1' }), VIEWER))).toBe('Owned by you');
+ expect(ownerText(roomCard(room({ ownerId: null }), VIEWER))).toBeNull();
+ });
+
+ it('marks a private channel private', () => {
+ expect(roomCard(room({ channelType: 'channel_private' }), VIEWER).privateChannel).toBe(true);
+ });
+
+ it('puts a Console chat in Switch Console, private to its members, its people not known', () => {
+ const card = roomCard(
+ room({
+ bridgeId: null,
+ bridgeType: null,
+ bridgeDisplayName: null,
+ isConsoleChat: true,
+ connectedUserCount: 0,
+ }),
+ VIEWER
+ );
+ expect(card).toMatchObject({
+ appLabel: 'Switch Console',
+ access: 'private',
+ peopleCount: null,
+ });
+ });
+
+ it('says nothing about access a server does not report', () => {
+ expect(roomCard(room({}), VIEWER).access).toBeNull();
+ });
+
+ it('counts a room as yours when the server says so, or when Console lists it as yours', () => {
+ expect(roomCard(room({ viewerIsMember: true }), VIEWER).mine).toBe(true);
+ expect(roomCard(room({}), { ...VIEWER, listedIds: new Set(['r']) }).mine).toBe(true);
+ expect(roomCard(room({}), VIEWER).mine).toBe(false);
+ });
+
+ it('counts in words', () => {
+ expect(countText(1, 'agent', 'agents')).toBe('1 agent');
+ expect(countText(0, 'person', 'people')).toBe('0 people');
+ });
+});
+
+describe('filtering the Rooms page', () => {
+ const cards = [
+ roomCard(room({ id: 'b', name: 'beta', groupId: 'g1', groupName: 'Design' }), VIEWER),
+ roomCard(
+ room({ id: 'a', name: 'Alpha', bridgeId: null, bridgeType: null, bridgeDisplayName: null }),
+ VIEWER
+ ),
+ roomCard(
+ room({ id: 'c', name: 'gamma', bridgeId: 'b-partners', bridgeDisplayName: 'Partners Slack' }),
+ VIEWER
+ ),
+ // A second connection under the same name as the first: still its own choice.
+ roomCard(room({ id: 'd', name: 'delta', bridgeId: 'b-acme-2' }), VIEWER),
+ ];
+
+ it('sorts by name and matches the search in any case', () => {
+ expect(filterRoomCards(cards, NO_FILTER).map((card) => card.id)).toEqual(['a', 'b', 'd', 'c']);
+ expect(filterRoomCards(cards, { ...NO_FILTER, query: ' ALP ' }).map((card) => card.id)).toEqual(
+ ['a']
+ );
+ });
+
+ it('narrows to one app connection and one group', () => {
+ expect(filterRoomCards(cards, { ...NO_FILTER, app: 'b-acme' }).map((card) => card.id)).toEqual([
+ 'b',
+ ]);
+ expect(filterRoomCards(cards, { ...NO_FILTER, groupId: 'g1' }).map((card) => card.id)).toEqual([
+ 'b',
+ ]);
+ });
+
+ it('offers each app connection by its name, with its platform, Switch Console last', () => {
+ expect(appOptions(cards)).toEqual([
+ { value: 'b-acme', label: 'Acme Slack', bridgeType: 'slack' },
+ { value: 'b-acme-2', label: 'Acme Slack', bridgeType: 'slack' },
+ { value: 'b-partners', label: 'Partners Slack', bridgeType: 'slack' },
+ { value: 'switch-console', label: 'Switch Console', bridgeType: null },
+ ]);
+ expect(groupOptions(cards)).toEqual([{ id: 'g1', name: 'Design' }]);
+ });
+
+ it('drops an app or group no longer offered, keeping the search', () => {
+ const picked = { query: 'be', app: 'b-gone', groupId: 'g1' };
+ expect(offeredFilter(picked, appOptions(cards), [])).toEqual({
+ query: 'be',
+ app: null,
+ groupId: null,
+ });
+ expect(
+ offeredFilter({ ...picked, app: 'b-acme' }, appOptions(cards), groupOptions(cards))
+ ).toEqual({ query: 'be', app: 'b-acme', groupId: 'g1' });
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-list.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-list.ts
new file mode 100644
index 000000000..9acf30ffe
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/room-list.ts
@@ -0,0 +1,172 @@
+import { bridgePlatformLabel } from '@renderer/lib/components/bridge-platform';
+import {
+ type RemoteRoomSummary,
+ type RoomAccess,
+ roomAccessOf,
+} from '@shared/core/switch-servers/switch-servers';
+
+/** One room as the Rooms page shows it, on its card. */
+export type RoomCard = {
+ id: string;
+ name: string;
+ description: string;
+ /**
+ * Which messaging app connection it is on, or Switch Console: the
+ * connection's id, so two Slack workspaces stay two choices even under the
+ * same name.
+ */
+ appKey: string;
+ /** The connection's own name ("Acme Slack"), or Switch Console. */
+ appLabel: string;
+ bridgeType: string | null;
+ /** A private channel on its app, or a Console chat, which only its members reach. */
+ privateChannel: boolean;
+ isConsoleChat: boolean;
+ groupId: string | null;
+ groupName: string | null;
+ ownedByYou: boolean;
+ /** Null when the server names no owner. */
+ ownerName: string | null;
+ /** Null when the server does not say. */
+ access: RoomAccess | null;
+ agentCount: number;
+ /** Null when not known: the server counts only the people on a room's messaging app. */
+ peopleCount: number | null;
+ createdAt: string;
+ /** You own it, take part in it, or have an agent in it. */
+ mine: boolean;
+ archived: boolean;
+};
+
+/** The short word a card shows for a room's access; the full sentence is its tooltip. */
+export const ACCESS_SHORT: Record<RoomAccess, string> = {
+ public: 'Open',
+ read_only: 'Read-only',
+ private: 'Private',
+};
+
+export const CONSOLE_APP_LABEL = 'Switch Console';
+const CONSOLE_APP_KEY = 'switch-console';
+
+export function roomCard(
+ room: RemoteRoomSummary,
+ viewer: {
+ id: string | null;
+ /** Rooms Console lists as yours, for a server that does not say which are. */
+ listedIds?: ReadonlySet<string>;
+ }
+): RoomCard {
+ const isConsoleChat = room.isConsoleChat;
+ const bridged = room.bridgeType !== null;
+ return {
+ id: room.id,
+ name: room.name,
+ description: room.description,
+ appKey: bridged
+ ? (room.bridgeId ?? `${room.bridgeType}:${room.bridgeDisplayName ?? ''}`)
+ : CONSOLE_APP_KEY,
+ appLabel: bridged
+ ? (room.bridgeDisplayName ?? bridgePlatformLabel(room.bridgeType))
+ : CONSOLE_APP_LABEL,
+ bridgeType: room.bridgeType,
+ privateChannel: isConsoleChat || room.channelType === 'channel_private',
+ isConsoleChat,
+ groupId: room.groupId ?? null,
+ groupName: room.groupName ?? null,
+ ownedByYou: viewer.id !== null && room.ownerId === viewer.id,
+ ownerName: room.ownerName ?? null,
+ // A Console chat is made readable only by its members.
+ access: isConsoleChat
+ ? 'private'
+ : room.readVisibility && room.writeVisibility
+ ? roomAccessOf(room.readVisibility, room.writeVisibility)
+ : null,
+ agentCount: room.agentCount,
+ // The server's count is of accounts on the room's app, so a room with no
+ // app always reads 0 whoever is in it: not known, rather than none.
+ peopleCount: bridged ? (room.connectedUserCount ?? null) : null,
+ createdAt: room.createdAt,
+ mine: room.viewerIsMember || (viewer.listedIds?.has(room.id) ?? false),
+ archived: room.archived,
+ };
+}
+
+/** "Owned by you", "Owned by Ada", or null when the server names no owner. */
+export function ownerText(card: Pick<RoomCard, 'ownedByYou' | 'ownerName'>): string | null {
+ if (card.ownedByYou) return 'Owned by you';
+ return card.ownerName ? `Owned by ${card.ownerName}` : null;
+}
+
+export function countText(count: number, one: string, many: string): string {
+ return `${count} ${count === 1 ? one : many}`;
+}
+
+export type RoomsFilter = {
+ query: string;
+ /** An app key, or null for any. */
+ app: string | null;
+ /** A group id, or null for any. */
+ groupId: string | null;
+};
+
+export const NO_FILTER: RoomsFilter = { query: '', app: null, groupId: null };
+
+export type AppOption = { value: string; label: string; bridgeType: string | null };
+
+/** The rooms that match the search and the app and group picked, in name order. */
+export function filterRoomCards(cards: readonly RoomCard[], filter: RoomsFilter): RoomCard[] {
+ const query = filter.query.trim().toLowerCase();
+ return cards
+ .filter((card) => query === '' || card.name.toLowerCase().includes(query))
+ .filter((card) => filter.app === null || card.appKey === filter.app)
+ .filter((card) => filter.groupId === null || card.groupId === filter.groupId)
+ .sort((a, b) => a.name.localeCompare(b.name));
+}
+
+/** Each app connection the rooms are on, once, by name, Switch Console last. */
+export function appOptions(cards: readonly RoomCard[]): AppOption[] {
+ const byKey = new Map<string, AppOption>();
+ for (const card of cards) {
+ if (!byKey.has(card.appKey))
+ byKey.set(card.appKey, {
+ value: card.appKey,
+ label: card.appLabel,
+ bridgeType: card.bridgeType,
+ });
+ }
+ return [...byKey.values()].sort((a, b) =>
+ a.value === CONSOLE_APP_KEY
+ ? 1
+ : b.value === CONSOLE_APP_KEY
+ ? -1
+ : a.label.localeCompare(b.label)
+ );
+}
+
+/** The groups the rooms are filed under, each once, in name order. */
+export function groupOptions(cards: readonly RoomCard[]): { id: string; name: string }[] {
+ const byId = new Map<string, string>();
+ for (const card of cards) {
+ if (card.groupId !== null) byId.set(card.groupId, card.groupName ?? 'Unnamed group');
+ }
+ return [...byId].map(([id, name]) => ({ id, name })).sort((a, b) => a.name.localeCompare(b.name));
+}
+
+/**
+ * `filter` without an app or group no longer offered: one picked among the
+ * active rooms that has none archived, say. Kept, it would hide every room
+ * while its dropdown, which lists only what is offered, read "Any".
+ */
+export function offeredFilter(
+ filter: RoomsFilter,
+ apps: readonly AppOption[],
+ groups: readonly { id: string }[]
+): RoomsFilter {
+ const app = filter.app !== null && apps.some((each) => each.value === filter.app);
+ const group = filter.groupId !== null && groups.some((each) => each.id === filter.groupId);
+ return {
+ query: filter.query,
+ app: app ? filter.app : null,
+ groupId: group ? filter.groupId : null,
+ };
+}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/rooms-table.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/rooms-table.test.ts
deleted file mode 100644
index 065f1bb26..000000000
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/rooms-table.test.ts
+++ /dev/null
@@ -1,103 +0,0 @@
-import { describe, expect, it } from 'vitest';
-import type { RemoteRoomSummary } from '@shared/core/switch-servers/switch-servers';
-import { appOptions, filterRoomRows, groupOptions, NO_FILTER, roomRow } from './rooms-table';
-
-function room(extra: Partial<RemoteRoomSummary>): RemoteRoomSummary {
- return {
- id: 'r',
- name: 'room',
- description: '',
- channelType: 'channel_public',
- agentCount: 1,
- bridgeDisplayName: 'Acme Slack',
- bridgeType: 'slack',
- externalChannelUrl: null,
- ownerId: 'u-2',
- viewerIsMember: false,
- isConsoleChat: false,
- archived: false,
- createdAt: '2026-10-01T09:00:00Z',
- ...extra,
- };
-}
-
-describe('a room as the Rooms table shows it', () => {
- it('names its app, group, owner and access, and counts its agents and people', () => {
- expect(
- roomRow(
- room({
- groupId: 'g1',
- groupName: 'Design',
- ownerName: 'Max Tam',
- readVisibility: 'public',
- writeVisibility: 'private',
- connectedUserCount: 6,
- }),
- 'u-1'
- )
- ).toMatchObject({
- appLabel: 'Acme Slack',
- groupName: 'Design',
- ownerLabel: 'Max Tam',
- access: 'read_only',
- agentCount: 1,
- peopleCount: 6,
- privateChannel: false,
- });
- });
-
- it('calls your own rooms yours, and a private channel private', () => {
- const row = roomRow(room({ ownerId: 'u-1', channelType: 'channel_private' }), 'u-1');
- expect(row.ownerLabel).toBe('You');
- expect(row.privateChannel).toBe(true);
- });
-
- it('puts a Console chat in Switch Console, private to its members', () => {
- const row = roomRow(
- room({ bridgeType: null, bridgeDisplayName: null, isConsoleChat: true }),
- null
- );
- expect(row).toMatchObject({ appLabel: 'Switch Console', access: 'private' });
- });
-
- it('says nothing about access a server does not report', () => {
- expect(roomRow(room({}), null).access).toBeNull();
- });
-});
-
-describe('filtering the Rooms table', () => {
- const rows = [
- roomRow(room({ id: 'b', name: 'beta', groupId: 'g1', groupName: 'Design' }), null),
- roomRow(room({ id: 'a', name: 'Alpha', bridgeType: null, bridgeDisplayName: null }), null),
- roomRow(
- room({
- id: 'c',
- name: 'gamma',
- bridgeDisplayName: 'Ops Mattermost',
- bridgeType: 'mattermost',
- }),
- null
- ),
- ];
-
- it('sorts by name and matches the search in any case', () => {
- expect(filterRoomRows(rows, NO_FILTER).map((row) => row.id)).toEqual(['a', 'b', 'c']);
- expect(filterRoomRows(rows, { ...NO_FILTER, query: ' ALP ' }).map((row) => row.id)).toEqual([
- 'a',
- ]);
- });
-
- it('narrows to one app and one group', () => {
- expect(filterRoomRows(rows, { ...NO_FILTER, app: 'Acme Slack' }).map((row) => row.id)).toEqual([
- 'b',
- ]);
- expect(filterRoomRows(rows, { ...NO_FILTER, groupId: 'g1' }).map((row) => row.id)).toEqual([
- 'b',
- ]);
- });
-
- it('offers the apps and groups the rows have, Switch Console last', () => {
- expect(appOptions(rows)).toEqual(['Acme Slack', 'Ops Mattermost', 'Switch Console']);
- expect(groupOptions(rows)).toEqual([{ id: 'g1', name: 'Design' }]);
- });
-});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/rooms-table.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/rooms-table.ts
deleted file mode 100644
index 3799598ce..000000000
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/rooms-table.ts
+++ /dev/null
@@ -1,105 +0,0 @@
-import { bridgePlatformLabel } from '@renderer/lib/components/bridge-platform';
-import {
- type RemoteRoomSummary,
- type RoomAccess,
- roomAccessOf,
-} from '@shared/core/switch-servers/switch-servers';
-
-/** One room as the Rooms table shows it. */
-export type RoomRow = {
- id: string;
- name: string;
- /** The messaging app it lives in, by its own name ("Acme Slack"), or Switch Console. */
- appLabel: string;
- bridgeType: string | null;
- /** A private channel on its app, or a Console chat, which only its members reach. */
- privateChannel: boolean;
- isConsoleChat: boolean;
- groupId: string | null;
- groupName: string | null;
- /** "You" for your own rooms; null when the server names no owner. */
- ownerLabel: string | null;
- /** Null when the server does not say. */
- access: RoomAccess | null;
- agentCount: number;
- /** Null when the server does not say. */
- peopleCount: number | null;
- createdAt: string;
- /** You own it, take part in it, or have an agent in it. */
- mine: boolean;
- archived: boolean;
-};
-
-/** The short word the table shows for a room's access; the full sentence is its tooltip. */
-export const ACCESS_SHORT: Record<RoomAccess, string> = {
- public: 'Open',
- read_only: 'Read-only',
- private: 'Private',
-};
-
-export const CONSOLE_APP_LABEL = 'Switch Console';
-
-export function roomRow(room: RemoteRoomSummary, viewerId: string | null): RoomRow {
- const isConsoleChat = room.isConsoleChat;
- return {
- id: room.id,
- name: room.name,
- appLabel: room.bridgeType
- ? (room.bridgeDisplayName ?? bridgePlatformLabel(room.bridgeType))
- : CONSOLE_APP_LABEL,
- bridgeType: room.bridgeType,
- privateChannel: isConsoleChat || room.channelType === 'channel_private',
- isConsoleChat,
- groupId: room.groupId ?? null,
- groupName: room.groupName ?? null,
- ownerLabel: viewerId !== null && room.ownerId === viewerId ? 'You' : (room.ownerName ?? null),
- // A Console chat is made readable only by its members.
- access: isConsoleChat
- ? 'private'
- : room.readVisibility && room.writeVisibility
- ? roomAccessOf(room.readVisibility, room.writeVisibility)
- : null,
- agentCount: room.agentCount,
- peopleCount: room.connectedUserCount ?? null,
- createdAt: room.createdAt,
- mine: room.viewerIsMember,
- archived: room.archived,
- };
-}
-
-export type RoomsFilter = {
- query: string;
- /** An app label, or null for any. */
- app: string | null;
- /** A group id, or null for any. */
- groupId: string | null;
-};
-
-export const NO_FILTER: RoomsFilter = { query: '', app: null, groupId: null };
-
-/** The rows that match the search and the app and group picked, in name order. */
-export function filterRoomRows(rows: readonly RoomRow[], filter: RoomsFilter): RoomRow[] {
- const query = filter.query.trim().toLowerCase();
- return rows
- .filter((row) => query === '' || row.name.toLowerCase().includes(query))
- .filter((row) => filter.app === null || row.appLabel === filter.app)
- .filter((row) => filter.groupId === null || row.groupId === filter.groupId)
- .sort((a, b) => a.name.localeCompare(b.name));
-}
-
-/** The apps the rows live in, each once, in name order, Switch Console last. */
-export function appOptions(rows: readonly RoomRow[]): string[] {
- const labels = [...new Set(rows.map((row) => row.appLabel))];
- return labels.sort((a, b) =>
- a === CONSOLE_APP_LABEL ? 1 : b === CONSOLE_APP_LABEL ? -1 : a.localeCompare(b)
- );
-}
-
-/** The groups the rows are filed under, each once, in name order. */
-export function groupOptions(rows: readonly RoomRow[]): { id: string; name: string }[] {
- const byId = new Map<string, string>();
- for (const row of rows) {
- if (row.groupId !== null) byId.set(row.groupId, row.groupName ?? 'Unnamed group');
- }
- return [...byId].map(([id, name]) => ({ id, name })).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 4e5ff9863..445073dcf 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
@@ -1,15 +1,12 @@
import { useQuery, useQueryClient } from '@tanstack/react-query';
-import { DoorOpen, Lock, MessagesSquare, Plus } from 'lucide-react';
+import { DoorOpen, Plus } from 'lucide-react';
import { observer } from 'mobx-react-lite';
import { useEffect, useState } from 'react';
import type { GuardResult, ViewDefinition } from '@renderer/app/view-registry';
-import { UnreadBadge } from '@renderer/features/chats/components/unread-badge';
import { chatsStore } from '@renderer/features/chats/stores/chats';
import { refreshSidebarRoomState } from '@renderer/features/sidebar/sidebar-tree-data';
import { openRoom } from '@renderer/features/switch-rooms/open-room';
-import { ACCESS_LABELS } from '@renderer/features/switch-rooms/room-settings-sections';
import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';
-import { BridgeIcon, hasBridgeIcon } from '@renderer/lib/components/bridge-icon';
import { LIST_PAGE_WIDTH, ListToolbar } from '@renderer/lib/components/list-toolbar';
import { failureText } from '@renderer/lib/errors/describe-failure';
import { toast } from '@renderer/lib/hooks/use-toast';
@@ -26,20 +23,19 @@ import {
SelectTrigger,
SelectValue,
} from '@renderer/lib/ui/select';
-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 { AppMark, RoomCard } from './room-card';
import { allReadableRooms, isConsoleGroupChatSummary, withConsoleGroupChats } from './room-filters';
import {
- ACCESS_SHORT,
appOptions,
- filterRoomRows,
+ filterRoomCards,
groupOptions,
NO_FILTER,
- type RoomRow,
+ offeredFilter,
+ type RoomCard as RoomCardData,
type RoomsFilter,
- roomRow,
-} from './rooms-table';
+ roomCard,
+} from './room-list';
import { ServerPage, ServerTableEmpty } from './server-page';
import { ServerSectionTitlebar } from './server-section-titlebar';
import { switchRoomsStore } from './switch-rooms-store';
@@ -70,10 +66,9 @@ const STATES = [
const ANY = '__any__';
/**
- * The workspace's rooms as one table: yours by default, every room you can
- * read at a switch, and the archived ones at another. The same row whichever
- * slice you look at, so moving between them never changes what a column
- * means.
+ * The workspace's rooms as cards: yours by default, every room you can read
+ * at a switch, and the archived ones at another. The same card whichever
+ * slice you look at.
*/
const ServerRoomsPanel = observer(function ServerRoomsPanel() {
const serverId = useServerId();
@@ -82,7 +77,7 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
const queryClient = useQueryClient();
const [scope, setScope] = useState<Scope>('mine');
const [state, setState] = useState<State>('active');
- const [filter, setFilter] = useState<RoomsFilter>(NO_FILTER);
+ const [picked, setFilter] = useState<RoomsFilter>(NO_FILTER);
useEffect(() => {
void refreshSidebarRoomState(false);
@@ -90,10 +85,14 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
const workspaceId = workspacesStore.idOnServerInScope(serverId);
const viewerId = switchServersStore.statusFor(serverId)?.user?.id ?? null;
- const yours = useListedRoomsInWorkspace(workspaceId);
- const all = allReadableRooms(yours, useReadableRoomsInWorkspace(workspaceId));
+ const listed = useListedRoomsInWorkspace(workspaceId);
+ const all = allReadableRooms(listed, useReadableRoomsInWorkspace(workspaceId));
const signedOut = switchRoomsStore.workspacesNotSignedIn.some((w) => w.id === workspaceId);
const failed = switchRoomsStore.workspacesThatFailedToLoad.some((w) => w.id === workspaceId);
+ // On a server Console runs, the sidebar lists every room, so only the
+ // server's word says which are yours. Elsewhere what the sidebar lists as
+ // yours counts too, for a server that does not say.
+ const listedIds = server?.managed ? undefined : new Set(listed.map((room) => room.id));
// Archived rooms in a messaging app come from the server; archived group
// chats from the chats list, which follows the active workspace.
@@ -106,52 +105,75 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
},
enabled: workspaceId !== null && !signedOut,
});
- const archivedChats =
- chatsStore.serverId === serverId
- ? [...chatsStore.archived.values()].filter(isConsoleGroupChatSummary)
- : [];
+ const chatsHere = chatsStore.serverId === serverId;
+ const archivedChats = chatsHere
+ ? [...chatsStore.archived.values()].filter(isConsoleGroupChatSummary)
+ : [];
- const toRow = (room: RemoteRoomSummary): RoomRow => {
- const row = roomRow(room, viewerId);
+ const toCard = (room: RemoteRoomSummary): RoomCardData => {
+ const card = roomCard(room, { id: viewerId, listedIds });
// A chat's people are its members, which the chat list knows.
- const chat = room.isConsoleChat ? chatsStore.chats.get(room.id) : undefined;
- return chat ? { ...row, peopleCount: chat.memberCount } : row;
+ const chat = room.isConsoleChat
+ ? (chatsStore.chats.get(room.id) ?? chatsStore.archived.get(room.id))
+ : undefined;
+ return chat ? { ...card, peopleCount: chat.memberCount } : card;
};
- const activeRows = (scope === 'all' ? all : yours).map(toRow);
- const archivedRows = [
- ...(archivedRoomsQuery.data ?? []).map(toRow),
+ const activeCards = all.map(toCard);
+ const archivedCards = [
+ ...(archivedRoomsQuery.data ?? []).map(toCard),
...withConsoleGroupChats([], archivedChats).map((room) => ({
- ...toRow(room),
+ ...toCard(room),
archived: true,
})),
- ].filter((row) => scope === 'all' || row.mine);
- const rows = state === 'archived' ? archivedRows : activeRows;
- const shown = filterRoomRows(rows, filter);
- const apps = appOptions(rows);
- const groups = groupOptions(rows);
+ ];
+ const cards = (state === 'archived' ? archivedCards : activeCards).filter(
+ (card) => scope === 'all' || card.mine
+ );
+ const apps = appOptions(cards);
+ const groups = groupOptions(cards);
+ const filter = offeredFilter(picked, apps, groups);
+ const shown = filterRoomCards(cards, filter);
+ const archivedError =
+ state === 'archived' &&
+ (archivedRoomsQuery.isError || (chatsHere && chatsStore.archivedError !== null));
- async function unarchive(row: RoomRow) {
+ const archivedSummary = (card: RoomCardData) =>
+ (archivedRoomsQuery.data ?? []).find((each) => each.id === card.id) ??
+ all.find((each) => each.id === card.id);
+ const mayArchive = (card: RoomCardData): boolean => {
+ if (card.isConsoleChat)
+ return (
+ (card.archived ? chatsStore.archived.get(card.id) : chatsStore.chats.get(card.id))
+ ?.canManage ?? false
+ );
+ const room = archivedSummary(card);
+ return room !== undefined && workspaceId !== null
+ ? switchRoomsStore.roomPermissions(workspaceId, room).canWrite
+ : false;
+ };
+ async function setArchived(card: RoomCardData) {
if (workspaceId === null) return;
+ const archived = !card.archived;
try {
- if (row.isConsoleChat) {
- await chatsStore.unarchive(serverId, row.id);
+ if (card.isConsoleChat) {
+ if (archived) await chatsStore.archive(serverId, card.id);
+ else await chatsStore.unarchive(serverId, card.id);
} else {
- await rpc.workspaces.setRoomArchived({ workspaceId, roomId: row.id, archived: false });
+ await rpc.workspaces.setRoomArchived({ workspaceId, roomId: card.id, archived });
await queryClient.invalidateQueries({ queryKey: ['archived-rooms', workspaceId] });
await switchRoomsStore.refreshRoomState();
}
void refreshSidebarRoomState(true);
} catch (error) {
- toast({ title: failureText(error, 'Could not unarchive the room.'), variant: 'destructive' });
+ toast({
+ title: failureText(
+ error,
+ archived ? 'Could not archive the room.' : 'Could not unarchive the room.'
+ ),
+ variant: 'destructive',
+ });
}
}
- const mayUnarchive = (row: RoomRow): boolean => {
- if (row.isConsoleChat) return chatsStore.archived.get(row.id)?.canManage ?? false;
- const room = (archivedRoomsQuery.data ?? []).find((each) => each.id === row.id);
- return room !== undefined && workspaceId !== null
- ? switchRoomsStore.roomPermissions(workspaceId, room).canWrite
- : false;
- };
return (
<ServerPage
@@ -173,9 +195,9 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
</Button>
}
>
- {/* Four ways to have no rows, and only one of them means "there are no
- rooms". Saying that in the others would send someone off to create a
- room they already have. */}
+ {/* Four ways to have no rooms to show, and only one of them means
+ "there are no rooms". Saying that in the others would send someone off
+ to create a room they already have. */}
{workspaceId === null ? (
<ServerTableEmpty>
This server has no workspace yet, so its rooms cannot be read.
@@ -195,10 +217,7 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
<SegmentedControl
ariaLabel="Whose rooms"
value={scope}
- onChange={(next) => {
- setScope(next);
- setFilter((current) => ({ ...current, app: null, groupId: null }));
- }}
+ onChange={setScope}
options={SCOPES}
/>
}
@@ -217,7 +236,11 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
label="Messaging app"
anyLabel="Any messaging app"
value={filter.app}
- options={apps.map((app) => ({ value: app, label: app }))}
+ options={apps.map((app) => ({
+ value: app.value,
+ label: app.label,
+ icon: <AppMark bridgeType={app.bridgeType} />,
+ }))}
onChange={(app) => setFilter({ ...filter, app })}
/>
<FilterSelect
@@ -236,22 +259,34 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
</>
}
/>
- {state === 'archived' && archivedRoomsQuery.isError && (
+ {archivedError && (
<p className="text-xs text-destructive">
- {failureText(archivedRoomsQuery.error, 'Could not list the archived rooms.')}
+ {archivedRoomsQuery.isError
+ ? failureText(archivedRoomsQuery.error, 'Could not list the archived rooms.')
+ : chatsStore.archivedError}
</p>
)}
{shown.length === 0 ? (
<p className="py-2 text-sm text-foreground-muted">
- {emptyText({ rows: rows.length, scope, state, query: filter.query })}
+ {emptyText({ rooms: cards.length, scope, state, query: filter.query })}
</p>
) : (
- <RoomsTable
- rows={shown}
- scope={scope}
- unarchive={state === 'archived' ? unarchive : null}
- mayUnarchive={mayUnarchive}
- />
+ <div
+ role="list"
+ aria-label="Rooms"
+ className="grid grid-cols-[repeat(auto-fill,minmax(280px,1fr))] gap-[14px]"
+ >
+ {shown.map((card) => (
+ <div role="listitem" key={card.id}>
+ <RoomCard
+ card={card}
+ showYours={scope === 'all'}
+ onOpen={() => void openRoom(card.id)}
+ onArchive={mayArchive(card) ? () => void setArchived(card) : null}
+ />
+ </div>
+ ))}
+ </div>
)}
</div>
)}
@@ -259,19 +294,19 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
);
});
-/** What an empty table means, which depends on why it is empty. */
+/** What an empty page means, which depends on why it is empty. */
export function emptyText({
- rows,
+ rooms,
scope,
state,
query,
}: {
- rows: number;
+ rooms: number;
scope: Scope;
state: State;
query: string;
}): string {
- if (rows > 0) return query.trim() ? `No room matches “${query.trim()}”.` : 'No room matches.';
+ if (rooms > 0) return query.trim() ? `No room matches “${query.trim()}”.` : 'No room matches.';
if (state === 'archived') return 'No archived rooms.';
return scope === 'mine'
? 'You are in no rooms yet. Create one, or choose All rooms to see the rest.'
@@ -288,23 +323,35 @@ function FilterSelect({
label: string;
anyLabel: string;
value: string | null;
- options: { value: string; label: string }[];
+ options: { value: string; label: string; icon?: React.ReactNode }[];
onChange: (next: string | null) => void;
}) {
- const current = options.find((option) => option.value === value)?.label ?? anyLabel;
+ const current = options.find((option) => option.value === value);
return (
<Select
value={value ?? ANY}
onValueChange={(next) => onChange(next === ANY ? null : (next as string))}
>
<SelectTrigger size="sm" className="w-auto min-w-[150px]" aria-label={label}>
- <SelectValue>{current}</SelectValue>
+ <SelectValue>
+ {current ? (
+ <span className="flex items-center gap-1.5">
+ {current.icon}
+ {current.label}
+ </span>
+ ) : (
+ anyLabel
+ )}
+ </SelectValue>
</SelectTrigger>
<SelectContent>
<SelectItem value={ANY}>{anyLabel}</SelectItem>
{options.map((option) => (
<SelectItem key={option.value} value={option.value}>
- {option.label}
+ <span className="flex items-center gap-1.5">
+ {option.icon}
+ {option.label}
+ </span>
</SelectItem>
))}
</SelectContent>
@@ -312,131 +359,6 @@ function FilterSelect({
);
}
-const RoomsTable = observer(function RoomsTable({
- rows,
- scope,
- unarchive,
- mayUnarchive,
-}: {
- rows: RoomRow[];
- scope: Scope;
- /** The way to unarchive a row, in the archived view. */
- unarchive: ((row: RoomRow) => Promise<void>) | null;
- mayUnarchive: (row: RoomRow) => boolean;
-}) {
- return (
- <div className="overflow-hidden rounded-[10px] border border-border">
- <table className="w-full border-collapse text-sm">
- <thead>
- <tr className="border-b border-border text-left text-xs text-foreground-muted">
- <th className="px-3 py-2 font-normal">Room</th>
- <th className="px-3 py-2 font-normal">Messaging app</th>
- <th className="px-3 py-2 font-normal">Group</th>
- <th className="px-3 py-2 font-normal">Owner</th>
- <th className="px-3 py-2 font-normal">Access</th>
- <th className="px-3 py-2 font-normal">Agents · people</th>
- <th className="px-3 py-2 font-normal">Created</th>
- {unarchive && <th className="px-3 py-2" />}
- </tr>
- </thead>
- <tbody>
- {rows.map((row) => (
- <tr
- key={row.id}
- onClick={() => void openRoom(row.id)}
- className="cursor-pointer border-b border-border last:border-b-0 hover:bg-[var(--fill)]"
- >
- <td className="px-3 py-2">
- <span className="flex min-w-0 items-center gap-2">
- <RoomMark row={row} />
- <span
- className={cn(
- 'truncate',
- // In All rooms, yours stand out; the rest are there to find.
- scope === 'all' && !row.mine
- ? 'text-foreground-muted'
- : 'font-medium text-foreground'
- )}
- >
- {row.name}
- </span>
- <UnreadBadge roomId={row.id} />
- </span>
- </td>
- <td className="px-3 py-2 text-foreground">{row.appLabel}</td>
- <td className="px-3 py-2 text-foreground">{row.groupName ?? '—'}</td>
- <td className="px-3 py-2 text-foreground">{row.ownerLabel ?? '—'}</td>
- <td className="px-3 py-2 text-foreground">
- {row.access ? (
- <Tooltip>
- <TooltipTrigger render={<span>{ACCESS_SHORT[row.access]}</span>} />
- <TooltipContent>{ACCESS_LABELS[row.access]}</TooltipContent>
- </Tooltip>
- ) : (
- '—'
- )}
- </td>
- <td className="px-3 py-2 text-foreground tabular-nums">
- {row.agentCount} · {row.peopleCount ?? '—'}
- </td>
- <td className="px-3 py-2 text-foreground-muted">
- {row.createdAt ? <AbsoluteDate value={row.createdAt} /> : '—'}
- </td>
- {unarchive && (
- <td className="px-3 py-2 text-right">
- {mayUnarchive(row) && (
- <Button
- size="sm"
- variant="outline"
- onClick={(event) => {
- event.stopPropagation();
- void unarchive(row);
- }}
- >
- Unarchive
- </Button>
- )}
- </td>
- )}
- </tr>
- ))}
- </tbody>
- </table>
- </div>
- );
-});
-
-/** Where the room lives at a glance: its app's mark, or a lock for one only its people reach. */
-function RoomMark({ row }: { row: RoomRow }) {
- if (row.privateChannel && !row.isConsoleChat) {
- return (
- <Lock className="size-3.5 shrink-0 text-foreground-muted" aria-label="Private channel" />
- );
- }
- if (hasBridgeIcon(row.bridgeType)) {
- return <BridgeIcon bridgeType={row.bridgeType} size={14} className="shrink-0" />;
- }
- return <MessagesSquare className="size-3.5 shrink-0 text-foreground-muted" />;
-}
-
-/** A day, with the year only when it is not this one. */
-function AbsoluteDate({ value }: { value: string }) {
- const date = new Date(
- value.includes('T') || value.includes('Z') ? value : value.replace(' ', 'T')
- );
- if (Number.isNaN(date.getTime())) return <>—</>;
- const sameYear = date.getFullYear() === new Date().getFullYear();
- return (
- <time dateTime={date.toISOString()}>
- {date.toLocaleDateString(undefined, {
- day: 'numeric',
- month: 'short',
- ...(sameYear ? {} : { year: 'numeric' }),
- })}
- </time>
- );
-}
-
export const serverRoomsView = {
WrapView: ({ children }: { children: React.ReactNode; serverId: string }) => <>{children}</>,
TitlebarSlot: ServerRoomsTitlebar,
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
index 39767beb3..1ed02833f 100644
--- 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
@@ -1,6 +1,6 @@
/**
- * 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
+ * Rooms shows yours by default, as cards. 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 { QueryClient, QueryClientProvider } from '@tanstack/react-query';
@@ -21,6 +21,7 @@ vi.hoisted(() => {
const rooms = vi.hoisted(() => ({ list: null as unknown as { all: RemoteRoomSummary[] } }));
const archivedRooms = vi.hoisted(() => ({ list: [] as RemoteRoomSummary[] }));
const setRoomArchived = vi.hoisted(() => vi.fn(async () => ({})));
+const serverState = vi.hoisted(() => ({ managed: false, canWrite: true }));
vi.mock('@renderer/lib/ipc', () => ({
events: { on: () => () => {} },
@@ -67,7 +68,9 @@ vi.mock('@renderer/features/workspaces/workspaces-store', () => ({
}));
vi.mock('@renderer/features/switch-servers/switch-servers-store', () => ({
switchServersStore: {
- servers: [{ id: 'srv', name: 'Server' }],
+ get servers() {
+ return [{ id: 'srv', name: 'Server', managed: serverState.managed }];
+ },
statusFor: () => ({ connected: true, user: { id: 'me' } }),
},
}));
@@ -77,11 +80,14 @@ vi.mock('@renderer/features/switch-servers/switch-rooms-store', () => ({
workspacesNotSignedIn: [],
workspacesThatFailedToLoad: [],
localMemberIds: () => [],
+ // On a server Console runs, the sidebar lists every room.
listedRoomsInWorkspace: () =>
- rooms.list.all.filter((room) => room.ownerId === 'me' || room.viewerIsMember),
+ serverState.managed
+ ? rooms.list.all
+ : rooms.list.all.filter((room) => room.ownerId === 'me' || room.viewerIsMember),
readableRoomsInWorkspace: () => rooms.list.all,
noteRooms: () => {},
- roomPermissions: () => ({ canWrite: true, canManage: false }),
+ roomPermissions: () => ({ canWrite: serverState.canWrite, canManage: false }),
refreshRoomState: async () => {},
},
}));
@@ -124,6 +130,8 @@ function chat(id: string) {
beforeEach(() => {
archivedRooms.list = [];
+ serverState.managed = false;
+ serverState.canWrite = true;
setRoomArchived.mockClear();
rooms.list = observable({
all: [
@@ -147,6 +155,7 @@ beforeEach(() => {
});
runInAction(() => {
chatsStore.chats.clear();
+ chatsStore.archivedError = null;
chatsStore.chats.set('bobs-chat', chat('bobs-chat') as never);
});
});
@@ -180,11 +189,16 @@ async function render(): Promise<void> {
}
const names = () =>
- [...container.querySelectorAll('tbody tr td:first-child span.truncate')].map(
- (s) => s.textContent
- );
+ [...container.querySelectorAll('[data-room-card] h3')].map((h) => h.textContent);
+const cardFor = (name: string) =>
+ [...container.querySelectorAll<HTMLElement>('[data-room-card]')].find(
+ (card) => card.querySelector('h3')?.textContent === name
+ )!;
const toggle = (label: string) =>
[...container.querySelectorAll('button')].find((b) => b.textContent === label);
+const settle = async () => {
+ for (let i = 0; i < 4; i++) await act(async () => await Promise.resolve());
+};
it('lists your rooms by default, and drops a chat once you are removed from it', async () => {
await render();
@@ -201,22 +215,41 @@ it('shows every room you can read under All rooms, never chats you are not in',
expect(names()).toEqual(['private-tool-room', 'public-slack', 'yaml-room']);
});
-it('keeps the same columns in both, and marks a room only its people reach', async () => {
+it('keeps Mine to your rooms on a server Console runs, where the sidebar lists them all', async () => {
+ serverState.managed = true;
+ await render();
+ expect(names()).toEqual(['bobs-chat', 'yaml-room']);
+});
+
+it('says who owns a room and what is in it in words, and marks one only its people reach', async () => {
+ rooms.list.all.push(
+ room('mine-slack', {
+ ownerId: 'me',
+ bridgeType: 'slack',
+ bridgeDisplayName: 'Slack',
+ channelType: 'channel_private',
+ connectedUserCount: 1,
+ })
+ );
+ await render();
+ const card = cardFor('mine-slack');
+ expect(card.textContent).toContain('Owned by you');
+ expect(card.textContent).toContain('2 agents');
+ expect(card.textContent).toContain('1 person');
+ expect(card.querySelector('[aria-label="Private"]')).not.toBeNull();
+ // A room with no messaging app: the server's people count would read 0, so none is shown.
+ expect(cardFor('yaml-room').textContent).not.toMatch(/people|person/);
+});
+
+it('offers archiving only where the server lets you', async () => {
await render();
- const headers = [...container.querySelectorAll('thead th')].map((th) => th.textContent);
- expect(headers).toEqual([
- 'Room',
- 'Messaging app',
- 'Group',
- 'Owner',
- 'Access',
- 'Agents · people',
- 'Created',
- ]);
- expect(container.querySelector('[aria-label="Private channel"]')).not.toBeNull();
+ expect(cardFor('yaml-room').querySelector('[aria-label="yaml-room actions"]')).not.toBeNull();
+ serverState.canWrite = false;
+ await act(async () => toggle('All rooms')!.click());
+ expect(cardFor('yaml-room').querySelector('[aria-label="yaml-room actions"]')).toBeNull();
});
-it('lists archived rooms under Archived, and brings one back', async () => {
+it('lists archived rooms under Archived, and brings one back from its menu', async () => {
archivedRooms.list = [
room('old-slack', {
bridgeType: 'slack',
@@ -226,14 +259,32 @@ it('lists archived rooms under Archived, and brings one back', async () => {
}),
];
await render();
- for (let i = 0; i < 4; i++) await act(async () => await Promise.resolve());
+ await settle();
await act(async () => toggle('Archived')!.click());
- for (let i = 0; i < 4; i++) await act(async () => await Promise.resolve());
+ await settle();
expect(names()).toEqual(['old-slack']);
- await act(async () => toggle('Unarchive')!.click());
+ await act(async () =>
+ cardFor('old-slack')
+ .querySelector<HTMLButtonElement>('[aria-label="old-slack actions"]')!
+ .click()
+ );
+ await settle();
+ const item = [...document.querySelectorAll<HTMLElement>('[role="menuitem"]')].find(
+ (each) => each.textContent === 'Unarchive'
+ )!;
+ await act(async () => item.click());
expect(setRoomArchived).toHaveBeenCalledWith({
workspaceId: 'ws',
roomId: 'old-slack',
archived: false,
});
});
+
+it('says so when the archived chats cannot be listed', async () => {
+ runInAction(() => {
+ chatsStore.archivedError = 'Your archived chats could not be listed.';
+ });
+ await render();
+ await act(async () => toggle('Archived')!.click());
+ expect(container.textContent).toContain('Your archived chats could not be listed.');
+});
diff --git a/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts b/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
index 5ba103f55..409c4ebe9 100644
--- a/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
+++ b/console/apps/switch-console-desktop/src/shared/core/switch-servers/switch-servers.ts
@@ -368,6 +368,9 @@ export type RemoteRoomSummary = {
* where Console works it out the same way (`roomPermissionsFor`).
*/
serverPermissions?: { canWrite: boolean; canManage: boolean; canUnlink: boolean };
+ /** The messaging app connection it is on, when the server says (the list does). Unlike
+ * the display name, it tells two connections to the same platform apart. */
+ bridgeId?: string | null;
/** The group the room is filed under, when the server says (the list does). */
groupId?: string | null;
groupName?: string | null;