Skip to content

ui-common: Restore mention state when editing a message#6532

Merged
gpunto merged 2 commits into
developfrom
fix/edit-mention-breaks-mentions
Jul 1, 2026
Merged

ui-common: Restore mention state when editing a message#6532
gpunto merged 2 commits into
developfrom
fix/edit-mention-breaks-mentions

Conversation

@gpunto

@gpunto gpunto commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Goal

Editing one mention in a message that has multiple mentions strips all of them. Entering edit mode never restored the composer's mention state, so selectedMentions was empty and filterMentions dropped every mention still present in the text on save.

Reported during QA: Android QA - Mentions

Closes AND-1277

Implementation

  • MessageComposerController now rebuilds selectedMentions from the message's mentionedUsers/mentionedChannel/mentionedHere/mentionedRoles/mentionedGroups when entering edit mode (both the action and the restored-session paths).
  • Dismissing an edit clears selectedMentions so restored mentions don't leak into the next message.

Testing

  • New MessageComposerControllerTest cases: removing one mention while editing keeps the others, an unchanged edit preserves mentions of every type, and dismissing an edit doesn't carry mentions into a fresh message.

Summary by CodeRabbit

  • Bug Fixes

    • Mention selections are now restored correctly when editing a message, so edited messages keep the right mentions.
    • Dismissing edit mode now clears any leftover mention selections, preventing them from carrying into the next message.
    • Editing a message with mentions now better preserves mention data across users, channels, roles, groups, and “here” mentions.
  • Tests

    • Added coverage for mention handling while editing messages and when leaving edit mode.

@gpunto gpunto added the pr:bug Bug fix label Jun 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled, or the PR is bot-authored.
  • An issue is linked (Linear ticket or GitHub issue), or the PR is bot-authored.

🎉 Great job! This PR is ready for review.

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.93 MB 5.93 MB 0.00 MB 🟢
stream-chat-android-ui-components 11.20 MB 11.20 MB 0.00 MB 🟢
stream-chat-android-compose 12.66 MB 12.66 MB 0.00 MB 🟢

@gpunto

gpunto commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

MessageComposerController gains a restoreSelectedMentions helper that rebuilds the selectedMentions set from a Message's mention fields. It is called when entering edit mode (via restoreEditMode and the Edit action branch) and selectedMentions is cleared when edit mode is dismissed. Three unit tests cover partial removal, full preservation, and post-dismiss cleanup.

Mention State in Edit Mode

Layer / File(s) Summary
restoreSelectedMentions helper and call sites
...feature/messages/composer/MessageComposerController.kt
New private helper converts all Message mention fields (mentionedUsers, mentionedChannel, mentionedHere, mentionedRoles, mentionedGroups) into a selectedMentions set and updates _state. Called from restoreEditMode, the Edit branch of performMessageAction, and dismissMessageActions (which clears to emptySet()).
Unit tests for mention lifecycle
...feature/messages/composer/MessageComposerControllerTest.kt
Three tests: editing a message then removing one mention keeps only the remaining user ID; editing without text changes preserves all mention types; dismissing edit mode clears mention state from subsequent buildNewMessage results.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • andremion

Poem

🐇 When you edit a message with @mentions galore,
The chips reappear just like they were before.
And when you dismiss, they vanish away—
No phantom mentions to ruin your day!
Hop hop, the state machine works right once more. 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely matches the main change: restoring mention state while editing messages.
Description check ✅ Passed The description covers the template's core Goal, Implementation, and Testing sections with specific, relevant details.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/edit-mention-breaks-mentions

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerControllerTest.kt (1)

1738-1826: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a restored-session mention regression test.

These additions cover performMessageAction(Edit) and dismissMessageActions(), but the new restoreEditMode(...) path in MessageComposerController is the other changed entry point in this PR. A persisted-session case asserting mention restoration there would lock down the full behavior promised by the PR.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerControllerTest.kt`
around lines 1738 - 1826, Add a regression test for the restored-session edit
flow by covering MessageComposerController.restoreEditMode(...), since the
current tests only exercise performMessageAction(Edit) and
dismissMessageActions(). Set up an edited message with mentions, restore the
edit state from a persisted session, then build a new message and assert the
expected mentions are preserved so the restore path matches the existing
edit-mode behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerControllerTest.kt`:
- Around line 1738-1826: Add a regression test for the restored-session edit
flow by covering MessageComposerController.restoreEditMode(...), since the
current tests only exercise performMessageAction(Edit) and
dismissMessageActions(). Set up an edited message with mentions, restore the
edit state from a persisted session, then build a new message and assert the
expected mentions are preserved so the restore path matches the existing
edit-mode behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5a4a7aad-b23a-4baa-bfa9-23b2c1869dc2

📥 Commits

Reviewing files that changed from the base of the PR and between 26ed3b1 and 0e09a78.

📒 Files selected for processing (2)
  • stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerController.kt
  • stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerControllerTest.kt

@gpunto gpunto marked this pull request as ready for review June 30, 2026 07:23
@gpunto gpunto requested a review from a team as a code owner June 30, 2026 07:23
@gpunto gpunto force-pushed the fix/edit-mention-breaks-mentions branch from 0e09a78 to ba1a545 Compare June 30, 2026 07:58
@gpunto gpunto changed the title ui-common: Restore mention state when editing a message compose: Reset mention suggestion list to top when suggestions change Jun 30, 2026
@gpunto gpunto marked this pull request as draft June 30, 2026 07:59
@gpunto gpunto force-pushed the fix/edit-mention-breaks-mentions branch from ba1a545 to 0e09a78 Compare June 30, 2026 08:03
@gpunto gpunto changed the title compose: Reset mention suggestion list to top when suggestions change ui-common: Restore mention state when editing a message Jun 30, 2026
@gpunto gpunto marked this pull request as ready for review June 30, 2026 08:07
@sonarqubecloud

Copy link
Copy Markdown

@gpunto gpunto enabled auto-merge (squash) June 30, 2026 13:04

@aleksandar-apostolov aleksandar-apostolov left a comment

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.

LGTM

@gpunto gpunto merged commit 65c3f38 into develop Jul 1, 2026
19 checks passed
@gpunto gpunto deleted the fix/edit-mention-breaks-mentions branch July 1, 2026 08:15
@stream-public-bot stream-public-bot added the released Included in a release label Jul 1, 2026
@stream-public-bot

Copy link
Copy Markdown
Contributor

🚀 Available in v7.5.0

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

Labels

pr:bug Bug fix released Included in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants