Fix unable to edit thread replies#6410
Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
SDK Size Comparison 📏
|
WalkthroughThe PR enhances message serialization by introducing type coercion logic. When ChangesMessage Type Coercion
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTestArguments.kt (1)
116-123: ⚡ Quick winExpand
uploadMessageTypeInput()with explicitFAILEDand"deleted"cases.The new table is good, but adding the remaining known non-uploadable/server-assigned types will harden this regression suite.
Proposed test-arguments extension
fun uploadMessageTypeInput() = listOf( Arguments.of(MessageType.REGULAR, MessageType.REGULAR), Arguments.of(MessageType.SYSTEM, MessageType.SYSTEM), Arguments.of(MessageType.REPLY, ""), Arguments.of(MessageType.ERROR, ""), Arguments.of(MessageType.EPHEMERAL, ""), + Arguments.of(MessageType.FAILED, ""), + Arguments.of("deleted", ""), )🤖 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-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTestArguments.kt` around lines 116 - 123, The uploadMessageTypeInput() test data is missing known non-uploadable/server-assigned types; update the function (MoshiChatApiTestArguments.uploadMessageTypeInput) to include explicit cases for MessageType.FAILED and the string "deleted" in the returned list so the table covers those regression cases (i.e., add Arguments.of(MessageType.FAILED, "") and Arguments.of("deleted", "") alongside the existing entries).
🤖 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-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTestArguments.kt`:
- Around line 116-123: The uploadMessageTypeInput() test data is missing known
non-uploadable/server-assigned types; update the function
(MoshiChatApiTestArguments.uploadMessageTypeInput) to include explicit cases for
MessageType.FAILED and the string "deleted" in the returned list so the table
covers those regression cases (i.e., add Arguments.of(MessageType.FAILED, "")
and Arguments.of("deleted", "") alongside the existing entries).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9b461a57-0b87-49b2-babf-e211a70104c9
📒 Files selected for processing (5)
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/MoshiChatApi.ktstream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/DtoMapping.ktstream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTest.ktstream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTestArguments.ktstream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/DtoMappingTest.kt
|
|
🚀 Available in v7.1.0 |



Goal
Editing a thread reply message currently fails with
400 Bad Requestfrom the backend.The backend's
UpdateMessageendpoint validatesmessage.typeagainstoneof='' regular system. When a thread reply is sent, the server overwrites itstypeto"reply"(server-assigned). Clients then echo the full message back on edit, which includestype: "reply"— rejected by the validator before the handler runs.The same issue affects any message whose stored
typeis notregularorsystem(reply,error,ephemeral,deleted, etc.).Implementation
The fix lives at the network adapter layer (
MoshiChatApi), which is the wire-format boundary — already responsible for similar wire-only quirks (e.g. liftingskip_push/skip_enrich_urloff the domainMessage). Local state is never touched.DtoMapping.Message.toDto()now accepts an optionalmessageType: String? = nullparameter. Whennull(default), it falls back to the message's own type — the mapper stays a pure 1:1 conversion.MoshiChatApiintroduces a privateMessage.uploadMessageTypeextension property that returnstypeonly when it isMessageType.REGULARorMessageType.SYSTEM, and""otherwise. The empty string is accepted by the backend validator (omitempty,oneof='' regular system) and ignored on update anyway, so this is functionally lossless.sendMessageandupdateMessagepassmessage.uploadMessageTypetotoDto(). No copy of the domainMessageis made, no plugin/transformer is involved.UI Changes
edit-reply-before.mp4
edit-reply-after.mp4
Testing
Manual verification: editing a thread reply now succeeds end-to-end against the backend.
Summary by CodeRabbit
Bug Fixes
Tests