Skip to content

Fix sending wrong type for incomplete command messages#6236

Merged
VelikovPetar merged 2 commits intodevelopfrom
bug/AND-1115_fix_wrong_message_type_for_commands
Mar 11, 2026
Merged

Fix sending wrong type for incomplete command messages#6236
VelikovPetar merged 2 commits intodevelopfrom
bug/AND-1115_fix_wrong_message_type_for_commands

Conversation

@VelikovPetar
Copy link
Contributor

@VelikovPetar VelikovPetar commented Mar 10, 2026

Goal

Incomplete commands (messages matching the pattern /command) were incorrectly being assigned the ephemeral message type due to a regex pattern in getMessageType(). This type of messages is rejected by the backend, returning the following error for SendMessage:

HTTP FAILED: streamCode: 4, statusCode: 400, message: SendMessage failed with error: "message.type must be one of ['' regular system]" 

Implementation

Removed the COMMAND_PATTERN regex and its associated check from getMessageType(). The ephemeral type is now only assigned when there are attachments pending upload (note: this type is then set to regular after the attachments are uploaded, so we don't send the ephemeral type)

🎨 UI Changes

Before Command enabled Commands disabled
command-before.mp4
command-after.mp4
command-disabled-after.mp4

Testing

Send a message with pattern "/command" -> It should not fail. if commands are enabled, a system message should be delivered providing more info. If commands are disabled, it should be sent as a regular message.

Summary by CodeRabbit

  • Bug Fixes

    • Updated message classification logic to improve message type accuracy. Messages containing commands no longer automatically fall into the ephemeral category. Ephemeral classification now focuses on messages with pending attachment uploads, ensuring proper message display and behavior.
  • Tests

    • Removed test case validating command-based message classification.

Co-Authored-By: Claude <noreply@anthropic.com>
@VelikovPetar VelikovPetar added the pr:bug Bug fix label Mar 10, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2026

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.

🎉 Great job! This PR is ready for review.

@VelikovPetar VelikovPetar changed the title Fix wrong message type for commands Fix wrong message type for incomplete commands Mar 10, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2026

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.26 MB 5.26 MB 0.00 MB 🟢
stream-chat-android-offline 5.48 MB 5.48 MB 0.00 MB 🟢
stream-chat-android-ui-components 10.63 MB 10.63 MB 0.00 MB 🟢
stream-chat-android-compose 12.85 MB 12.85 MB 0.00 MB 🟢

@VelikovPetar VelikovPetar changed the title Fix wrong message type for incomplete commands Fix sending wrong type for incomplete command messages Mar 10, 2026
@VelikovPetar VelikovPetar marked this pull request as ready for review March 10, 2026 19:22
@VelikovPetar VelikovPetar requested a review from a team as a code owner March 10, 2026 19:22
@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Walkthrough

The changes remove the command-based EPHEMERAL message type classification from the getMessageType function, eliminating regex pattern matching for command-format text and its associated test case. The EPHEMERAL condition is narrowed to only classify messages with pending attachment uploads.

Changes

Cohort / File(s) Summary
Message Type Classification Refactor
stream-chat-android-client/.../MessageUtils.kt, stream-chat-android-state/.../MessageUtilsTest.kt
Removed command-based EPHEMERAL condition and regex pattern matching (COMMAND_PATTERN); narrowed EPHEMERAL classification to pending upload attachments only; removed testCommandMessage test case and corresponding import (java.util.regex.Pattern); added REGULAR as default classification branch.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐰 Commands cease to mark ephemeral lines,
No regex patterns in our designs,
Attachments pending—that's the sign,
With simpler logic, the code will shine!
Regular paths now intertwine,
Classification flows just fine! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: removing incorrect EPHEMERAL classification for incomplete command messages and fixing the resulting backend rejection error.
Description check ✅ Passed The description provides a clear goal explaining the bug, implementation details of the fix, UI changes with demo videos, and testing instructions. All critical sections are well-addressed.
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 docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bug/AND-1115_fix_wrong_message_type_for_commands

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

@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)
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/utils/internal/MessageUtils.kt (1)

24-33: ⚠️ Potential issue | 🟡 Minor

KDoc is now outdated after removing the command check.

The documentation still states "If the message contains a command or has attachments to upload, the type will be [MessageType.EPHEMERAL]", but the code no longer checks for commands. Update the KDoc to reflect the current behavior.

📝 Proposed fix
 /**
- * Updates the type of the [Message] based on its content.
+ * Determines the type of the [Message] based on its content.
  *
- * If the message contains a command or has attachments to upload, the type will be [MessageType.EPHEMERAL].
+ * If the message has attachments pending upload, the type will be [MessageType.EPHEMERAL].
  * If the message is a system message, the type will be [MessageType.SYSTEM].
  * Otherwise, the type will be [MessageType.REGULAR], as we cannot send messages which are not regular, ephemeral, or
  * system.
  *
  * `@param` message The message to update.
  */
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@stream-chat-android-client/src/main/java/io/getstream/chat/android/client/utils/internal/MessageUtils.kt`
around lines 24 - 33, Update the KDoc in MessageUtils.kt to remove the outdated
"contains a command" clause: state that messages with attachments pending upload
are set to MessageType.EPHEMERAL, messages flagged as system are set to
MessageType.SYSTEM, and all others are MessageType.REGULAR; reference the
Message class and MessageType enum in the doc so it accurately reflects the
current behavior of the function that updates the message type.
🤖 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
`@stream-chat-android-client/src/main/java/io/getstream/chat/android/client/utils/internal/MessageUtils.kt`:
- Around line 24-33: Update the KDoc in MessageUtils.kt to remove the outdated
"contains a command" clause: state that messages with attachments pending upload
are set to MessageType.EPHEMERAL, messages flagged as system are set to
MessageType.SYSTEM, and all others are MessageType.REGULAR; reference the
Message class and MessageType enum in the doc so it accurately reflects the
current behavior of the function that updates the message type.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e9988a9e-8443-4365-b24a-db0ae28ad782

📥 Commits

Reviewing files that changed from the base of the PR and between 73f14e6 and 1738cd8.

📒 Files selected for processing (2)
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/utils/internal/MessageUtils.kt
  • stream-chat-android-state/src/test/java/io/getstream/chat/android/client/utils/internal/MessageUtilsTest.kt
💤 Files with no reviewable changes (1)
  • stream-chat-android-state/src/test/java/io/getstream/chat/android/client/utils/internal/MessageUtilsTest.kt

@sonarqubecloud
Copy link

Copy link
Contributor

@andremion andremion left a comment

Choose a reason for hiding this comment

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

👏🏻

@VelikovPetar VelikovPetar merged commit 02e4407 into develop Mar 11, 2026
15 checks passed
@VelikovPetar VelikovPetar deleted the bug/AND-1115_fix_wrong_message_type_for_commands branch March 11, 2026 13:41
@stream-public-bot stream-public-bot added the released Included in a release label Mar 13, 2026
@stream-public-bot
Copy link
Contributor

🚀 Available in v6.35.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