Skip to content

TW-4308 Add labels for several messages part 1#4430

Open
tddang-linagora wants to merge 2 commits intomasterfrom
feature/TW-4308-Add-labels-for-several-messages-part-1
Open

TW-4308 Add labels for several messages part 1#4430
tddang-linagora wants to merge 2 commits intomasterfrom
feature/TW-4308-Add-labels-for-several-messages-part-1

Conversation

@tddang-linagora
Copy link
Copy Markdown
Collaborator

@tddang-linagora tddang-linagora commented Apr 1, 2026

Data preparation only

Summary by CodeRabbit

Release Notes

  • New Features
    • Users can now apply multiple labels to multiple selected emails simultaneously via the new "Label As" action in email selection mode
    • System displays status notifications after label operations, indicating whether they succeeded fully, partially succeeded, or failed entirely

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 1, 2026

Walkthrough

This PR introduces a bulk email labeling feature across the entire application stack. It adds the addListLabelToListEmail method to abstract datasources, concrete implementations (EmailAPI, network, repositories), and domain layers. The PR includes state classes for UI feedback (success, partial success, and failure states), an interactor that orchestrates the operation, a new "labelAs" action in email selection UI, localization strings for user-facing messages, and a helper extension method to generate batch update objects for label operations.

Possibly related PRs

Suggested labels

Label

Suggested reviewers

  • dab246
  • hoangdat
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'TW-4308 Add labels for several messages part 1' accurately describes the main change: adding functionality to apply labels to multiple emails, which is reflected across all file modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/TW-4308-Add-labels-for-several-messages-part-1

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@lib/features/email/domain/usecases/labels/add_list_label_to_list_emails_interactor.dart`:
- Around line 33-40: The method in add_list_label_to_list_emails_interactor.dart
currently treats an empty emailIds list as success because 0 ==
result.emailIdsSuccess.length; add an early guard at the start of the use case
(before calling the repository) to check if emailIds.isEmpty and immediately
yield Left(AddListLabelsToListEmailsFailure(...)) with an appropriate
empty-selection error, so you never proceed to call the repository or return
AddListLabelsToListEmailsSuccess for a no-op; update any callers/tests expecting
the previous behavior accordingly and keep references to emailIds, result,
AddListLabelsToListEmailsSuccess and AddListLabelsToListEmailsFailure to locate
the change.

In `@lib/main/utils/toast_manager.dart`:
- Around line 327-330: The toast matching checks
AddListLabelsToListEmailsSuccess before its subclass
AddListLabelsToListEmailsHasSomeFailure, causing partial-failure cases to be
treated as full success; update the conditional order in toast_manager.dart so
that AddListLabelsToListEmailsHasSomeFailure is checked before
AddListLabelsToListEmailsSuccess (or otherwise explicitly check for the
partial-failure type first) and set message using
appLocalizations.addListLabelToListEmailHasSomeFailureMessage for the
HasSomeFailure branch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 193b8500-00b9-482d-9513-e24a97f75c0a

📥 Commits

Reviewing files that changed from the base of the PR and between 1c1b16d and e78589f.

📒 Files selected for processing (16)
  • lib/features/email/data/datasource/email_datasource.dart
  • lib/features/email/data/datasource_impl/email_datasource_impl.dart
  • lib/features/email/data/datasource_impl/email_hive_cache_datasource_impl.dart
  • lib/features/email/data/datasource_impl/email_local_storage_datasource_impl.dart
  • lib/features/email/data/datasource_impl/email_session_storage_datasource_impl.dart
  • lib/features/email/data/network/email_api.dart
  • lib/features/email/data/repository/email_repository_impl.dart
  • lib/features/email/domain/repository/email_repository.dart
  • lib/features/email/domain/state/labels/add_list_label_to_list_email_state.dart
  • lib/features/email/domain/usecases/labels/add_list_label_to_list_emails_interactor.dart
  • lib/features/thread/presentation/extensions/email_selection_action_type_extension.dart
  • lib/features/thread/presentation/model/email_selection_action_type.dart
  • lib/l10n/intl_messages.arb
  • lib/main/localizations/app_localizations.dart
  • lib/main/utils/toast_manager.dart
  • model/lib/extensions/list_email_id_extension.dart

Comment on lines +33 to +40
if (emailIds.length == result.emailIdsSuccess.length) {
yield Right(AddListLabelsToListEmailsSuccess(
result.emailIdsSuccess,
labelKeywords,
labelDisplays,
));
} else if (result.emailIdsSuccess.isEmpty) {
yield Left(AddListLabelsToListEmailsFailure(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Handle empty selection before success branching.

emailIds.isEmpty currently resolves to success (0 == 0), which can show a misleading success for a no-op. Add an early guard before repository call/branching.

Proposed tweak
   ) async* {
     try {
+      if (emailIds.isEmpty) {
+        yield Left(AddListLabelsToListEmailsFailure(
+          exception: EmailIdsSuccessIsEmptyException(),
+          labelDisplays: labelDisplays,
+        ));
+        return;
+      }
+
       yield Right(AddingListLabelsToListEmails());
       final result = await _emailRepository.addListLabelToListEmail(
         session,
         accountId,
         emailIds,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@lib/features/email/domain/usecases/labels/add_list_label_to_list_emails_interactor.dart`
around lines 33 - 40, The method in
add_list_label_to_list_emails_interactor.dart currently treats an empty emailIds
list as success because 0 == result.emailIdsSuccess.length; add an early guard
at the start of the use case (before calling the repository) to check if
emailIds.isEmpty and immediately yield
Left(AddListLabelsToListEmailsFailure(...)) with an appropriate empty-selection
error, so you never proceed to call the repository or return
AddListLabelsToListEmailsSuccess for a no-op; update any callers/tests expecting
the previous behavior accordingly and keep references to emailIds, result,
AddListLabelsToListEmailsSuccess and AddListLabelsToListEmailsFailure to locate
the change.

Comment on lines +327 to +330
} else if (success is AddListLabelsToListEmailsSuccess) {
message = appLocalizations.addListLabelToListEmailSuccessfullyMessage;
} else if (success is AddListLabelsToListEmailsHasSomeFailure) {
message = appLocalizations.addListLabelToListEmailHasSomeFailureMessage;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Fix subclass check order to preserve partial-failure toast.

At Line 327, AddListLabelsToListEmailsSuccess is matched before AddListLabelsToListEmailsHasSomeFailure. Since the latter is a subclass of the former, partial failures are currently shown as full success.

🔧 Proposed fix
-    } else if (success is AddListLabelsToListEmailsSuccess) {
-      message = appLocalizations.addListLabelToListEmailSuccessfullyMessage;
-    } else if (success is AddListLabelsToListEmailsHasSomeFailure) {
+    } else if (success is AddListLabelsToListEmailsHasSomeFailure) {
       message = appLocalizations.addListLabelToListEmailHasSomeFailureMessage;
+    } else if (success is AddListLabelsToListEmailsSuccess) {
+      message = appLocalizations.addListLabelToListEmailSuccessfullyMessage;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/main/utils/toast_manager.dart` around lines 327 - 330, The toast matching
checks AddListLabelsToListEmailsSuccess before its subclass
AddListLabelsToListEmailsHasSomeFailure, causing partial-failure cases to be
treated as full success; update the conditional order in toast_manager.dart so
that AddListLabelsToListEmailsHasSomeFailure is checked before
AddListLabelsToListEmailsSuccess (or otherwise explicitly check for the
partial-failure type first) and set message using
appLocalizations.addListLabelToListEmailHasSomeFailureMessage for the
HasSomeFailure branch.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

This PR has been deployed to https://linagora.github.io/tmail-flutter/4430.

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.

1 participant