Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(channel): sort sidebar channels and highlight unread / @mention (#22859)

Arvin Xu60e6c5dbd0b9
diff --git a/locales/en-US/channel.json b/locales/en-US/channel.json
index 0ff887746fc..0a4a372402f 100644
--- a/locales/en-US/channel.json
+++ b/locales/en-US/channel.json
@@ -217,6 +217,16 @@
"settings.tab.members": "Members",
"settings.tab.reply": "Replies",
"settings.title": "Channel settings",
+ "sort.by": "Sort by",
+ "sort.by.createdAt": "Date created",
+ "sort.by.title": "Name",
+ "sort.by.updatedAt": "Last activity",
+ "sort.order": "Order",
+ "sort.order.alpha.asc": "A to Z",
+ "sort.order.alpha.desc": "Z to A",
+ "sort.order.time.asc": "Oldest first",
+ "sort.order.time.desc": "Newest first",
+ "sort.title": "Sort channels",
"startThread": "Start thread",
"status.cancelled": "Stopped",
"status.completed": "Replied",
@@ -245,5 +255,6 @@
"unarchiveSuccess": "Channel unarchived",
"unarchiveThread": "Unarchive thread",
"unarchiveThreadSuccess": "Thread unarchived",
- "unnamedAgent": "Unnamed Agent"
+ "unnamedAgent": "Unnamed Agent",
+ "unreadMentions": "Unread mentions: {{count}}"
}
diff --git a/locales/zh-CN/channel.json b/locales/zh-CN/channel.json
index 19f4092692e..bbe8fe4df8a 100644
--- a/locales/zh-CN/channel.json
+++ b/locales/zh-CN/channel.json
@@ -217,6 +217,16 @@
"settings.tab.members": "成员",
"settings.tab.reply": "回复策略",
"settings.title": "频道设置",
+ "sort.by": "排序方式",
+ "sort.by.createdAt": "创建时间",
+ "sort.by.title": "名称",
+ "sort.by.updatedAt": "最近活跃",
+ "sort.order": "顺序",
+ "sort.order.alpha.asc": "A 到 Z",
+ "sort.order.alpha.desc": "Z 到 A",
+ "sort.order.time.asc": "最早在前",
+ "sort.order.time.desc": "最新在前",
+ "sort.title": "频道排序",
"startThread": "发起线程",
"status.cancelled": "已停止",
"status.completed": "已回复",
@@ -245,5 +255,6 @@
"unarchiveSuccess": "频道已取消归档",
"unarchiveThread": "取消归档线程",
"unarchiveThreadSuccess": "线程已取消归档",
- "unnamedAgent": "未命名 Agent"
+ "unnamedAgent": "未命名 Agent",
+ "unreadMentions": "{{count}} 条未读提及"
}
diff --git a/packages/database/src/repositories/channel/__tests__/view.test.ts b/packages/database/src/repositories/channel/__tests__/view.test.ts
index 4be7c166f11..b55582bc5c2 100644
--- a/packages/database/src/repositories/channel/__tests__/view.test.ts
+++ b/packages/database/src/repositories/channel/__tests__/view.test.ts
@@ -241,6 +241,32 @@ describe('Channel public view', () => {
).toEqual([]);
});
+ it('counts unread @mentions of the caller, Threads included, until they are read', async () => {
+ const { asMember, asOwner, channel, member } = await fixture.createTeamChannel();
+ const send = (content: string, mentions: string[] = [], threadId?: string) =>
+ asOwner.send(channel.id, {
+ content,
+ mentions,
+ requestKey: content,
+ routing: 'fallback',
+ threadId,
+ });
+ await send('Hi all');
+ const first = await send('Ping', [member.id]);
+ const root = await send('Ping again', [member.id]);
+ const thread = await asOwner.createThread(channel.id, { rootMessageId: root.id });
+ const reply = await send('In a thread', [member.id], thread.id);
+
+ const listed = async () => (await asMember.list()).find((item) => item.id === channel.id);
+ expect(await listed()).toMatchObject({ mentionCount: 3, unreadCount: 4 });
+ expect((await asOwner.list()).find((item) => item.id === channel.id)?.mentionCount).toBe(0);
+
+ await asMember.markRead(channel.id, first.sequence);
+ expect(await listed()).toMatchObject({ mentionCount: 2, unreadCount: 2 });
+ await asMember.markRead(channel.id, reply.sequence);
+ expect(await listed()).toMatchObject({ mentionCount: 0, unreadCount: 0 });
+ });
+
it('preserves the actual reply author when a member is rebound', async () => {
const { asOwner, channel } = await fixture.createTeamChannel();
const original = await fixture.addAgent(channel.id, 'Original');
diff --git a/packages/database/src/repositories/channel/index.ts b/packages/database/src/repositories/channel/index.ts
index 9f7f495d4f1..cf602911f8d 100644
--- a/packages/database/src/repositories/channel/index.ts
+++ b/packages/database/src/repositories/channel/index.ts
@@ -420,6 +420,7 @@ export class ChannelRepository {
ChannelItem & {
canDelete: boolean;
lastMessage: { content: string; createdAt: Date } | null;
+ mentionCount: number;
replyJobs: ChannelReplyJob[];
unreadCount: number;
}
@@ -429,6 +430,7 @@ export class ChannelRepository {
.select({
channel: channels,
lastReadSequence: channelMembers.lastReadSequence,
+ memberId: channelMembers.id,
role: channelMembers.role,
})
.from(channels)
@@ -500,10 +502,35 @@ export class ChannelRepository {
replyJobsOf.set(channelId, jobs);
}
+ // Unread messages that @mention the caller, counted from the same read position as
+ // `unreadCount`; only channels with unread messages are scanned.
+ const unreadMemberIds = rows
+ .filter(({ channel, lastReadSequence }) => channel.sequence > (lastReadSequence ?? 0))
+ .map(({ memberId }) => memberId);
+ const mentioned = unreadMemberIds.length
+ ? await this.db
+ .select({
+ channelId: channelMessages.channelId,
+ count: sql<number>`count(*)::int`,
+ })
+ .from(channelMessages)
+ .innerJoin(channelMembers, eq(channelMembers.channelId, channelMessages.channelId))
+ .where(
+ and(
+ inArray(channelMembers.id, unreadMemberIds),
+ sql`${channelMessages.sequence} > coalesce(${channelMembers.lastReadSequence}, 0)`,
+ sql`${channelMessages.mentions} @> jsonb_build_array(${channelMembers.id}::text)`,
+ ),
+ )
+ .groupBy(channelMessages.channelId)
+ : [];
+ const mentionCountOf = new Map(mentioned.map(({ channelId, count }) => [channelId, count]));
+
return rows.map(({ channel, lastReadSequence, role }) => ({
...channel,
canDelete: hasRole(role, 'admin'),
lastMessage: lastMessageOf.get(channel.id) ?? null,
+ mentionCount: mentionCountOf.get(channel.id) ?? 0,
replyJobs: replyJobsOf.get(channel.id) ?? [],
unreadCount: Math.max(0, channel.sequence - (lastReadSequence ?? 0)),
}));
diff --git a/packages/locales/src/default/channel.ts b/packages/locales/src/default/channel.ts
index 3850777b7bf..604b8dcb136 100644
--- a/packages/locales/src/default/channel.ts
+++ b/packages/locales/src/default/channel.ts
@@ -8,7 +8,18 @@ export default {
'receipt.errorReason': 'Failure reason',
'receipt.errorUnavailable':
'No detailed reason was recorded. Check the Agent’s model and device settings before sending again.',
+ 'sort.by': 'Sort by',
+ 'sort.by.createdAt': 'Date created',
+ 'sort.by.title': 'Name',
+ 'sort.by.updatedAt': 'Last activity',
+ 'sort.order': 'Order',
+ 'sort.order.alpha.asc': 'A to Z',
+ 'sort.order.alpha.desc': 'Z to A',
+ 'sort.order.time.asc': 'Oldest first',
+ 'sort.order.time.desc': 'Newest first',
+ 'sort.title': 'Sort channels',
'title': 'Channels',
+ 'unreadMentions': 'Unread mentions: {{count}}',
'create': 'Create channel',
'submit': 'Create',
'create.onlyYou': 'Only you for now. Create it and invite members whenever you like.',
diff --git a/packages/types/src/channel.ts b/packages/types/src/channel.ts
index 3b4c2310b35..a34d2979d81 100644
--- a/packages/types/src/channel.ts
+++ b/packages/types/src/channel.ts
@@ -349,6 +349,8 @@ export interface ChannelListItem {
id: string;
/** The newest main-channel message, cut for a preview; set by the Channel list. */
lastMessage?: { content: string; createdAt: Date } | null;
+ /** Unread messages, Threads included, that @mention the caller; set by the Channel list. */
+ mentionCount?: number;
/** The project the channel is grouped under; null for a standalone channel. */
projectId: string | null;
/**
diff --git a/src/features/Channels/ChannelList.tsx b/src/features/Channels/ChannelList.tsx
index 8da04646d85..95bf765d24f 100644
--- a/src/features/Channels/ChannelList.tsx
+++ b/src/features/Channels/ChannelList.tsx
@@ -9,13 +9,14 @@ import {
AccordionTrigger,
ActionIcon,
cx,
+ type DropdownItem,
DropdownMenu,
Flexbox,
Text,
} from '@lobehub/ui';
import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
import * as stylex from '@stylexjs/stylex';
-import { Archive, Hash, MoreHorizontal, Plus } from 'lucide-react';
+import { Archive, ArrowDownUp, Hash, MoreHorizontal, Plus } from 'lucide-react';
import { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -28,10 +29,14 @@ import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwar
import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';
import { useActiveLocation } from '@/hooks/useActiveLocation';
import { channelActions, channelSelectors, useChannelStore } from '@/store/channel';
+import { useGlobalStore } from '@/store/global';
+import type { ChannelListSort } from '@/store/global/initialState';
+import { systemStatusSelectors } from '@/store/global/selectors';
import { channelsInScope } from './channelScope';
import { openCreateChannel } from './CreateChannel';
import { matchChannel } from './paths';
+import { sortChannels } from './sortChannels';
import { threadTitle } from './threadTitle';
import { useChannelEvents } from './useChannelEvents';
import { useChannelMenu } from './useChannelMenu';
@@ -43,6 +48,9 @@ import { useThreadMenu } from './useThreadMenu';
// centres on that axis; Chromium floors fractional border widths, so 1.5px drew as 1px.
const SPINE_X = 17;
+const SORT_BYS: ChannelListSort['by'][] = ['createdAt', 'updatedAt', 'title'];
+const SORT_ORDERS: ChannelListSort['order'][] = ['desc', 'asc'];
+
const styles = stylex.create({
thread: {
position: 'relative',
@@ -76,6 +84,37 @@ const styles = stylex.create({
},
// The first thread reaches up under the Channel's icon.
firstElbow: { insetBlockStart: -8 },
+ channel: { position: 'relative' },
+ // An unread Channel gets a pill on the row's leading edge and a bright, bold title, the way
+ // Discord marks it; an @mention adds a count badge. The accordion panel clips anything
+ // outside the row, so the pill sits in the row's own inline padding.
+ unreadPill: {
+ pointerEvents: 'none',
+ position: 'absolute',
+ insetBlockStart: 14,
+ insetInlineStart: 0,
+ width: 4,
+ height: 8,
+ borderStartEndRadius: 4,
+ borderEndEndRadius: 4,
+ backgroundColor: cssVar.colorText,
+ },
+ unreadTitle: { fontWeight: 600 },
+ mentionBadge: {
+ display: 'inline-flex',
+ alignItems: 'center',
+ justifyContent: 'center',
+ minWidth: 16,
+ height: 16,
+ paddingInline: 4,
+ borderRadius: 999,
+ fontSize: 10,
+ fontWeight: 600,
+ lineHeight: 1,
+ color: '#fff',
+ backgroundColor: cssVar.colorError,
+ cursor: 'pointer',
+ },
});
const ChannelThreads = ({
@@ -166,7 +205,12 @@ const EnabledChannelSection = ({ itemKey = 'channels', projectId }: ChannelSecti
const slug = useActiveWorkspaceSlug();
const sync = channelActions.useFetchList();
const allChannels = useChannelStore(channelSelectors.list);
- const channels = useMemo(() => channelsInScope(allChannels, projectId), [allChannels, projectId]);
+ const sort = useGlobalStore(systemStatusSelectors.channelListSort);
+ const updateSystemStatus = useGlobalStore((s) => s.updateSystemStatus);
+ const channels = useMemo(() => {
+ const scoped = channelsInScope(allChannels, projectId);
+ return scoped && sortChannels(scoped, sort);
+ }, [allChannels, projectId, sort]);
useChannelEvents();
const [showArchived, setShowArchived] = useState(false);
@@ -177,28 +221,81 @@ const EnabledChannelSection = ({ itemKey = 'channels', projectId }: ChannelSecti
const query = new URLSearchParams(search);
const activeThreadId = query.get('view') === 'page' ? query.get('thread') : null;
const menuItems = useChannelMenu();
+ const setSort = (channelListSort: ChannelListSort) => updateSystemStatus({ channelListSort });
+ // Name sorts read as A–Z / Z–A; time sorts as newest / oldest first.
+ const orderLabelKey = sort.by === 'title' ? 'alpha' : 'time';
+ const sortMenuItems: DropdownItem[] = [
+ {
+ children: SORT_BYS.map((by) => ({
+ checked: sort.by === by,
+ key: `sort-by-${by}`,
+ label: t(`sort.by.${by}`),
+ onCheckedChange: () => setSort({ ...sort, by }),
+ type: 'checkbox' as const,
+ })),
+ key: 'sort-by',
+ label: t('sort.by'),
+ type: 'group' as const,
+ },
+ { type: 'divider' as const },
+ {
+ children: SORT_ORDERS.map((order) => ({
+ checked: sort.order === order,
+ key: `sort-order-${order}`,
+ label: t(`sort.order.${orderLabelKey}.${order}`),
+ onCheckedChange: () => setSort({ ...sort, order }),
+ type: 'checkbox' as const,
+ })),
+ key: 'sort-order',
+ label: t('sort.order'),
+ type: 'group' as const,
+ },
+ ];
const renderChannel = (channel: ChannelListItem) => {
const path = CHANNEL_URL(channel.id, null, channel.projectId);
const open = activeChannelId === channel.id;
+ // The open Channel is being read; its count clears once the read receipt lands.
+ const unread = !open && (channel.unreadCount ?? 0) > 0;
+ const mentions = open ? 0 : (channel.mentionCount ?? 0);
return (
- <Flexbox key={channel.id}>
+ <Flexbox key={channel.id} {...stylex.props(styles.channel)}>
+ {unread && <span aria-hidden {...stylex.props(styles.unreadPill)} />}
<NavItem
active={open && !activeThreadId}
aria-current={open && !activeThreadId ? 'page' : undefined}
contextMenuItems={() => menuItems(channel)}
data-channel-id={channel.id}
href={buildWorkspaceAwarePath(path, slug)}
- icon={Hash}
- // The glyph fills its whole box, so it reads larger than other nav icons at 18px.
- iconSize={14}
- title={channel.title}
+ titleColor={unread ? cssVar.colorText : undefined}
actions={() => (
<DropdownMenu items={menuItems(channel)}>
<ActionIcon icon={MoreHorizontal} size="small" title={t('more', { ns: 'common' })} />
</DropdownMenu>
)}
+ extra={
+ mentions > 0 ? (
+ <span
+ aria-label={t('unreadMentions', { count: mentions })}
+ {...stylex.props(styles.mentionBadge)}
+ // NavItem stops clicks inside `extra`; the badge still opens the Channel.
+ onClick={() => navigate(path)}
+ >
+ {mentions > 99 ? '99+' : mentions}
+ </span>
+ ) : undefined
+ }
+ title={
+ unread ? (
+ <span {...stylex.props(styles.unreadTitle)}>{channel.title}</span>
+ ) : (
+ channel.title
+ )
+ }
onClick={() => navigate(path)}
+ icon={Hash}
+ // The glyph fills its whole box, so it reads larger than other nav icons at 18px.
+ iconSize={14}
/>
{open && (
<ChannelThreads
@@ -235,6 +332,15 @@ const EnabledChannelSection = ({ itemKey = 'channels', projectId }: ChannelSecti
accordionStyles.actionBorderless,
)}
>
+ <DropdownMenu items={sortMenuItems} placement="bottomRight">
+ <ActionIcon
+ aria-label={t('sort.title')}
+ icon={ArrowDownUp}
+ size="small"
+ title={t('sort.title')}
+ onClick={(event) => event.stopPropagation()}
+ />
+ </DropdownMenu>
<ActionIcon
aria-label={t('create')}
icon={Plus}
diff --git a/src/features/Channels/sortChannels.test.ts b/src/features/Channels/sortChannels.test.ts
new file mode 100644
index 00000000000..b80dca25180
--- /dev/null
+++ b/src/features/Channels/sortChannels.test.ts
@@ -0,0 +1,49 @@
+import { describe, expect, it } from 'vitest';
+
+import { sortChannels } from './sortChannels';
+
+const channel = (id: string, title: string, createdAt: string, updatedAt?: string) => ({
+ createdAt: new Date(createdAt),
+ id,
+ title,
+ updatedAt: updatedAt ? new Date(updatedAt) : undefined,
+});
+
+const channels = [
+ channel('a', 'Beta', '2026-01-02', '2026-03-01'),
+ channel('b', 'alpha', '2026-01-03'),
+ channel('c', 'Gamma', '2026-01-01', '2026-02-01'),
+];
+
+const ids = (list: { id: string }[]) => list.map((item) => item.id);
+
+describe('sortChannels', () => {
+ it('orders by creation time in both directions', () => {
+ expect(ids(sortChannels(channels, { by: 'createdAt', order: 'desc' }))).toEqual([
+ 'b',
+ 'a',
+ 'c',
+ ]);
+ expect(ids(sortChannels(channels, { by: 'createdAt', order: 'asc' }))).toEqual(['c', 'a', 'b']);
+ });
+
+ it('orders by activity, falling back to creation time for a Channel never updated', () => {
+ expect(ids(sortChannels(channels, { by: 'updatedAt', order: 'desc' }))).toEqual([
+ 'a',
+ 'c',
+ 'b',
+ ]);
+ expect(ids(sortChannels(channels, { by: 'updatedAt', order: 'asc' }))).toEqual(['b', 'c', 'a']);
+ });
+
+ it('orders by name ignoring case', () => {
+ expect(ids(sortChannels(channels, { by: 'title', order: 'asc' }))).toEqual(['b', 'a', 'c']);
+ expect(ids(sortChannels(channels, { by: 'title', order: 'desc' }))).toEqual(['c', 'a', 'b']);
+ });
+
+ it('leaves the input untouched', () => {
+ const before = ids(channels);
+ sortChannels(channels, { by: 'title', order: 'asc' });
+ expect(ids(channels)).toEqual(before);
+ });
+});
diff --git a/src/features/Channels/sortChannels.ts b/src/features/Channels/sortChannels.ts
new file mode 100644
index 00000000000..6e7824ad542
--- /dev/null
+++ b/src/features/Channels/sortChannels.ts
@@ -0,0 +1,27 @@
+import type { ChannelListItem } from '@lobechat/types';
+
+import type { ChannelListSort } from '@/store/global/initialState';
+
+type SortableChannel = Pick<ChannelListItem, 'createdAt' | 'id' | 'title' | 'updatedAt'>;
+
+const time = (value: Date | string | undefined) => (value ? new Date(value).getTime() : 0);
+
+/**
+ * Order a sidebar Channel section. A Channel never updated sorts by its creation time when
+ * ordering by activity; ties keep the newest Channel first.
+ */
+export const sortChannels = <T extends SortableChannel>(
+ channels: T[],
+ { by, order }: ChannelListSort,
+): T[] => {
+ const direction = order === 'asc' ? 1 : -1;
+ const compare = (a: T, b: T) => {
+ if (by === 'title') return a.title.localeCompare(b.title);
+ if (by === 'updatedAt')
+ return time(a.updatedAt ?? a.createdAt) - time(b.updatedAt ?? b.createdAt);
+ return time(a.createdAt) - time(b.createdAt);
+ };
+ return channels.toSorted(
+ (a, b) => direction * compare(a, b) || time(b.createdAt) - time(a.createdAt),
+ );
+};
diff --git a/src/store/channel/action.openDirect.test.ts b/src/store/channel/action.openDirect.test.ts
index a4521b442ae..586bee7b45e 100644
--- a/src/store/channel/action.openDirect.test.ts
+++ b/src/store/channel/action.openDirect.test.ts
@@ -75,6 +75,37 @@ describe('channelActions.markRead', () => {
expect(channelService.markRead).toHaveBeenCalledExactlyOnceWith('chn_000000000001', 5);
});
+ // The mention badge reappeared after switching away, until the next list poll.
+ it('clears the listed mention count when the read reaches the known sequence', async () => {
+ useChannelStore.setState({
+ listMap: {
+ all: [direct({ mentionCount: 3, sequence: 5, unreadCount: 3 } as Partial<ChannelListItem>)],
+ },
+ });
+ vi.mocked(channelService.markRead).mockResolvedValue(5 as never);
+
+ await channelActions.markRead('chn_000000000001', 5);
+
+ expect(useChannelStore.getState().listMap.all?.[0].mentionCount).toBe(0);
+ });
+
+ // A partial read leaves later mentions unread; the cache cannot split the count.
+ it('keeps the mention count for a partial read', async () => {
+ useChannelStore.setState({
+ listMap: {
+ all: [direct({ mentionCount: 2, sequence: 9, unreadCount: 4 } as Partial<ChannelListItem>)],
+ },
+ });
+ vi.mocked(channelService.markRead).mockResolvedValue(5 as never);
+
+ await channelActions.markRead('chn_000000000001', 5);
+
+ expect(useChannelStore.getState().listMap.all?.[0]).toMatchObject({
+ mentionCount: 2,
+ unreadCount: 4,
+ });
+ });
+
it('restores the count when the write fails', async () => {
useChannelStore.setState({
listMap: { all: [direct({ sequence: 5, unreadCount: 3 } as Partial<ChannelListItem>)] },
diff --git a/src/store/channel/action.ts b/src/store/channel/action.ts
index e2a48eaefe6..585082af407 100644
--- a/src/store/channel/action.ts
+++ b/src/store/channel/action.ts
@@ -92,14 +92,20 @@ class ChannelActionImpl {
return result.data.channel.id;
};
/**
- * Marks the main channel read up to `sequence`. The listed unread count drops at once, so a
- * conversation row does not keep its badge until the next list poll; a failed write restores it.
+ * Marks the main channel read up to `sequence`. The listed unread and mention counts drop at
+ * once, so a conversation row does not keep its badges until the next list poll; a failed write
+ * restores them.
+ *
+ * Mentions are counted from the same read position as `unreadCount`, so a read that reaches the
+ * known `sequence` consumes all of them. A partial read cannot be split client-side without the
+ * per-message mention data, so the cached count stays until the next list poll recomputes it.
*/
markRead = (channelId: string, sequence: number) =>
this.#private.entity.optimistic(
channelId,
(channel) => ({
...channel,
+ mentionCount: channel.sequence <= sequence ? 0 : channel.mentionCount,
unreadCount: Math.min(channel.unreadCount ?? 0, Math.max(0, channel.sequence - sequence)),
}),
() => channelService.markRead(channelId, sequence),
diff --git a/src/store/global/initialState.ts b/src/store/global/initialState.ts
index c718d88aa6c..66c5fc05ba9 100644
--- a/src/store/global/initialState.ts
+++ b/src/store/global/initialState.ts
@@ -187,6 +187,13 @@ export const DEFAULT_DOCS_PAGE_SECTION_VIEW: DocsPageSectionView = {
/** How the Contacts list is ordered: by name, or most recently updated first. */
export type ContactListSortBy = 'title' | 'updatedAt';
+/** How a sidebar Channel section orders its Channels. */
+export interface ChannelListSort {
+ /** `updatedAt` follows the latest message, so it orders by activity. */
+ by: 'createdAt' | 'title' | 'updatedAt';
+ order: 'asc' | 'desc';
+}
+
/** How the sidebar project list is ordered; `manual` follows the shared drag order. */
export type ProjectListSortBy = 'manual' | 'createdAt' | 'updatedAt';
@@ -233,6 +240,10 @@ export interface SystemStatus {
* scalars instead of index-merging arrays.
*/
assigneeAgentSelectorCollapsedGroups?: Record<string, boolean>;
+ /**
+ * Order of the sidebar Channel sections. Device-local view setting.
+ */
+ channelListSort?: ChannelListSort;
chatInputHeight?: number;
/**
* Which topicGroups are collapsed, bucketed by group mode. We persist the
diff --git a/src/store/global/selectors/systemStatus.ts b/src/store/global/selectors/systemStatus.ts
index 562d0a74891..dbc704eb9c9 100644
--- a/src/store/global/selectors/systemStatus.ts
+++ b/src/store/global/selectors/systemStatus.ts
@@ -2,6 +2,7 @@ import { type TopicGroupMode } from '@/types/topic';
import type {
AgentDocumentSort,
+ ChannelListSort,
ContactListSortBy,
DocsPageSectionKey,
DocsPageSectionView,
@@ -508,6 +509,10 @@ const DEFAULT_AGENT_DOCUMENT_SORT: AgentDocumentSort = {
};
const contactListSortBy = (s: GlobalState): ContactListSortBy =>
s.status.contactListSortBy ?? 'title';
+// The server lists Channels newest first; keep that as the default view.
+const DEFAULT_CHANNEL_LIST_SORT: ChannelListSort = { by: 'createdAt', order: 'desc' };
+const channelListSort = (s: GlobalState): ChannelListSort =>
+ s.status.channelListSort ?? DEFAULT_CHANNEL_LIST_SORT;
const projectListSortBy = (s: GlobalState): ProjectListSortBy =>
s.status.projectListSortBy ?? 'manual';
const agentDocumentSort = (s: GlobalState): AgentDocumentSort =>
@@ -562,6 +567,7 @@ export const systemStatusSelectors = {
agentBuilderPanelWidth,
agentDocumentSort,
contactListSortBy,
+ channelListSort,
projectListSortBy,
agentListExpandedGroupKeys,
agentListSidebarSectionCollapsed,