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): list a Switch Console chat only when the chat list has you in it

raullopez-sandbox4fff897d86e5
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 c0094a49c..2efab0f16 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
@@ -62,26 +62,28 @@ export function withConsoleGroupChats(
}
/**
- * 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.
+ * Your rooms, then every other room you can read: one list, by name.
*/
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) && !isConsoleChatYouAreNotIn(room));
+ const more = readable.filter((room) => !listed.has(room.id));
if (more.length === 0) return yours;
return [...yours, ...more].sort((a, b) => a.name.localeCompare(b.name));
}
-/** A Switch Console chat (unbridged, direct or private) the signed-in user is not in: they cannot open it. */
-export function isConsoleChatYouAreNotIn(
- room: Pick<RemoteRoomSummary, 'bridgeType' | 'channelType' | 'viewerIsMember'>
+/**
+ * A Switch Console chat: unbridged, direct or private. Whether the user is in it
+ * is the chat list's to say, not the room list's `viewerIsMember`, which is also
+ * true for a room one of their agents is in.
+ */
+export function isConsoleChatRoom(
+ room: Pick<RemoteRoomSummary, 'bridgeType' | 'channelType'>
): boolean {
return (
room.bridgeType === null &&
- (room.channelType === 'direct' || room.channelType === 'channel_private') &&
- !room.viewerIsMember
+ (room.channelType === 'direct' || room.channelType === 'channel_private')
);
}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.ts
index 6503b612d..3ee1fe633 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.test.ts
@@ -84,12 +84,6 @@ describe('listed rooms', () => {
room('mine', 'user-of-srv-a'),
room('someone-elses', 'user-of-someone-else'),
room('gone', 'user-of-srv-a', { archived: true }),
- // A Switch Console chat they are not in: the server will not open it to them.
- room('not-my-chat', 'user-of-someone-else', { channelType: 'channel_private' }),
- room('my-chat', 'user-of-someone-else', {
- channelType: 'channel_private',
- viewerIsMember: true,
- }),
]
: []
);
@@ -97,11 +91,7 @@ describe('listed rooms', () => {
const store = new SwitchRoomsStore();
await store.loadRoomNames();
- expect(store.listedRoomsInActiveScope.map((r) => r.id)).toEqual([
- 'mine',
- 'my-chat',
- 'someone-elses',
- ]);
+ expect(store.listedRoomsInActiveScope.map((r) => r.id)).toEqual(['mine', 'someone-elses']);
});
it('lists only rooms owned by that server’s signed-in user, excluding archived ones', async () => {
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts
index 369a1d802..78c69d2d8 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-rooms-store.ts
@@ -9,7 +9,6 @@ import {
type RetireOutcome,
} from '@shared/core/switch-servers/switch-servers';
import { UNBRIDGED_FILTER_VALUE } from '@shared/view-state';
-import { isConsoleChatYouAreNotIn } from './room-filters';
import { serverAvailability } from './server-availability';
import { switchServersStore } from './switch-servers-store';
@@ -185,11 +184,7 @@ export class SwitchRoomsStore {
listedRoomsInWorkspace(workspaceId: string): RemoteRoomSummary[] {
const serverId = workspacesStore.serverIdFor(workspaceId);
const managed = switchServersStore.servers.find((s) => s.id === serverId)?.managed ?? false;
- if (managed) {
- return (this.allRoomsByWorkspace.get(workspaceId) ?? []).filter(
- (room) => !isConsoleChatYouAreNotIn(room)
- );
- }
+ if (managed) return this.allRoomsByWorkspace.get(workspaceId) ?? [];
const own = this.ownedRoomsByWorkspace.get(workspaceId) ?? [];
const ownIds = new Set(own.map((room) => room.id));
// And the rooms the user's agents are in, managed ones included, by their membership.
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 885b1f2b4..08bf70e10 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
@@ -3,7 +3,7 @@ import { chatsStore } from '@renderer/features/chats/stores/chats';
import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';
import { useFeatureFlags } from '@renderer/lib/hooks/useFeatureFlags';
import type { RemoteRoomSummary } from '@shared/core/switch-servers/switch-servers';
-import { isConsoleDirectChat, withConsoleGroupChats } from './room-filters';
+import { isConsoleChatRoom, isConsoleDirectChat, withConsoleGroupChats } from './room-filters';
import { switchRoomsStore } from './switch-rooms-store';
import { switchServersStore } from './switch-servers-store';
@@ -15,6 +15,25 @@ function filterConsoleDirectChats(
return rooms.filter((room) => !isConsoleDirectChat(room));
}
+/**
+ * Without the Switch Console chats the user is not in: they cannot open one. Only
+ * the chat list knows, and it follows the active workspace's server, so a chat
+ * elsewhere is left out until that workspace is the active one.
+ */
+function withoutChatsYouAreNotIn(
+ rooms: RemoteRoomSummary[],
+ serverId: string | null,
+ chatsOn: boolean
+): RemoteRoomSummary[] {
+ if (!chatsOn) return rooms;
+ const following = serverId !== null && chatsStore.serverId === serverId;
+ return rooms.filter(
+ (room) =>
+ !isConsoleChatRoom(room) ||
+ (following && (chatsStore.chats.has(room.id) || chatsStore.unlisted.has(room.id)))
+ );
+}
+
/**
* Rooms listed in the sidebar and on the Your Rooms page, filtered by the
* agent_chats flag: when on, 1-1 Console chats (see `isConsoleDirectChat`)
@@ -23,9 +42,14 @@ function filterConsoleDirectChats(
*/
export function useListedRoomsInActiveScope(): RemoteRoomSummary[] {
const flags = useFeatureFlags(switchServersStore.activeServerId);
+ const serverId = switchServersStore.activeServerId;
return computed(() =>
withConsoleGroupChats(
- filterConsoleDirectChats(switchRoomsStore.listedRoomsInActiveScope, flags.agent_chats),
+ withoutChatsYouAreNotIn(
+ filterConsoleDirectChats(switchRoomsStore.listedRoomsInActiveScope, flags.agent_chats),
+ serverId,
+ flags.agent_chats || flags.group_chats
+ ),
flags.agent_chats ? chatsStore.chats.values() : []
)
).get();
@@ -49,10 +73,16 @@ function useRoomsInWorkspace(
workspaceId: string | null,
rooms: (workspaceId: string) => RemoteRoomSummary[]
): RemoteRoomSummary[] {
- const flags = useFeatureFlags(workspaceId && workspacesStore.serverIdFor(workspaceId));
+ const serverId = workspaceId && workspacesStore.serverIdFor(workspaceId);
+ const flags = useFeatureFlags(serverId);
if (workspaceId === null) return [];
+ const active = workspaceId === workspacesStore.activeId;
return withConsoleGroupChats(
- filterConsoleDirectChats(rooms(workspaceId), flags.agent_chats),
+ withoutChatsYouAreNotIn(
+ filterConsoleDirectChats(rooms(workspaceId), flags.agent_chats),
+ active ? serverId : null,
+ flags.agent_chats || flags.group_chats
+ ),
flags.agent_chats && workspaceId === workspacesStore.activeId ? chatsStore.chats.values() : []
);
}
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 662c562c9..e3dee74cc 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
@@ -30,7 +30,17 @@ vi.mock('@renderer/features/sidebar/sidebar-tree-data', () => ({
}));
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() } }));
+// The chats the user is in, as GET /gateway/chats lists them.
+vi.mock('@renderer/features/chats/stores/chats', async () => {
+ const { observable } = await import('mobx');
+ return {
+ chatsStore: observable({
+ serverId: 'srv',
+ chats: new Map<string, unknown>(),
+ unlisted: new Set<string>(),
+ }),
+ };
+});
vi.mock('@renderer/lib/stores/use-workspace-agents', () => ({
useWorkspaceAgents: () => ({ data: [] }),
}));
@@ -44,7 +54,7 @@ vi.mock('@renderer/features/workspaces/workspaces-store', () => ({
workspacesStore: {
idOnServerInScope: () => 'ws',
serverIdFor: () => 'srv',
- activeId: 'other',
+ activeId: 'ws',
},
}));
vi.mock('@renderer/features/switch-servers/switch-servers-store', () => ({
@@ -62,6 +72,7 @@ vi.mock('@renderer/features/switch-servers/switch-rooms-store', () => ({
},
}));
+import { chatsStore } from '@renderer/features/chats/stores/chats';
import { serverRoomsView } from '@renderer/features/switch-servers/server-rooms-view';
function room(id: string, extra: Partial<RemoteRoomSummary>): RemoteRoomSummary {
@@ -85,17 +96,42 @@ function room(id: string, extra: Partial<RemoteRoomSummary>): RemoteRoomSummary
let container: HTMLDivElement;
let root: Root;
+function chat(id: string) {
+ return {
+ roomId: id,
+ name: id,
+ channelType: 'channel_private',
+ bridgeType: null,
+ agents: [{ id: 'a1' }, { id: 'a2' }],
+ lastMessage: null,
+ };
+}
+
beforeEach(() => {
rooms.list = observable({
all: [
room('bobs-chat', { viewerIsMember: true, channelType: 'channel_private' }),
+ // The room list says "member" because the user's agent is in it; the user is not.
+ room('agent-only-chat', { viewerIsMember: true, channelType: 'channel_private' }),
room('strangers-chat', { channelType: 'channel_private' }),
room('public-room', { channelType: 'channel_public' }),
room('public-slack', { bridgeType: 'slack', bridgeDisplayName: 'Slack' }),
],
});
+ runInAction(() => {
+ chatsStore.chats.clear();
+ chatsStore.chats.set('bobs-chat', chat('bobs-chat') as never);
+ });
});
+const removeFromBobsChat = () =>
+ act(async () =>
+ runInAction(() => {
+ chatsStore.chats.delete('bobs-chat');
+ rooms.list.all[0].viewerIsMember = false;
+ })
+ );
+
afterEach(async () => {
await act(async () => root.unmount());
container.remove();
@@ -117,7 +153,7 @@ const toggle = (label: string) =>
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)));
+ await removeFromBobsChat();
expect(names()).toEqual([]);
});
@@ -125,12 +161,12 @@ it('offers All rooms to someone who can read more: bridged rooms, never chats th
await render();
await act(async () => toggle('All rooms')!.click());
expect(names()).toEqual(['#public-slack', 'bobs-chat', 'public-room']);
- await act(async () => runInAction(() => (rooms.list.all[0].viewerIsMember = false)));
+ await removeFromBobsChat();
expect(names()).toEqual(['#public-slack', 'public-room']);
});
it('offers no choice to someone who can read only their own rooms', async () => {
- rooms.list.all = [room('bobs-chat', { viewerIsMember: true })];
+ rooms.list.all = [room('bobs-chat', { viewerIsMember: true, channelType: 'channel_private' })];
await render();
expect(toggle('All rooms')).toBeUndefined();
});