feat: Auto contacts suggestion while composing mail
This pull request adds contact suggestions in the email composer, allowing users to quickly select frequent contacts when composing a message and even added contacts endpoint which is useful in searching as well as to get the recent contacts. To ensure a fast and responsive experience, these suggestions are cached for five minutes using Redis, which significantly improves performance and reduces redundant API calls.
Type of Change
- [ ] π Bug fix (non-breaking change which fixes an issue)
- [x] β¨ 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.)
- [x] User Interface/Experience
- [ ] Authentication/Authorization
- [ ] Data Storage/Management
- [x] 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)
- [x] Mobile responsiveness verified (if UI changes)
Security Considerations
For changes involving data or authentication:
- [ ] No sensitive data is exposed
- [ ] Authentication checks are in place
- [x] Input validation is implemented
- [ ] Rate limiting is considered (if applicable)
Checklist
- [x] I have read the CONTRIBUTING document
- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in complex areas
- [ ] I have updated the documentation
- [x] 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
Screenshots/Recordings
Before:
https://github.com/user-attachments/assets/14829394-a7d9-49e0-8430-c7656582f096
After:
https://github.com/user-attachments/assets/32041f4b-242e-428d-8e28-9c2d13e2b384
By submitting this pull request, I confirm that my contribution is made under the terms of the project's license.
Summary by CodeRabbit
Summary by CodeRabbit
-
New Features
- Introduced an autocomplete contact input for email recipients, allowing users to add, remove, and select multiple contacts with suggestions and keyboard navigation.
- Added support for pasting multiple emails and automatic validation with user feedback.
- Contact suggestions are now fetched from recent and matching contacts, improving usability and speed.
- Added API endpoints to fetch and manage cached contact data for improved performance.
-
Enhancements
- Recipient fields ("To", "Cc", "Bcc") in the email composer now use the new autocomplete input for a more streamlined experience.
- Added avatars and usage details to contact suggestions for better context.
-
Localization
- Added new English language strings for contact search and recipient input feedback.
-
Performance
- Contact data is now cached for faster suggestions and reduced loading times.
Walkthrough
This change introduces a reusable ContactAutocomplete React component for email address input with autocomplete, keyboard navigation, and validation. It centralizes all recipient input logic in the email composer, removing manual handling from EmailComposer. Supporting hooks, backend routes, and localization strings for contact suggestions are added, and the server-side contacts API is integrated into the main router.
Changes
| File(s) | Change Summary |
|---|---|
| apps/mail/components/create/contact-autocomplete.tsx | Added ContactAutocomplete component for multi-email autocomplete input with validation and UX logic. |
| apps/mail/components/create/email-composer.tsx | Refactored to use ContactAutocomplete for recipient fields; removed manual input and validation logic. |
| apps/mail/hooks/use-contacts.ts | Added hooks for contact search, recent contacts, and suggestions using TRPC and React Query. |
| apps/mail/locales/en.json | Added new localization strings for contact autocomplete and related UI messages. |
| apps/server/src/trpc/routes/contacts.ts | Added contactsRouter with endpoints for searching, listing, and clearing recent contacts, with Redis caching. |
| apps/server/src/trpc/index.ts | Integrated contactsRouter into the main TRPC app router. |
| apps/server/src/lib/schemas.ts | Removed standalone defaultUserSettings object literal. |
Sequence Diagram(s)
sequenceDiagram
participant User
participant ContactAutocomplete
participant useContactSuggestions
participant tRPC_Client
participant contactsRouter
participant Redis
participant MailDriver
User->>ContactAutocomplete: Types email input
ContactAutocomplete->>useContactSuggestions: Request suggestions (input)
useContactSuggestions->>tRPC_Client: Fetch contact suggestions
tRPC_Client->>contactsRouter: search { query }
contactsRouter->>Redis: Check cache for contacts
alt Cache hit
Redis-->>contactsRouter: Return cached contacts
else Cache miss
contactsRouter->>MailDriver: Fetch recent contacts
MailDriver-->>contactsRouter: Return contacts
contactsRouter->>Redis: Cache contacts
end
contactsRouter-->>tRPC_Client: Return suggestions
tRPC_Client-->>useContactSuggestions: Suggestions data
useContactSuggestions-->>ContactAutocomplete: Suggestions
ContactAutocomplete-->>User: Show dropdown, handle selection/validation
Possibly related PRs
- Mail-0/Zero#1294: The main PR replaces manual email input handling and paste logic in
email-composer.tsxwith a newContactAutocompletecomponent that internally manages email entry, validation, and paste behavior, whereas the retrieved PR adds a paste handler directly insideemail-composer.tsx; thus, the main PR supersedes and removes the code changed in the retrieved PR, making their changes related but the main PR refactors and replaces the retrieved PRβs functionality.
Suggested reviewers
- needleXO
- ahmetskilinc
Poem
A bunny hopped through fields of mail,
Suggesting friends with every trail.
Autocomplete now leaps ahead,
With chips and dropdowns, gently spread.
No more manual, fiddly codeβ
Just seamless contacts on the road!
πβ¨
β¨ 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.
πͺ§ 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
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai explain this code block. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin 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 pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile 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.
can caching happen on the client side instead of redis?
Yea, will make changes and cache on client side
This PR has merge conflicts and has been open for more than 3 days. It will be automatically closed. Please resolve the conflicts and reopen the PR if you'd like to continue working on it.