Skip to content

Comments

feat: add counter for drafts, sent, archive#1734

Merged
MrgSub merged 2 commits intostagingfrom
counter
Jul 15, 2025
Merged

feat: add counter for drafts, sent, archive#1734
MrgSub merged 2 commits intostagingfrom
counter

Conversation

@retrogtx
Copy link
Contributor

@retrogtx retrogtx commented Jul 15, 2025

after

image

Summary by cubic

Added counters for Drafts, Sent, and Archive folders in the mail navigation to show the number of emails in each.

  • New Features
    • Shows total counts for Drafts and Sent.
    • Shows count for Archive.

Summary by CodeRabbit

  • New Features

    • Badges with stats are now displayed for all navigation items, including "Sent".
    • Archive counts are now included in label statistics.
  • Bug Fixes

    • Improved accuracy of label counts, including correct handling of "Drafts" and "Sent" labels.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 15, 2025

"""

Walkthrough

The changes update the navigation UI to display badge counts for all mail labels, including "sent," and enhance the backend label counting logic to normalize label names, distinguish between unread and total counts for certain labels, and add an archive count by querying Gmail. No public API signatures were changed.

Changes

File(s) Change Summary
apps/mail/components/ui/nav-main.tsx Removed condition that excluded "sent" label from badge display; badges now shown for all matching stats.
apps/server/src/lib/driver/google.ts Enhanced count method to normalize label names, use total counts for "sent"/"drafts," and add archive.

Sequence Diagram(s)

sequenceDiagram
    participant UI as NavMain UI
    participant Server as GoogleMailManager
    participant Gmail as Gmail API

    UI->>Server: Request label counts
    Server->>Gmail: Fetch label list
    Gmail-->>Server: Return label data
    Server->>Gmail: Fetch archive thread count (in:archive)
    Gmail-->>Server: Return archive count
    Server-->>UI: Return normalized label counts (including sent, drafts, archive)
    UI->>UI: Display badges for all labels with counts
Loading

Possibly related issues

Possibly related PRs

  • Staging #1054: Both PRs modify badge rendering logic in nav-main.tsx to include the "sent" label count.
  • hotfix stuff #1703: Both PRs modify the count method in GoogleMailManager, focusing on label counting and error handling.

Poem

In the warren of mail, a badge now appears,
For "sent" and "archive," it counts all your cheers.
With labels made tidy and logic refined,
The inbox and outbox are perfectly aligned.
A hop and a skip, the rabbit is proud—
Every label now counts, and badges abound! 🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b53dc6 and fafaad5.

📒 Files selected for processing (1)
  • apps/server/src/lib/driver/google.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: retrogtx
PR: Mail-0/Zero#1734
File: apps/server/src/lib/driver/google.ts:211-221
Timestamp: 2025-07-15T06:46:33.321Z
Learning: In apps/server/src/lib/driver/google.ts, the normalization of "draft" to "drafts" in the count() method is necessary because the navigation item in apps/mail/config/navigation.ts has id: 'drafts' (plural) while the Google API returns "draft" (singular). The nav-main.tsx component matches stats by comparing stat.label with item.id, so the backend must return "drafts" for the draft counter badge to appear in the sidebar.
apps/server/src/lib/driver/google.ts (6)
Learnt from: retrogtx
PR: Mail-0/Zero#1734
File: apps/server/src/lib/driver/google.ts:211-221
Timestamp: 2025-07-15T06:46:33.321Z
Learning: In apps/server/src/lib/driver/google.ts, the normalization of "draft" to "drafts" in the count() method is necessary because the navigation item in apps/mail/config/navigation.ts has id: 'drafts' (plural) while the Google API returns "draft" (singular). The nav-main.tsx component matches stats by comparing stat.label with item.id, so the backend must return "drafts" for the draft counter badge to appear in the sidebar.
Learnt from: retrogtx
PR: Mail-0/Zero#1622
File: apps/server/src/lib/email-verification.ts:189-189
Timestamp: 2025-07-05T05:27:24.623Z
Learning: During testing phases, debug logging should be kept active in apps/server/src/lib/email-verification.ts for BIMI validation and email verification debugging, even if it's verbose.
Learnt from: retrogtx
PR: Mail-0/Zero#1328
File: apps/mail/lib/hotkeys/mail-list-hotkeys.tsx:202-209
Timestamp: 2025-06-18T17:26:50.918Z
Learning: In apps/mail/lib/hotkeys/mail-list-hotkeys.tsx, the switchCategoryByIndex function using hardcoded indices for category hotkeys does not break when users reorder categories, contrary to the theoretical index-shifting issue. The actual implementation has constraints or mechanisms that prevent hotkey targeting issues.
Learnt from: snehendu098
PR: Mail-0/Zero#1323
File: apps/mail/lib/themes/theme-utils.ts:318-318
Timestamp: 2025-06-24T06:22:58.753Z
Learning: In the Mail-0/Zero theme system (apps/mail/lib/themes/theme-utils.ts), when color themes are being applied, all color values come in HSL format, so there's no need for additional format validation when converting colors with hslToHex().
Learnt from: retrogtx
PR: Mail-0/Zero#1468
File: apps/server/src/trpc/routes/mail.ts:386-391
Timestamp: 2025-06-27T04:59:29.731Z
Learning: In apps/server/src/trpc/routes/mail.ts, the attachment processing logic conditionally handles mixed attachment types - it preserves existing File-like objects with arrayBuffer methods while only converting serialized attachments that need processing through toAttachmentFiles.
Learnt from: retrogtx
PR: Mail-0/Zero#1468
File: apps/server/src/trpc/routes/mail.ts:331-331
Timestamp: 2025-06-28T03:56:09.376Z
Learning: In apps/server/src/trpc/routes/mail.ts, the user indicated they are not using ISO format for the scheduleAt parameter, despite the frontend code showing toISOString() usage in the ScheduleSendPicker component.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
apps/server/src/lib/driver/google.ts (1)

228-241: Excellent archive count implementation with proper error handling.

The archive count logic is well-implemented:

  • Uses the correct Gmail API endpoint with in:archive search query
  • Gracefully handles API failures without breaking the entire count operation
  • Uses resultSizeEstimate which is the appropriate field for count estimates
  • Maintains consistency with the rest of the label counting logic
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic found 1 issue across 2 files. Review it in cubic.dev

React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 816279b and 4b53dc6.

📒 Files selected for processing (2)
  • apps/mail/components/ui/nav-main.tsx (0 hunks)
  • apps/server/src/lib/driver/google.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/mail/components/ui/nav-main.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (2)
apps/server/src/lib/driver/google.ts (2)

209-210: LGTM! Clean type definition.

The LabelCount type definition improves code clarity and type safety for the label counting functionality.


223-237: Excellent implementation of archive count with proper error handling.

The implementation correctly:

  • Uses the appropriate Gmail search query in:archive
  • Optimizes performance with maxResults: 1
  • Uses resultSizeEstimate for efficient counting
  • Implements robust error handling that logs but doesn't break the flow

Note that this adds an additional Gmail API call, which increases quota usage, but this is reasonable for the requested feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants