diff --git a/apps/mail/components/ui/nav-main.tsx b/apps/mail/components/ui/nav-main.tsx index 91ee06fc9f..5dc02c77eb 100644 --- a/apps/mail/components/ui/nav-main.tsx +++ b/apps/mail/components/ui/nav-main.tsx @@ -311,7 +311,6 @@ function NavItem(item: NavItemProps & { href: string }) { {item.title}

{stats && - item.id?.toLowerCase() !== 'sent' && stats.some((stat) => stat.label?.toLowerCase() === item.id?.toLowerCase()) && ( {stats diff --git a/apps/server/src/lib/driver/google.ts b/apps/server/src/lib/driver/google.ts index b44542ef6f..4092d180bd 100644 --- a/apps/server/src/lib/driver/google.ts +++ b/apps/server/src/lib/driver/google.ts @@ -206,10 +206,41 @@ export class GoogleMailManager implements MailManager { Effect.all(labelRequests, { concurrency: 'unbounded' }), ); - return results.map((res) => ({ - label: res.data.name ?? res.data.id ?? '', - count: Number(res.data.threadsUnread), - })); + type LabelCount = { label: string; count: number }; + + const mapped: LabelCount[] = (await Promise.all( + results.map(async (res) => { + if ('_tag' in res && res._tag === 'LabelFetchFailed') { + return null; + } + let labelName = (res.data.name ?? res.data.id ?? '').toLowerCase(); + if (labelName === 'draft') { + labelName = 'drafts'; + } + const isTotalLabel = labelName === 'drafts' || labelName === 'sent'; + return { + label: labelName, + count: Number(isTotalLabel ? res.data.threadsTotal : res.data.threadsUnread), + }; + }), + )).filter((item): item is LabelCount => item !== null); + + // Get archive count + try { + const archiveRes = await this.gmail.users.threads.list({ + userId: 'me', + q: 'in:archive', + maxResults: 1, + }); + mapped.push({ + label: 'archive', + count: Number(archiveRes.data.resultSizeEstimate ?? 0), + }); + } catch (error: unknown) { + console.error('Failed to fetch archive count:', error); + } + + return mapped; }, { email: this.config.auth?.email }, );