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: answer Petr's review, and show your unread count on a card

Simon Flack92673cd893f3
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
index c31fff7d8..8c237e4f5 100644
--- 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
@@ -39,11 +39,14 @@ export function AppMark({ bridgeType, size = 14 }: { bridgeType: string | null;
*/
export function RoomCard({
card,
+ unread,
showYours,
onOpen,
onArchive,
}: {
card: RoomCardData;
+ /** Messages here you have not read, as the sidebar counts them; 0 for none. */
+ unread: number;
/** Marks your rooms "Yours": in All rooms, where they sit among everyone's. */
showYours: boolean;
onOpen: () => void;
@@ -117,6 +120,22 @@ export function RoomCard({
{countText(card.peopleCount, 'person', 'people')}
</span>
)}
+ {unread > 0 && (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <span className="pointer-events-auto relative ml-auto rounded-full bg-primary-button-background px-2 py-0.5 text-[11px] leading-none font-medium text-primary-button-foreground tabular-nums">
+ {unreadText(unread)}
+ </span>
+ }
+ />
+ <TooltipContent>
+ {unread === 1
+ ? '1 message you haven’t read'
+ : `${unread} messages you haven’t read`}
+ </TooltipContent>
+ </Tooltip>
+ )}
</span>
</div>
</div>
@@ -151,3 +170,8 @@ export function RoomCard({
</div>
);
}
+
+/** "3 unread", or "99+ unread" past that: the word says what the number counts. */
+export function unreadText(count: number): string {
+ return `${count > 99 ? '99+' : count} unread`;
+}
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
index 97ab45755..1c4217bab 100644
--- 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
@@ -97,6 +97,11 @@ describe('a room as the Rooms page shows it', () => {
expect(roomCard(room({}), VIEWER).mine).toBe(false);
});
+ it('counts a room you own as yours, archived or not, whatever the server says of membership', () => {
+ expect(roomCard(room({ ownerId: 'u-1', archived: true }), VIEWER).mine).toBe(true);
+ expect(roomCard(room({ ownerId: 'u-1' }), { id: null }).mine).toBe(false);
+ });
+
it('counts in words', () => {
expect(countText(1, 'agent', 'agents')).toBe('1 agent');
expect(countText(0, 'person', 'people')).toBe('0 people');
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
index 9acf30ffe..aac5f3fe2 100644
--- 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
@@ -86,7 +86,12 @@ export function roomCard(
// 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),
+ // Yours as the sidebar counts it, owned or taken part in, plus what it lists as
+ // yours on a server that does not say: an archived room is in no sidebar.
+ mine:
+ (viewer.id !== null && room.ownerId === viewer.id) ||
+ room.viewerIsMember ||
+ (viewer.listedIds?.has(room.id) ?? false),
archived: room.archived,
};
}
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 e7822d5e4..4e62cde6a 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
@@ -7,6 +7,7 @@ import { chatsStore } from '@renderer/features/chats/stores/chats';
import { refreshSidebarRoomState } from '@renderer/features/sidebar/sidebar-tree-data';
import { useArchiveRoomConfirm } from '@renderer/features/switch-rooms/archive-room-confirm';
import { openRoom } from '@renderer/features/switch-rooms/open-room';
+import { roomDetailKey } from '@renderer/features/switch-rooms/room-participants';
import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';
import { LIST_PAGE_WIDTH, ListToolbar } from '@renderer/lib/components/list-toolbar';
import { failureText } from '@renderer/lib/errors/describe-failure';
@@ -118,7 +119,8 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
const chat = room.isConsoleChat
? (chatsStore.chats.get(room.id) ?? chatsStore.archived.get(room.id))
: undefined;
- return chat ? { ...card, peopleCount: chat.memberCount } : card;
+ // An older server reports no members as 0, which is not known rather than none.
+ return chat ? { ...card, peopleCount: chat.memberCount > 0 ? chat.memberCount : null } : card;
};
const activeCards = all.map(toCard);
const archivedCards = [
@@ -139,9 +141,10 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
state === 'archived' &&
(archivedRoomsQuery.isError || (chatsHere && chatsStore.archivedError !== null));
- const archivedSummary = (card: RoomCardData) =>
- (archivedRoomsQuery.data ?? []).find((each) => each.id === card.id) ??
- all.find((each) => each.id === card.id);
+ const summaries = new Map(
+ [...all, ...(archivedRoomsQuery.data ?? [])].map((room) => [room.id, room] as const)
+ );
+ const archivedSummary = (card: RoomCardData) => summaries.get(card.id);
const mayArchive = (card: RoomCardData): boolean => {
if (card.isConsoleChat)
return (
@@ -161,7 +164,13 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
if (archived) await chatsStore.archive(serverId, card.id);
else await chatsStore.unarchive(serverId, card.id);
} else {
- await rpc.workspaces.setRoomArchived({ workspaceId, roomId: card.id, archived });
+ const updated = await rpc.workspaces.setRoomArchived({
+ workspaceId,
+ roomId: card.id,
+ archived,
+ });
+ // The room's page reads its detail from the cache: give it the answer, as its own Archive does.
+ queryClient.setQueryData(roomDetailKey(workspaceId, card.id), updated);
await queryClient.invalidateQueries({ queryKey: ['archived-rooms', workspaceId] });
await switchRoomsStore.refreshRoomState();
}
@@ -269,9 +278,14 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
</p>
)}
{shown.length === 0 ? (
- <p className="py-2 text-sm text-foreground-muted">
- {emptyText({ rooms: cards.length, scope, state, query: filter.query })}
- </p>
+ // While the archived rooms load, or after they failed, "none" would be a claim.
+ state === 'archived' && archivedRoomsQuery.isPending && !signedOut ? (
+ <p className="py-2 text-sm text-foreground-muted">Loading archived rooms…</p>
+ ) : archivedError ? null : (
+ <p className="py-2 text-sm text-foreground-muted">
+ {emptyText({ rooms: cards.length, scope, state, query: filter.query })}
+ </p>
+ )
) : (
<div
role="list"
@@ -282,6 +296,7 @@ const ServerRoomsPanel = observer(function ServerRoomsPanel() {
<div role="listitem" key={card.id}>
<RoomCard
card={card}
+ unread={chatsStore.unread(card.id)}
showYours={scope === 'all'}
onOpen={() => void openRoom(card.id)}
onArchive={
diff --git a/console/apps/switch-console-desktop/src/renderer/features/templates/templates-view.tsx b/console/apps/switch-console-desktop/src/renderer/features/templates/templates-view.tsx
index e50e52d04..cf5e560c1 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/templates/templates-view.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/templates/templates-view.tsx
@@ -204,7 +204,9 @@ const TemplatesPanel = observer(function TemplatesPanel() {
const [kind, setKind] = useState<KindFilter>(initialKind ?? 'all');
// Navigating here without the param, as the sidebar does, shows every kind.
useEffect(() => setKind(initialKind ?? 'all'), [initialKind]);
- const [onlyMine, setOnlyMine] = useState(false);
+ const [mineChosen, setOnlyMine] = useState(false);
+ // With nobody signed in there is no Mine to show, nor a control to leave it: All it is.
+ const onlyMine = mineChosen && meId !== null;
const [dragging, setDragging] = useState(0);
const [reloadKey, setReloadKey] = useState(0);
const reload = useCallback(() => setReloadKey((k) => k + 1), []);
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 35e391ab2..30e1afb1b 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
@@ -47,6 +47,10 @@ vi.mock('@renderer/features/chats/stores/chats', async () => {
unlisted: new Set<string>(),
archived: new Map<string, unknown>(),
archivedError: null,
+ unreadCounts: new Map<string, number>(),
+ unread(roomId: string) {
+ return this.unreadCounts.get(roomId) ?? 0;
+ },
}),
};
});
@@ -289,6 +293,38 @@ it('says so when the archived chats cannot be listed', async () => {
expect(container.textContent).toContain('Your archived chats could not be listed.');
});
+it('lists your own archived room under Mine even when the server says nothing of membership', async () => {
+ archivedRooms.list = [room('my-old-room', { ownerId: 'me', archived: true })];
+ await render();
+ await settle();
+ await act(async () => toggle('Archived')!.click());
+ await settle();
+ expect(names()).toEqual(['my-old-room']);
+});
+
+it('does not claim there are no archived rooms beside an error listing them', async () => {
+ runInAction(() => {
+ chatsStore.archivedError = 'Your archived chats could not be listed.';
+ });
+ await render();
+ await settle();
+ await act(async () => toggle('Archived')!.click());
+ await settle();
+ expect(container.textContent).not.toContain('No archived rooms.');
+});
+
+it('labels your unread messages on a room’s card as unread', async () => {
+ runInAction(() => {
+ (chatsStore as unknown as { unreadCounts: Map<string, number> }).unreadCounts.set(
+ 'bobs-chat',
+ 3
+ );
+ });
+ await render();
+ expect(cardFor('bobs-chat').textContent).toContain('3 unread');
+ expect(cardFor('yaml-room').textContent).not.toContain('unread');
+});
+
it('archives a room from its menu only once you confirm', async () => {
await render();
await act(async () =>