Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Sidebar: bots with unread messages get an Unread section under the pinned bots

luishron1239c5547d7ec4e
diff --git a/src/components/Sidebar.simple-layout.test.ts b/src/components/Sidebar.simple-layout.test.ts
index c8bb12e42c..0d3b29e5f4 100644
--- a/src/components/Sidebar.simple-layout.test.ts
+++ b/src/components/Sidebar.simple-layout.test.ts
@@ -43,8 +43,8 @@ vi.mock("@/state/store", async (importOriginal) => {
return { ...original, useStore: () => ({ state: fixture.state, dispatch: fixture.dispatch }) };
});
-import { initialState } from "@/state/store";
-import { BOTS_SECTION_ID, CHANNELS_SECTION_ID, PINNED_SECTION_ID, userSectionId } from "@/lib/sidebar-layout";
+import { initialState, reducer } from "@/state/store";
+import { BOTS_SECTION_ID, CHANNELS_SECTION_ID, PINNED_SECTION_ID, UNREAD_SECTION_ID, userSectionId } from "@/lib/sidebar-layout";
import { SIDEBAR_COLLAPSED_SECTIONS_KEY, SIDEBAR_DENSITY_KEY, SIDEBAR_SECTION_ORDER_KEY, SIDEBAR_WIDTH_KEY, SIMPLE_SIDEBAR_SECTION_ORDER_KEY, SIMPLE_SIDEBAR_WIDTH_KEY, setSidebarDensity } from "@/lib/sidebar-preferences";
import { Sidebar, TeamMenuItems } from "./Sidebar";
const drawSidebar = (Sidebar as unknown as { type: (props: import("react").ComponentProps<typeof Sidebar>) => import("react").ReactNode }).type;
@@ -403,3 +403,103 @@ describe("Simple-mode sidebar layout", () => {
expect(render(true).tree.some((node) => node.type === SimpleRailFooter)).toBe(true);
});
});
+
+describe("the sidebar's Unread section", () => {
+ const unreadHeader = (tree: ReactElement<Props>[]) => headers(tree).find((header) => header.props.name === "Unread");
+ const thread = (id: string, updatedAt: number, unread = true) => ({ threadId: `${id}-thread`, title: id, createdAt: 1, updatedAt, unread });
+ const withUnread = () => {
+ fixture.state = { ...fixture.state, bots: [
+ bot("atlas"),
+ bot("bea", { unread: true, tasks: [thread("bea", 20)] }),
+ bot("cora", { unread: true, tasks: [thread("cora", 40)] }),
+ bot("dodo", { section: "Work", unread: true, tasks: [thread("dodo", 30)] }),
+ bot("eve", { section: "Work" }),
+ ] };
+ };
+
+ it("is absent while every bot is read", () => {
+ const { tree } = render();
+ expect(sectionOrder(tree)).not.toContain(UNREAD_SECTION_ID);
+ expect(unreadHeader(tree)).toBeUndefined();
+ });
+
+ it("gathers the unread bots of the main list and of departments above the rest, newest first, with their count", () => {
+ withUnread();
+ const { tree } = render();
+ expect(sectionOrder(tree)).toEqual([UNREAD_SECTION_ID, BOTS_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work")]);
+ expect(listedBots(tree)).toEqual(["cora", "dodo", "bea", "atlas", "eve"]);
+ expect(unreadHeader(tree)!.props).toMatchObject({ count: 3, reorderable: false, line: true });
+ expect(headers(tree).map((header) => [header.props.name, "count" in header.props])).toEqual([["Unread", true], ["Bots", false], ["Group chats", false], ["Work", false]]);
+ });
+
+ it("sends a bot back to its own place once it is opened, and brings it back when it is marked unread", () => {
+ withUnread();
+ fixture.state = reducer(fixture.state, { type: "select", id: "dodo" });
+ let tree = render().tree;
+ expect(listedBots(tree)).toEqual(["cora", "bea", "atlas", "dodo", "eve"]);
+ expect(unreadHeader(tree)!.props.count).toBe(2);
+
+ fixture.state = reducer(reducer(fixture.state, { type: "select", id: "cora" }), { type: "select", id: "bea" });
+ tree = render().tree;
+ expect(sectionOrder(tree)).toEqual([BOTS_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work")]);
+ expect(listedBots(tree)).toEqual(["atlas", "bea", "cora", "dodo", "eve"]);
+
+ fixture.state = { ...fixture.state, bots: fixture.state.bots.map((candidate) => (candidate.id === "eve" ? { ...candidate, tasks: undefined } : candidate)) };
+ fixture.state = reducer(fixture.state, { type: "markUnread", botId: "eve" });
+ tree = render().tree;
+ expect(sectionOrder(tree)[0]).toBe(UNREAD_SECTION_ID);
+ expect(listedBots(tree)).toEqual(["eve", "atlas", "bea", "cora", "dodo"]);
+ expect(unreadHeader(tree)!.props.count).toBe(1);
+ });
+
+ it("keeps a department whose bots are all unread, and takes no drag on its own rows", () => {
+ withUnread();
+ fixture.state = { ...fixture.state, sections: [], bots: fixture.state.bots.filter((candidate) => candidate.id !== "eve") };
+ const { tree } = render();
+ expect(sectionOrder(tree)).toContain(userSectionId("Work"));
+ const rows = tree.filter((node) => (node.props.bot as Bot | undefined) !== undefined);
+ expect(rows.map((row) => [(row.props.bot as Bot).id, row.props.botDrag !== undefined])).toEqual([["cora", false], ["dodo", false], ["bea", false], ["atlas", true]]);
+ });
+
+ it("leaves pinned bots and the Chief where they are, and sits under Advanced's Pinned heading", () => {
+ fixture.state = { ...fixture.state, bots: [
+ bot("chief", { chiefOfStaff: true, unread: true }), bot("atlas", { pinned: true, unread: true }), bot("bea", { unread: true }), bot("cora"),
+ ] };
+ let tree = render().tree;
+ const grid = tree.find((node) => node.type === SidebarTileGrid)!.props as Parameters<typeof SidebarTileGrid>[0];
+ expect([grid.primary?.id, ...grid.pinned.map((candidate) => candidate.id)]).toEqual(["chief", "atlas"]);
+ expect(sectionOrder(tree).slice(0, 2)).toEqual([UNREAD_SECTION_ID, BOTS_SECTION_ID]);
+ expect(listedBots(tree)).toEqual(["bea", "cora"]);
+
+ fixture.advanced = true;
+ tree = render().tree;
+ expect(sectionOrder(tree).slice(0, 2)).toEqual([PINNED_SECTION_ID, UNREAD_SECTION_ID]);
+ expect(listedBots(tree)).toEqual(["chief", "bea", "cora"]);
+ expect(unreadHeader(tree)!.props).toMatchObject({ count: 1, reorderable: false, line: false });
+ });
+
+ it("stays at the top whatever order the sections were dragged into", () => {
+ withUnread();
+ fixture.storage.set(SIMPLE_SIDEBAR_SECTION_ORDER_KEY, JSON.stringify([userSectionId("Work"), CHANNELS_SECTION_ID, BOTS_SECTION_ID]));
+ expect(sectionOrder(render().tree)).toEqual([UNREAD_SECTION_ID, userSectionId("Work"), CHANNELS_SECTION_ID, BOTS_SECTION_ID]);
+ });
+
+ it("gives way to a search, which lists every match in its own place", () => {
+ withUnread();
+ (render().tree.find((node) => node.type === SidebarSearchToggle)!.props as Parameters<typeof SidebarSearchToggle>[0]).onToggle();
+ (render().tree.find((node) => node.type === SidebarSearchPill)!.props as Parameters<typeof SidebarSearchPill>[0]).onQuery("o");
+ const { tree } = render();
+ expect(sectionOrder(tree)).not.toContain(UNREAD_SECTION_ID);
+ expect(listedBots(tree)).toEqual(["cora", "dodo"]);
+ });
+
+ it("leads the rail as a group of its own, with no heading", () => {
+ withUnread();
+ setSidebarDensity("icons");
+ const { tree } = render();
+ expect(sectionOrder(tree)).toEqual([UNREAD_SECTION_ID, BOTS_SECTION_ID, CHANNELS_SECTION_ID, userSectionId("Work")]);
+ expect(listedBots(tree)).toEqual(["cora", "dodo", "bea", "atlas", "eve"]);
+ expect(headers(tree)).toEqual([]);
+ expect(tree.filter((node) => node.type === SidebarRailSeparator)).toHaveLength(3);
+ });
+});
diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx
index cd214c953d..4c63a3858a 100644
--- a/src/components/Sidebar.tsx
+++ b/src/components/Sidebar.tsx
@@ -48,14 +48,17 @@ import {
PINNED_SECTION_ID,
PINNED_THREADS_SECTION_ID,
TOOLS_SECTION_ID,
+ UNREAD_SECTION_ID,
activeBotsFirst,
partitionSidebarBots,
partitionSidebarGroups,
pinnedCircleThreadListVisible,
sidebarSectionLabel,
+ unreadBotsApart,
userSectionId,
userSectionName,
withPrimaryTile,
+ withUnreadSection,
} from "@/lib/sidebar-layout";
import { stepKey, type BotDropPlace } from "@/lib/sidebar-bot-drop";
import { BotDropLine, botRowDropClass, useSidebarBotDrag, type BotRowDrag } from "./SidebarBotDrag";
@@ -114,6 +117,7 @@ export const MAC_TRAFFIC_LIGHT_CENTER_Y = 23;
const SECTION_LABEL_KEYS: Record<string, LocaleKey> = {
[PINNED_SECTION_ID]: "sidebar.section.pinned",
+ [UNREAD_SECTION_ID]: "sidebar.section.unread",
[CHANNELS_SECTION_ID]: "sidebar.section.channels",
[BOT_CHATS_SECTION_ID]: "sidebar.section.botChats",
[BOTS_SECTION_ID]: "sidebar.section.bots",
@@ -1096,22 +1100,15 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
const parts = partitionSidebarBots(botDrag.preview(matchingBots), { universalPins, viewerEmail, welcoming: useWelcomingBot(), searching: Boolean(q) });
const saved = simpleDesk ? withPrimaryTile(parts, myDefaultBot(state.bots, viewerEmail)?.id) : { ...parts, primary: null };
// Shown order only: drag and Alt+Up/Down keep working on the saved order, so a reorder never stores this one.
- const { primary, unsectionedChief, pinnedBots, sectionChiefs, sectionedBots, unsectionedBots } = { ...saved, ...activeBotsFirst(saved, (bot) => {
+ const { primary, unsectionedChief, pinnedBots, ...ordered } = { ...saved, ...activeBotsFirst(saved, (bot) => {
const { waiting, working } = sidebarBotStatus(bot, state.pendingQueued);
return waiting || working;
}) };
const { botChats, sectionedRooms, unsectionedRooms } = partitionSidebarGroups(visibleGroups);
const sectionNames: string[] = [...(state.sections ?? []).filter((name) => !q || name.toLowerCase().includes(q.toLowerCase())), ...botDrag.pending];
- for (const bot of sectionedBots) {
- if (!sectionNames.includes(bot.section!)) sectionNames.push(bot.section!);
- }
- for (const bot of sectionChiefs) {
- if (!sectionNames.includes(bot.section!)) sectionNames.push(bot.section!);
- }
- for (const group of sectionedRooms) {
- if (!sectionNames.includes(group.section!)) sectionNames.push(group.section!);
- }
+ for (const { section } of [...ordered.sectionedBots, ...ordered.sectionChiefs, ...sectionedRooms]) if (!sectionNames.includes(section!)) sectionNames.push(section!);
+ const { unreadBots, sectionChiefs, sectionedBots, unsectionedBots } = unreadBotsApart(ordered, !q);
const drops = botDrag.arrange({ enabled: (sections.interactive || density === "icons") && !phone, withinList: density === "icons", main: saved.unsectionedBots, sectioned: saved.sectionedBots, departments: sectionNames, bots: state.bots, taken: departmentNames(state) });
const naturalSectionIds = [
...(pinnedBots.length > 0 && !universalPins && !simpleDesk ? [PINNED_SECTION_ID] : []),
@@ -1121,7 +1118,7 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
...sectionNames.map(userSectionId),
];
const layout = sections.arrange(naturalSectionIds);
- const sectionIds = layout.sectionIds;
+ const sectionIds = withUnreadSection(layout.sectionIds, unreadBots.length > 0);
const showPinnedCircleThreads = !simpleDesk && pinnedCircleThreadListVisible(pinnedCircles, density, pinnedBots.length);
const tiles = simpleDesk && (primary !== null || pinnedBots.length > 0);
const { interactive: layoutInteractive, collapsed: sectionCollapsed, toggle: toggleSection } = sections;
@@ -1130,7 +1127,7 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
const attention = crossBotAttentionThreads(state.bots, state.pendingQueued, undefined, state.groups);
const pinnedThreads = crossBotPinnedThreads(state.bots, state.groups, state.pendingQueued);
const pendingBotUndo = teamFeedback?.restoreBot;
- const botRow = (bot: Bot) => botRowProps(state, dispatch, bot, { density, query: q, onMenu: setMenu, renameRequest: renameRequest?.botId === bot.id ? renameRequest.nonce : 0, ...drops.row(bot.id) });
+ const botRow = (bot: Bot, fixed = false) => botRowProps(state, dispatch, bot, { density, query: q, onMenu: setMenu, renameRequest: renameRequest?.botId === bot.id ? renameRequest.nonce : 0, ...(fixed ? {} : drops.row(bot.id)) });
const railSearch = () => {
if (collapseToIcons) return openCommandPalette();
setSearchOpen(true);
@@ -1392,7 +1389,9 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
const sectionBotItems =
id === PINNED_SECTION_ID
? pinnedBots
- : id === BOTS_SECTION_ID
+ : id === UNREAD_SECTION_ID
+ ? unreadBots
+ : id === BOTS_SECTION_ID
? unsectionedBots
: sectionName
? sectionedBots.filter((bot) => bot.section === sectionName)
@@ -1436,7 +1435,7 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
collapsed={collapsed}
attention={attention}
onToggle={layoutInteractive ? () => toggleSection(id) : undefined}
- {...layout.header(id)} naming={drops.naming(sectionName)} dropInto={drops.into(sectionName)}
+ {...layout.header(id)} {...(id === UNREAD_SECTION_ID && { count: unreadBots.length, reorderable: false })} naming={drops.naming(sectionName)} dropInto={drops.into(sectionName)}
onDelete={!simple && !remoteClient && sectionName ? () => setDeletingTeam(sectionName) : undefined} onShare={!simple && !remoteClient && sectionName ? () => setShareTeam(sectionName) : undefined}
/>
)}
@@ -1464,7 +1463,7 @@ export const Sidebar = memo(function Sidebar({ open, onClose, collapseToIcons =
row={botRow}
listItem={BotListItem}
/>
- ) : sectionBotItems.map((bot) => <BotListItem key={bot.id} {...botRow(bot)} />)}
+ ) : sectionBotItems.map((bot) => <BotListItem key={bot.id} {...botRow(bot, id === UNREAD_SECTION_ID)} />)}
{!remoteClient && sectionName && layoutInteractive && !drops.naming(sectionName) && (!simple || sectionChiefItems.length + sectionGroupItems.length + sectionBotItems.length === 0) && (
<button onClick={() => setMoveToTeam(sectionName)} aria-label={t(state.bots.some(bot => !bot.hidden && bot.section?.trim() === sectionName) ? "team.manageBotsIn" : "team.addBotsTo", { name: sectionName })}
className="mx-3 my-1 flex items-center gap-1.5 rounded-md px-2 py-1.5 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink">
diff --git a/src/components/SidebarSectionHeader.tsx b/src/components/SidebarSectionHeader.tsx
index 75ea4c4a57..eb2b276982 100644
--- a/src/components/SidebarSectionHeader.tsx
+++ b/src/components/SidebarSectionHeader.tsx
@@ -11,6 +11,7 @@ import type { SectionNaming } from "./SidebarBotDrag";
export function SidebarSectionHeader({
name,
+ count,
collapsed,
attention,
alert,
@@ -31,6 +32,8 @@ export function SidebarSectionHeader({
dropInto = false,
}: {
name: string;
+ /** How many rows the section holds, for a section whose size is the point of it. */
+ count?: number;
collapsed: boolean;
attention?: SidebarSectionAttention;
alert?: boolean;
@@ -74,6 +77,8 @@ export function SidebarSectionHeader({
? t("sidebar.section.expand", { name })
: t("sidebar.section.collapse", { name });
+ const counted = count !== undefined;
+ const size = counted && <span data-section-count="" className={cn("shrink-0 text-[12px] leading-4 tabular-nums text-ink-tertiary", line && "me-auto")}>{count}</span>;
const dropMark = dropInto ? "bg-accent/10 outline outline-2 -outline-offset-2 outline-accent/70" : undefined;
if (line) {
@@ -102,13 +107,15 @@ export function SidebarSectionHeader({
title={toggleTitle}
className="flex min-w-0 flex-1 items-center gap-1.5 rounded text-left focus-visible:outline focus-visible:outline-2 focus-visible:outline-focus"
>
- <span className="min-w-0 flex-1 truncate text-[13px] leading-[18px] text-ink-secondary">{name}</span>
+ <span className={cn("min-w-0 truncate text-[13px] leading-[18px] text-ink-secondary", !counted && "flex-1")}>{name}</span>
+ {size}
{collapsed && <SectionAttention attention={attention} label={attentionLabel} alert={alert} />}
{tail}
</button>
) : (
<div className="flex min-w-0 flex-1 items-center gap-1.5">
- <span className="min-w-0 flex-1 truncate text-[13px] leading-[18px] text-ink-secondary">{name}</span>
+ <span className={cn("min-w-0 truncate text-[13px] leading-[18px] text-ink-secondary", !counted && "flex-1")}>{name}</span>
+ {size}
{attentionLabel && <span className="sr-only">{attentionLabel}</span>}
{tail}
</div>
@@ -146,6 +153,7 @@ export function SidebarSectionHeader({
<span className="truncate text-[13px] leading-[18px] text-ink-secondary">
{name}
</span>
+ {size}
<Chevron size={12} className="shrink-0 text-ink-secondary" aria-hidden="true" />
<SectionAttention attention={attention} label={attentionLabel} alert={alert} />
</button>
@@ -154,6 +162,7 @@ export function SidebarSectionHeader({
<span className="truncate text-[13px] leading-[18px] text-ink-secondary">
{name}
</span>
+ {size}
{attentionLabel && <span className="sr-only">{attentionLabel}</span>}
</div>
)}
diff --git a/src/lib/sidebar-layout.test.ts b/src/lib/sidebar-layout.test.ts
index 9565572474..bb11753ea5 100644
--- a/src/lib/sidebar-layout.test.ts
+++ b/src/lib/sidebar-layout.test.ts
@@ -6,6 +6,7 @@ import {
BOTS_SECTION_ID,
CHANNELS_SECTION_ID,
PINNED_SECTION_ID,
+ UNREAD_SECTION_ID,
mergeSectionOrder,
moveSection,
orderedSidebarSections,
@@ -20,9 +21,11 @@ import {
sidebarSectionLabel,
simpleOrderedSections,
simpleSidebarSections,
+ unreadBotsApart,
userSectionId,
userSectionName,
withPrimaryTile,
+ withUnreadSection,
} from "./sidebar-layout";
describe("sidebar virtual sections", () => {
@@ -334,3 +337,48 @@ describe("active bots first", () => {
expect(parts.sectionedBots).toEqual(["w1", "h1", "w2"]);
});
});
+
+describe("the unread section", () => {
+ const read = (id: string) => ({ id, unread: false });
+ const thread = (unread: boolean, updatedAt?: number, extra: { routineRunId?: string; archivedAt?: number } = {}) => ({ unread, updatedAt, createdAt: 1, ...extra });
+
+ it("takes unread bots out of their lists, newest unread conversation first, and leaves the lists otherwise as they were", () => {
+ const parts = {
+ sectionChiefs: [{ id: "lead", unread: true, tasks: [thread(true, 50), thread(false, 90)] }],
+ sectionedBots: [read("w1"), { id: "w2", unread: true, tasks: [thread(true, 70), thread(true, 10)] }],
+ unsectionedBots: [{ id: "a", unread: true, messages: [{ at: 5 }, { at: 60 }] }, read("b"), { id: "c", unread: true }],
+ };
+ const apart = unreadBotsApart(parts);
+ expect(apart.unreadBots.map((bot) => bot.id)).toEqual(["w2", "a", "lead", "c"]);
+ expect(apart.sectionChiefs).toEqual([]);
+ expect(apart.sectionedBots.map((bot) => bot.id)).toEqual(["w1"]);
+ expect(apart.unsectionedBots.map((bot) => bot.id)).toEqual(["b"]);
+ expect(parts.unsectionedBots).toHaveLength(3);
+ });
+
+ it("counts a bot unread exactly as its row's dot does: a routine run or an archived conversation does not", () => {
+ const parts = {
+ sectionChiefs: [],
+ sectionedBots: [],
+ unsectionedBots: [
+ { id: "run", unread: true, tasks: [thread(true, 9, { routineRunId: "r" })] },
+ { id: "old", unread: true, tasks: [thread(true, 9, { archivedAt: 3 })] },
+ { id: "flag", unread: true, tasks: [thread(false, 9)] },
+ ],
+ };
+ expect(unreadBotsApart(parts).unreadBots).toEqual([]);
+ });
+
+ it("moves nothing while it is off", () => {
+ const parts = { sectionChiefs: [], sectionedBots: [], unsectionedBots: [{ id: "a", unread: true }] };
+ expect(unreadBotsApart(parts, false)).toEqual({ ...parts, unreadBots: [] });
+ });
+
+ it("goes under the pinned bots when they lead the list, at the top otherwise, and nowhere with nothing unread", () => {
+ expect(withUnreadSection([PINNED_SECTION_ID, BOTS_SECTION_ID], true)).toEqual([PINNED_SECTION_ID, UNREAD_SECTION_ID, BOTS_SECTION_ID]);
+ expect(withUnreadSection([BOTS_SECTION_ID, PINNED_SECTION_ID], true)).toEqual([UNREAD_SECTION_ID, BOTS_SECTION_ID, PINNED_SECTION_ID]);
+ expect(withUnreadSection([], true)).toEqual([UNREAD_SECTION_ID]);
+ expect(withUnreadSection([BOTS_SECTION_ID], false)).toEqual([BOTS_SECTION_ID]);
+ expect(sidebarSectionLabel(UNREAD_SECTION_ID)).toBe("Unread");
+ });
+});
diff --git a/src/lib/sidebar-layout.ts b/src/lib/sidebar-layout.ts
index e49caee9b9..1dd355b580 100644
--- a/src/lib/sidebar-layout.ts
+++ b/src/lib/sidebar-layout.ts
@@ -4,8 +4,10 @@ import { t } from "./i18n";
import type { LocaleKey } from "@/locales";
import type { DefaultBotFields } from "../../shared/default-bot";
import { hiddenFromSidebar, someoneElsesDefaultBot } from "./default-bot";
+import { botShowsUnread } from "./bot-unread";
export const PINNED_SECTION_ID = "builtin:pinned";
+export const UNREAD_SECTION_ID = "builtin:unread";
export const CHANNELS_SECTION_ID = "builtin:channels";
export const BOT_CHATS_SECTION_ID = "builtin:bot-chats";
export const BOTS_SECTION_ID = "builtin:bots";
@@ -59,6 +61,7 @@ export function userSectionName(id: SidebarSectionId): string | null {
export function sidebarSectionLabel(id: SidebarSectionId): string {
if (id === PINNED_SECTION_ID) return "Pinned";
+ if (id === UNREAD_SECTION_ID) return "Unread";
if (id === CHANNELS_SECTION_ID) return "Group chats";
if (id === BOT_CHATS_SECTION_ID) return "Bot threads";
if (id === BOTS_SECTION_ID) return "Bots";
@@ -151,6 +154,34 @@ export function activeBotsFirst<T>(parts: { pinnedBots: T[]; sectionedBots: T[];
return { pinnedBots: first(parts.pinnedBots), sectionedBots: first(parts.sectionedBots), unsectionedBots: first(parts.unsectionedBots) };
}
+type UnreadListBot = {
+ unread?: boolean;
+ tasks?: ReadonlyArray<{ unread?: boolean; routineRunId?: string; archivedAt?: number; updatedAt?: number; createdAt?: number }> | null;
+ messages?: ReadonlyArray<{ at: number }>;
+};
+
+function unreadSince(bot: UnreadListBot): number {
+ const threads = (bot.tasks ?? []).filter((task) => task.unread && !task.routineRunId && task.archivedAt === undefined);
+ if (threads.length === 0) return bot.messages?.at(-1)?.at ?? 0;
+ return Math.max(...threads.map((task) => task.updatedAt ?? task.createdAt ?? 0));
+}
+
+/** Bots showing unread leave their department or the main list for one list of their own, newest first, and go back
+ * once read. Pinned bots and the main Chief keep their place above it. Only how the list is shown changes. */
+export function unreadBotsApart<T extends UnreadListBot>(parts: { sectionChiefs: T[]; sectionedBots: T[]; unsectionedBots: T[] }, enabled = true) {
+ if (!enabled) return { ...parts, unreadBots: [] as T[] };
+ const read = (bots: T[]) => bots.filter((bot) => !botShowsUnread(bot));
+ const unreadBots = [...parts.unsectionedBots, ...parts.sectionChiefs, ...parts.sectionedBots].filter(botShowsUnread)
+ .map((bot) => ({ bot, since: unreadSince(bot) })).sort((a, b) => b.since - a.since).map(({ bot }) => bot);
+ return { unreadBots, sectionChiefs: read(parts.sectionChiefs), sectionedBots: read(parts.sectionedBots), unsectionedBots: read(parts.unsectionedBots) };
+}
+
+/** Unread sits under the pinned bots when they lead the list and above everything else otherwise. */
+export function withUnreadSection(ids: SidebarSectionId[], shown: boolean): SidebarSectionId[] {
+ if (!shown) return ids;
+ return ids[0] === PINNED_SECTION_ID ? [PINNED_SECTION_ID, UNREAD_SECTION_ID, ...ids.slice(1)] : [UNREAD_SECTION_ID, ...ids];
+}
+
export function partitionSidebarGroups<T extends SidebarGroup>(groups: T[]) {
const botChats = groups.filter((group) => Boolean(group.dm));
const rooms = groups.filter((group) => !group.dm);
diff --git a/src/locales/de.json b/src/locales/de.json
index 7108cb411f..302741f0e2 100644
--- a/src/locales/de.json
+++ b/src/locales/de.json
@@ -819,6 +819,7 @@
"sidebar.preview.signedOut": "{name} ist nicht angemeldet",
"sidebar.preview.you": "Du: {text}",
"sidebar.section.pinned": "Angeheftet",
+ "sidebar.section.unread": "Ungelesen",
"sidebar.section.botChats": "Bot-Threads",
"sidebar.section.bots": "Bots",
"sidebar.section.moved": "{name} auf Position {position} von {count} verschoben",
diff --git a/src/locales/en.json b/src/locales/en.json
index 350b00b653..76d63a5864 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -2261,6 +2261,7 @@
"sidebar.preview.signedOut": "{name} isn't signed in",
"sidebar.preview.you": "You: {text}",
"sidebar.section.pinned": "Pinned",
+ "sidebar.section.unread": "Unread",
"sidebar.section.channels": "Group chats",
"sidebar.section.botChats": "Bot threads",
"sidebar.section.bots": "Bots",
diff --git a/src/locales/es.json b/src/locales/es.json
index b224b11b2e..06837aca43 100644
--- a/src/locales/es.json
+++ b/src/locales/es.json
@@ -1516,6 +1516,7 @@
"sidebar.preview.signedOut": "{name} no tiene la sesión iniciada",
"sidebar.preview.you": "Tú: {text}",
"sidebar.section.pinned": "Fijados",
+ "sidebar.section.unread": "No leídos",
"sidebar.section.channels": "Chats de grupo",
"sidebar.section.botChats": "Hilos entre bots",
"sidebar.section.bots": "Bots",
diff --git a/src/locales/fr.json b/src/locales/fr.json
index 6ff1742c86..7dde6844f3 100644
--- a/src/locales/fr.json
+++ b/src/locales/fr.json
@@ -625,6 +625,7 @@
"sidebar.preview.signedOut": "{name} n’est pas connecté",
"sidebar.preview.you": "Vous : {text}",
"sidebar.section.pinned": "Épinglés",
+ "sidebar.section.unread": "Non lus",
"sidebar.section.botChats": "Fils entre bots",
"sidebar.section.bots": "Bots",
"sidebar.section.moved": "{name} déplacé en position {position} sur {count}",
diff --git a/src/locales/hi.json b/src/locales/hi.json
index 347bd87f9d..3286d71f70 100644
--- a/src/locales/hi.json
+++ b/src/locales/hi.json
@@ -623,6 +623,7 @@
"sidebar.preview.signedOut": "{name} में साइन इन नहीं है",
"sidebar.preview.you": "आप: {text}",
"sidebar.section.pinned": "पिन किए गए",
+ "sidebar.section.unread": "अपठित",
"sidebar.section.botChats": "बॉट के थ्रेड",
"sidebar.section.bots": "बॉट",
"sidebar.section.moved": "{name} को {count} में से स्थान {position} पर ले जाया गया",
diff --git a/src/locales/it.json b/src/locales/it.json
index fb4742c2f5..935c4496ec 100644
--- a/src/locales/it.json
+++ b/src/locales/it.json
@@ -2250,6 +2250,7 @@
"sidebar.preview.signedOut": "{name} non ha effettuato l'accesso",
"sidebar.preview.you": "Tu: {text}",
"sidebar.section.pinned": "Fissati",
+ "sidebar.section.unread": "Non letti",
"sidebar.section.channels": "Chat di gruppo",
"sidebar.section.botChats": "Thread dei bot",
"sidebar.section.bots": "Bot",
diff --git a/src/locales/ja.json b/src/locales/ja.json
index 8fb42ed2e3..f8d5089a02 100644
--- a/src/locales/ja.json
+++ b/src/locales/ja.json
@@ -1865,6 +1865,7 @@
"sidebar.preview.signedOut": "{name} にサインインしていません",
"sidebar.preview.you": "あなた:{text}",
"sidebar.section.pinned": "ピン留め",
+ "sidebar.section.unread": "未読",
"sidebar.section.channels": "グループチャット",
"sidebar.section.botChats": "ボット間のスレッド",
"sidebar.section.bots": "ボット",
diff --git a/src/locales/ko.json b/src/locales/ko.json
index 676162e612..882b2339ec 100644
--- a/src/locales/ko.json
+++ b/src/locales/ko.json
@@ -1776,6 +1776,7 @@
"sidebar.preview.signedOut": "{name}이(가) 로그인되어 있지 않아요",
"sidebar.preview.you": "나: {text}",
"sidebar.section.pinned": "고정됨",
+ "sidebar.section.unread": "읽지 않음",
"sidebar.section.channels": "그룹 채팅",
"sidebar.section.botChats": "봇 스레드",
"sidebar.section.bots": "봇",
diff --git a/src/locales/pl.json b/src/locales/pl.json
index f77375de54..f8dee4c769 100644
--- a/src/locales/pl.json
+++ b/src/locales/pl.json
@@ -1687,6 +1687,7 @@
"sidebar.preview.signedOut": "{name}: brak zalogowania",
"sidebar.preview.you": "Ty: {text}",
"sidebar.section.pinned": "Przypięte",
+ "sidebar.section.unread": "Nieprzeczytane",
"sidebar.section.channels": "Czaty grupowe",
"sidebar.section.botChats": "Wątki botów",
"sidebar.section.bots": "Boty",
diff --git a/src/locales/pt-br.json b/src/locales/pt-br.json
index e060f07de9..d51c8356f4 100644
--- a/src/locales/pt-br.json
+++ b/src/locales/pt-br.json
@@ -2082,6 +2082,7 @@
"sidebar.preview.signedOut": "{name} está sem login",
"sidebar.preview.you": "Você: {text}",
"sidebar.section.pinned": "Fixados",
+ "sidebar.section.unread": "Não lidas",
"sidebar.section.channels": "Chats em grupo",
"sidebar.section.botChats": "Conversas dos bots",
"sidebar.section.bots": "Bots",
diff --git a/src/locales/ru.json b/src/locales/ru.json
index a1244943cf..b3e4278c63 100644
--- a/src/locales/ru.json
+++ b/src/locales/ru.json
@@ -1692,6 +1692,7 @@
"sidebar.preview.signedOut": "{name} не выполнен вход",
"sidebar.preview.you": "Вы: {text}",
"sidebar.section.pinned": "Закреплённые",
+ "sidebar.section.unread": "Непрочитанные",
"sidebar.section.channels": "Групповые чаты",
"sidebar.section.botChats": "Потоки ботов",
"sidebar.section.bots": "Боты",
diff --git a/src/locales/tr.json b/src/locales/tr.json
index c46ee40ba7..fa79f71d9e 100644
--- a/src/locales/tr.json
+++ b/src/locales/tr.json
@@ -1220,6 +1220,7 @@
"sidebar.preview.signedOut": "{name} oturum açmamış",
"sidebar.preview.you": "Siz: {text}",
"sidebar.section.pinned": "Sabitlenenler",
+ "sidebar.section.unread": "Okunmamış",
"sidebar.section.channels": "Grup sohbetleri",
"sidebar.section.botChats": "Bot konuları",
"sidebar.section.bots": "Botlar",
diff --git a/src/locales/uk.json b/src/locales/uk.json
index dc1f35073e..ec700a9d99 100644
--- a/src/locales/uk.json
+++ b/src/locales/uk.json
@@ -723,6 +723,7 @@
"sidebar.preview.signedOut": "У {name} не виконано вхід",
"sidebar.preview.you": "Ви: {text}",
"sidebar.section.pinned": "Закріплені",
+ "sidebar.section.unread": "Непрочитані",
"sidebar.section.channels": "Групові чати",
"sidebar.section.botChats": "Гілки ботів",
"sidebar.section.bots": "Боти",
diff --git a/src/locales/vi.json b/src/locales/vi.json
index 0248562809..5f8028f451 100644
--- a/src/locales/vi.json
+++ b/src/locales/vi.json
@@ -1220,6 +1220,7 @@
"sidebar.preview.signedOut": "{name} chưa đăng nhập",
"sidebar.preview.you": "Bạn: {text}",
"sidebar.section.pinned": "Đã ghim",
+ "sidebar.section.unread": "Chưa đọc",
"sidebar.section.channels": "Group chat",
"sidebar.section.botChats": "Đoạn chat với bot",
"sidebar.section.bots": "Bot",
diff --git a/src/locales/zh-tw.json b/src/locales/zh-tw.json
index cc856c6089..fcdd5c1cb5 100644
--- a/src/locales/zh-tw.json
+++ b/src/locales/zh-tw.json
@@ -2005,6 +2005,7 @@
"sidebar.preview.signedOut": "{name} 未登入",
"sidebar.preview.you": "你:{text}",
"sidebar.section.pinned": "已釘選",
+ "sidebar.section.unread": "未讀",
"sidebar.section.channels": "聊天室",
"sidebar.section.botChats": "機器人對話",
"sidebar.section.bots": "機器人",
diff --git a/src/locales/zh.json b/src/locales/zh.json
index 57aca8af4d..410854aadd 100644
--- a/src/locales/zh.json
+++ b/src/locales/zh.json
@@ -2104,6 +2104,7 @@
"sidebar.preview.signedOut": "{name} 未登录",
"sidebar.preview.you": "你:{text}",
"sidebar.section.pinned": "已置顶",
+ "sidebar.section.unread": "未读",
"sidebar.section.channels": "群组聊天",
"sidebar.section.botChats": "机器人对话",
"sidebar.section.bots": "机器人",