Skip to content

Comments

[ZERO-170] Toggle for 'Auto-read' emails#1473

Merged
MrgSub merged 5 commits intoMail-0:stagingfrom
adamghaida:ZERO-170
Jun 24, 2025
Merged

[ZERO-170] Toggle for 'Auto-read' emails#1473
MrgSub merged 5 commits intoMail-0:stagingfrom
adamghaida:ZERO-170

Conversation

@adamghaida
Copy link
Member

@adamghaida adamghaida commented Jun 24, 2025

Description

Users can set an "autoRead" toggle to automatically read emails on click or not.


Type of Change

Please delete options that are not relevant.

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature with breaking changes)
  • 📝 Documentation update
  • 🎨 UI/UX improvement
  • 🔒 Security enhancement
  • ⚡ Performance improvement

Areas Affected

Please check all that apply:

  • Email Integration (Gmail, IMAP, etc.)
  • User Interface/Experience
  • Authentication/Authorization
  • Data Storage/Management
  • API Endpoints
  • Documentation
  • Testing Infrastructure
  • Development Workflow
  • Deployment/Infrastructure

Testing Done

Describe the tests you've done:

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • Cross-browser testing (if UI changes)
  • Mobile responsiveness verified (if UI changes)

Security Considerations

For changes involving data or authentication:

  • No sensitive data is exposed
  • Authentication checks are in place
  • Input validation is implemented
  • Rate limiting is considered (if applicable)

Checklist

  • I have read the CONTRIBUTING document
  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in complex areas
  • I have updated the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix/feature works
  • All tests pass locally
  • Any dependent changes are merged and published

Additional Notes

none

Screenshots/Recordings

none


By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.

Summary by CodeRabbit

  • New Features
    • Added an "Auto Read" option in general settings, allowing emails to be automatically marked as read when clicked.
  • Bug Fixes
    • Improved mail list behavior to respect the new "Auto Read" setting when marking emails as read.
  • Localization
    • Added English labels and descriptions for the new "Auto Read" feature in settings.
  • Chores
    • Updated default user settings and database schema to include the "Auto Read" option.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 24, 2025

Walkthrough

A new "autoRead" boolean setting was introduced to the mail application's user settings. This setting appears in the general settings UI as a toggle, is included in localization files, and is persisted via schema and database migration updates. The mail list behavior now respects this setting when marking emails as read.

Changes

File(s) Change Summary
apps/mail/app/(routes)/settings/general/page.tsx Added "autoRead" toggle to the general settings form, with localized label and description.
apps/mail/components/mail/mail-list.tsx Modified logic to mark emails as read only if "autoRead" is enabled; added debug logs; uses useSettings hook.
apps/mail/locales/en.json Added "autoRead" and "autoReadDescription" localization strings.
apps/server/src/lib/schemas.ts Added autoRead boolean property (default: true) to defaultUserSettings and userSettingsSchema.
apps/server/src/db/migrations/0029_thin_triathlon.sql Set default JSONB value for "settings" in "mail0_user_settings" to include "autoRead" and other defaults.
apps/server/src/db/migrations/meta/0029_snapshot.json Updated schema snapshot to reflect new default settings, including "autoRead".
apps/server/src/db/migrations/0032_smiling_raider.sql Updated default JSONB for "settings" column with comprehensive defaults including "autoRead" and categories.
apps/server/src/db/migrations/meta/0032_snapshot.json Added new schema snapshot reflecting updated default settings including "autoRead" and categories.
apps/server/src/db/migrations/meta/_journal.json Added migration journal entry for migration 32 ("0032_smiling_raider").

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SettingsPage
    participant Server
    participant MailList

    User->>SettingsPage: Toggles "Auto Read" setting
    SettingsPage->>Server: Updates user settings (autoRead)
    Server-->>SettingsPage: Confirms update

    User->>MailList: Clicks on an email
    MailList->>Server: Fetches user settings (autoRead)
    alt autoRead is enabled
        MailList->>Server: Marks email as read
    else autoRead is disabled
        MailList-->>User: Does not mark as read
    end
Loading

Possibly related PRs

  • Hotfix #1358: Modifies the default JSONB value for the "settings" column in the "mail0_user_settings" table via database migrations, directly relating to user settings defaults including boolean flags like "zeroSignature" and "autoRead."
  • Feature/mark as read #599: Adds bulk "mark as read" feature with UI and action handling, related to mail read-marking logic but addressing different aspects than this PR.
  • feature/persist user settings #513: Introduces foundational persistence and API for user settings, related at the feature level as this PR builds upon that infrastructure to add "autoRead."

Suggested reviewers

  • MrgSub

Poem

🐇
In the burrows of code, a toggle appears,
"Auto Read" now listens to user frontiers.
Click an email, and—if you wish—
It marks as read, swift as a fish!
Settings and schema, all in a row,
The rabbit hops forward—onward we go!
📧✨


📜 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 8e88f56 and 7b5ac0d.

📒 Files selected for processing (8)
  • apps/mail/app/(routes)/settings/general/page.tsx (1 hunks)
  • apps/mail/components/mail/mail-list.tsx (3 hunks)
  • apps/mail/locales/en.json (1 hunks)
  • apps/server/src/db/migrations/0032_smiling_raider.sql (1 hunks)
  • apps/server/src/db/migrations/meta/0029_snapshot.json (1 hunks)
  • apps/server/src/db/migrations/meta/0032_snapshot.json (1 hunks)
  • apps/server/src/db/migrations/meta/_journal.json (1 hunks)
  • apps/server/src/lib/schemas.ts (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/server/src/db/migrations/0032_smiling_raider.sql
🚧 Files skipped from review as they are similar to previous changes (6)
  • apps/server/src/db/migrations/meta/_journal.json
  • apps/mail/locales/en.json
  • apps/mail/app/(routes)/settings/general/page.tsx
  • apps/mail/components/mail/mail-list.tsx
  • apps/server/src/lib/schemas.ts
  • apps/server/src/db/migrations/meta/0029_snapshot.json
🔇 Additional comments (1)
apps/server/src/db/migrations/meta/0032_snapshot.json (1)

944-950: Back-fill existing user_settings rows with the new autoRead key

The snapshot sets autoReadtrue only as the column‐default.
Rows that pre-date this migration will keep their previous JSONB payload and therefore lack the autoRead property, causing the backend to return null / undefined for those users.
If the application assumes a boolean and does === true checks, this will silently disable the feature for legacy accounts.

Follow-up actions:

  1. In the 0032_*.sql “up” script add a one-off update:
UPDATE public.mail0_user_settings
SET    settings = jsonb_set(settings, '{autoRead}', 'true')
WHERE  settings ? 'autoRead' = false;
  1. Optionally wrap this in a transaction to avoid partial updates.

  2. Add a regression test ensuring every settings object contains autoRead after the migration.

✨ 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

@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: 0

🧹 Nitpick comments (3)
apps/mail/components/mail/mail-list.tsx (3)

797-799: Remove debug console.log statements before production.

These debug statements should be removed as they're not suitable for production code and could clutter the browser console.

-        console.log("cooking");
         const autoRead = settingsData?.settings?.autoRead;
-        console.log("COOKED!")

798-798: Add defensive null checking for autoRead setting.

While the current implementation works, consider adding more explicit null checking for better type safety.

-        const autoRead = settingsData?.settings?.autoRead;
+        const autoRead = settingsData?.settings?.autoRead ?? true; // Default to true if undefined

Alternatively, you could use a more explicit check:

-        const autoRead = settingsData?.settings?.autoRead;
+        const autoRead = Boolean(settingsData?.settings?.autoRead);

816-825: Consider adding settingsData to the dependency array.

The handleMailClick callback uses settingsData but doesn't include it in the dependency array. While this might work due to React's optimization, it's better to be explicit about dependencies.

      [
        getSelectMode,
        handleSelectMail,
        handleMouseEnter,
        setFocusedIndex,
        optimisticMarkAsRead,
        setThreadId,
        setDraftId,
        setActiveReplyId,
+       settingsData,
      ],
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 027e913 and 8e88f56.

📒 Files selected for processing (7)
  • apps/mail/app/(routes)/settings/general/page.tsx (1 hunks)
  • apps/mail/components/mail/mail-list.tsx (3 hunks)
  • apps/mail/locales/en.json (1 hunks)
  • apps/server/src/db/migrations/0029_thin_triathlon.sql (1 hunks)
  • apps/server/src/db/migrations/meta/0029_snapshot.json (1 hunks)
  • apps/server/src/db/migrations/meta/_journal.json (1 hunks)
  • apps/server/src/lib/schemas.ts (2 hunks)
🔇 Additional comments (9)
apps/server/src/db/migrations/meta/_journal.json (1)

208-214: Migration journal entry looks correct.

The new migration entry follows the established pattern and properly tracks the database schema change for the autoRead feature.

apps/server/src/lib/schemas.ts (2)

47-47: LGTM! Consistent default value.

The autoRead: true addition to defaultUserSettings is properly implemented and aligns with the schema definition.


60-60: LGTM! Proper Zod validation with consistent default.

The schema validation for autoRead is correctly implemented with appropriate boolean type and default value that matches defaultUserSettings.

apps/mail/app/(routes)/settings/general/page.tsx (1)

263-279: LGTM! Consistent UI implementation.

The autoRead toggle follows the established pattern used for other boolean settings in the form. The Switch component, form binding, and localization usage are all properly implemented.

apps/server/src/db/migrations/0029_thin_triathlon.sql (1)

1-1: LGTM! Migration properly adds autoRead with consistent defaults.

The SQL migration correctly adds the autoRead: true property to the default JSONB settings while preserving all existing settings. The structure matches the schema definition.

apps/mail/locales/en.json (1)

390-391: LGTM! Clear and informative localization.

The localization strings for the autoRead feature are well-written with a concise label and descriptive explanation that clearly communicates the feature's functionality to users.

apps/mail/components/mail/mail-list.tsx (2)

650-650: LGTM - Settings data retrieval looks correct.

The useSettings hook is properly imported and used to retrieve settings data.


811-811: Verify the autoRead logic implementation.

The conditional logic looks correct - it only marks emails as read when both the message is unread AND autoRead is enabled. This properly respects the user's preference.

apps/server/src/db/migrations/meta/0029_snapshot.json (1)

713-713: Database schema correctly includes autoRead setting.

The default JSONB value properly includes the new autoRead setting with a sensible default value of true. This ensures that existing users will have the autoRead feature enabled by default, which aligns with typical email client behavior.

@adamghaida adamghaida marked this pull request as draft June 24, 2025 19:18
@adamghaida adamghaida marked this pull request as ready for review June 24, 2025 20:05
@adamghaida
Copy link
Member Author

pending approval, should be done from my end

@MrgSub MrgSub merged commit 8d2a00d into Mail-0:staging Jun 24, 2025
3 checks passed
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