Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion apps/mail/components/ui/nav-main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ function NavItem(item: NavItemProps & { href: string }) {
{item.title}
</p>
{stats &&
item.id?.toLowerCase() !== 'sent' &&
stats.some((stat) => stat.label?.toLowerCase() === item.id?.toLowerCase()) && (
<Badge className="text-muted-foreground ml-auto shrink-0 rounded-full border-none bg-transparent">
{stats
Expand Down
39 changes: 35 additions & 4 deletions apps/server/src/lib/driver/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
);
Expand Down