Skip to content

TF-4383 Handle read only labels#4412

Merged
hoangdat merged 1 commit intomasterfrom
enhancement/tf-4383-handle-read-only-labels
Mar 26, 2026
Merged

TF-4383 Handle read only labels#4412
hoangdat merged 1 commit intomasterfrom
enhancement/tf-4383-handle-read-only-labels

Conversation

@dab246
Copy link
Copy Markdown
Member

@dab246 dab246 commented Mar 25, 2026

Issue

#4383

Resolved

  • With readOnly=false:
demo1.mov
  • With readOnly=true:
Screen.Recording.2026-03-25.at.18.34.26.mov

Summary by CodeRabbit

  • New Features

    • Added label read-only state to the model and exposed a read-only indicator.
    • UI respects read-only labels: context menu and long-press can be disabled and prompting shown based on capability.
    • Session layer can read a labels capability to determine whether to ask about read-only behavior.
  • Chores

    • Re-exported labels capability types for consumer access.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a15b8f3b-40c6-49cf-8552-678e0f06ac14

📥 Commits

Reviewing files that changed from the base of the PR and between c1aef32 and 5b4c941.

📒 Files selected for processing (10)
  • labels/lib/extensions/label_extension.dart
  • labels/lib/labels.dart
  • labels/lib/model/label.dart
  • labels/lib/model/labels_capability.dart
  • lib/features/home/domain/converter/capability_properties_converter.dart
  • lib/features/home/domain/extensions/session_extensions.dart
  • lib/features/labels/presentation/label_controller.dart
  • lib/features/mailbox/presentation/base_mailbox_view.dart
  • lib/features/mailbox/presentation/widgets/labels/label_list_item.dart
  • lib/features/mailbox/presentation/widgets/labels/label_list_view.dart
✅ Files skipped from review due to trivial changes (4)
  • labels/lib/labels.dart
  • lib/features/mailbox/presentation/widgets/labels/label_list_view.dart
  • labels/lib/model/label.dart
  • labels/lib/model/labels_capability.dart
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/features/home/domain/converter/capability_properties_converter.dart
  • labels/lib/extensions/label_extension.dart

Walkthrough

Adds read-only support to labels: a nullable readOnly field on Label, an isReadOnly extension getter and copyWith parameter; introduces LabelsCapability (with version and JSON (de)serialization); extends session capability deserialization and adds getLabelsCapability(AccountId); stores labelsCapability in LabelController and exposes shouldAskReadOnly; and forwards shouldAskReadOnly through LabelListViewLabelListItem to conditionally gate UI interactions.

Possibly related PRs

Suggested reviewers

  • hoangdat
  • tddang-linagora
🚥 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 'TF-4383 Handle read only labels' clearly and specifically summarizes the main change of adding support for read-only labels across the codebase.
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 enhancement/tf-4383-handle-read-only-labels

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

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
labels/lib/extensions/label_extension.dart (1)

32-43: ⚠️ Potential issue | 🟠 Major

Preserve readOnly in copyWith to avoid dropping state.

copyWith currently rebuilds Label without readOnly, so copied labels can silently lose read-only protection.

🔧 Proposed fix
   Label copyWith({
     Id? id,
     KeyWordIdentifier? keyword,
     String? displayName,
     HexColor? color,
+    bool? readOnly,
   }) {
     return Label(
       id: id ?? this.id,
       displayName: displayName ?? this.displayName,
       keyword: keyword ?? this.keyword,
       color: color ?? this.color,
+      readOnly: readOnly ?? this.readOnly,
     );
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@labels/lib/extensions/label_extension.dart` around lines 32 - 43, The
copyWith implementation on Label is dropping the readOnly field; update
Label.copyWith to accept an optional bool? readOnly parameter and when
constructing the new Label pass readOnly: readOnly ?? this.readOnly so the
copied instance preserves existing read-only state (and can be overridden when
provided). Ensure the parameter name matches the Label.readOnly property and add
it to the returned Label constructor call.
🧹 Nitpick comments (1)
lib/features/labels/presentation/label_controller.dart (1)

55-55: Capability reactivity: optional improvement, not a correctness issue.

While _labelsCapability is a plain field, the code functions correctly because capability updates are coupled with reactive labels updates. When checkLabelSettingState updates the capability at line 77, it immediately triggers getAllLabels(), which updates labels.value (reactive). The Obx wrapper at line 401 rebuilds when labels changes, so shouldAskReadOnly is evaluated with the current capability. Converting to Rxn<LabelsCapability> would be cleaner design, but the current pattern avoids stale state through coupled updates.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/features/labels/presentation/label_controller.dart` at line 55, The field
_labelsCapability is currently a plain (nullable) LabelsCapability which relies
on coupled updates to avoid staleness; convert it to a reactive
Rxn<LabelsCapability> (e.g., Rxn<LabelsCapability> _labelsCapability = Rxn())
and update all usages: set capability via _labelsCapability.value in
checkLabelSettingState, read it via _labelsCapability.value where
shouldAskReadOnly and any other logic reference it, and ensure any side-effects
that previously called getAllLabels() still do so after updating .value so
observers (like labels and the Obx at line 401) react properly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@labels/lib/extensions/label_extension.dart`:
- Around line 32-43: The copyWith implementation on Label is dropping the
readOnly field; update Label.copyWith to accept an optional bool? readOnly
parameter and when constructing the new Label pass readOnly: readOnly ??
this.readOnly so the copied instance preserves existing read-only state (and can
be overridden when provided). Ensure the parameter name matches the
Label.readOnly property and add it to the returned Label constructor call.

---

Nitpick comments:
In `@lib/features/labels/presentation/label_controller.dart`:
- Line 55: The field _labelsCapability is currently a plain (nullable)
LabelsCapability which relies on coupled updates to avoid staleness; convert it
to a reactive Rxn<LabelsCapability> (e.g., Rxn<LabelsCapability>
_labelsCapability = Rxn()) and update all usages: set capability via
_labelsCapability.value in checkLabelSettingState, read it via
_labelsCapability.value where shouldAskReadOnly and any other logic reference
it, and ensure any side-effects that previously called getAllLabels() still do
so after updating .value so observers (like labels and the Obx at line 401)
react properly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 524612c8-663b-47ab-8045-8d3e7496384d

📥 Commits

Reviewing files that changed from the base of the PR and between a8dca32 and d0d6a7f.

📒 Files selected for processing (10)
  • labels/lib/extensions/label_extension.dart
  • labels/lib/labels.dart
  • labels/lib/model/label.dart
  • labels/lib/model/labels_capability.dart
  • lib/features/home/domain/converter/capability_properties_converter.dart
  • lib/features/home/domain/extensions/session_extensions.dart
  • lib/features/labels/presentation/label_controller.dart
  • lib/features/mailbox/presentation/base_mailbox_view.dart
  • lib/features/mailbox/presentation/widgets/labels/label_list_item.dart
  • lib/features/mailbox/presentation/widgets/labels/label_list_view.dart

@github-actions
Copy link
Copy Markdown

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

@hoangdat
Copy link
Copy Markdown
Member

  • how about adding toast when user try to long press

@dab246
Copy link
Copy Markdown
Member Author

dab246 commented Mar 26, 2026

  • how about adding toast when user try to long press

What is the purpose? No long press action is performed when readyOnly = true.

@hoangdat
Copy link
Copy Markdown
Member

What is the purpose? No long press action is performed when readyOnly = true.

To notice user that label cannot change

@dab246
Copy link
Copy Markdown
Member Author

dab246 commented Mar 26, 2026

What is the purpose? No long press action is performed when readyOnly = true.

To notice user that label cannot change

We haven't performed any action that would require a user notification.

@hoangdat hoangdat merged commit eb017b5 into master Mar 26, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants