Skip to content

Migrate sendReaction request body to generated ReactionRequest and SendReactionRequest models#6566

Open
gpunto wants to merge 2 commits into
developfrom
migrate/send-reaction
Open

Migrate sendReaction request body to generated ReactionRequest and SendReactionRequest models#6566
gpunto wants to merge 2 commits into
developfrom
migrate/send-reaction

Conversation

@gpunto

@gpunto gpunto commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Goal

Migrate the sendReaction request body (POST /messages/{id}/reaction) to the generated SendReactionRequest + ReactionRequest network models. First patch-free generated model that carries a flattened custom field. Part of the incremental OpenAPI model migration.

Part of AND-1291

Implementation

  • Add generated internal SendReactionRequest (the {reaction, enforce_unique, skip_push} wrapper) and ReactionRequest (the reaction object) in network.models. Remove the hand-written api2.model.requests.ReactionRequest wrapper and the hand-written UpstreamReactionDto. Real names, no alias.
  • Enhance CustomObjectDtoAdapter (backward-compatibly) with an extraDataPropertyName parameter (defaults to extraData) and @Json-aware member-name resolution, so generated DTOs that hold the overflow map as custom flatten correctly. Existing hand-written adapters are unchanged. UpstreamReactionDtoAdapter now targets the generated ReactionRequest with extraDataPropertyName = "custom".
  • Reaction.toDto() now emits the lean backend shape: it drops message_id (comes from the URL path), user/user_id (set server-side), and folds emoji_code into custom. Verified against the /chat SendReactionRequest/ReactionRequest Go structs.

Testing

  • spotlessApply, apiCheck (no API drift), detekt, lint, and the full client testDebugUnitTest suite pass.
  • Verified on device: POST /messages/{id}/reaction sends {"reaction":{"type":"like","score":1,"migrate_probe":"v1","emoji_code":"👍"},"enforce_unique":false,"skip_push":false} (lean object, no message_id/user/user_id; custom flattened to root), returns 201, and the custom field + emoji_code round-trip on the returned reaction.

Summary by CodeRabbit

  • Bug Fixes
    • Improved message reaction requests to use the correct API payload format.
    • Preserved reaction details, including emoji codes and custom data, during serialization.
    • Added more flexible handling for custom JSON data and nullable values.
  • Tests
    • Updated reaction mapping and serialization tests to reflect the corrected payload structure.

@gpunto gpunto added the pr:internal Internal changes / housekeeping label Jul 10, 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 Jul 10, 2026

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.94 MB 5.94 MB 0.00 MB 🟢
stream-chat-android-ui-components 11.21 MB 11.20 MB -0.01 MB 🚀
stream-chat-android-compose 12.68 MB 12.68 MB 0.00 MB 🟢

@gpunto gpunto force-pushed the migrate/send-reaction branch from e688018 to de6a5a7 Compare July 10, 2026 11:43
@gpunto gpunto force-pushed the migrate/send-reaction branch from de6a5a7 to 21d230e Compare July 10, 2026 11:44
@gpunto gpunto marked this pull request as ready for review July 10, 2026 14:19
@gpunto gpunto requested a review from a team as a code owner July 10, 2026 14:19
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
71.9% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Reaction sending now uses dedicated network request models. Reaction mapping and Moshi adapters support custom overflow data, while the API endpoint and client construct the new nested request shape. Related mapping and parser fixtures were updated.

Changes

Reaction request migration

Layer / File(s) Summary
Request models and reaction mapping
stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/*, stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/DtoMapping.kt, stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/ReactionDtos.kt, stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/ReactionRequest.kt, stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/DtoMappingTest.kt
Adds ReactionRequest and SendReactionRequest, removes the obsolete upstream reaction DTO, maps emoji data into custom, and updates mapping assertions.
Custom-data adapter migration
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/*, stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/ReactionDtoTestData.kt
Makes overflow data configurable, uses custom for reaction serialization, adds null-safe merging, and updates parser fixtures.
Reaction endpoint wiring
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/MoshiChatApi.kt, stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/MessageApi.kt
Updates reaction submission to use SendReactionRequest while preserving endpoint inputs and response mapping.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: pr:improvement

Suggested reviewers: andremion

Poem

A rabbit packed reactions tight,
With custom fields tucked out of sight.
New requests hop through the API,
Emoji data joins the ride.
Moshi smiles: the payload’s right!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 accurately summarizes the main change: migrating sendReaction to generated request models.
Description check ✅ Passed The description covers Goal, Implementation, and Testing; the missing UI/checklist sections are non-critical for this backend migration.
✨ 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 migrate/send-reaction

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 (3)
stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ReactionRequest.kt (1)

17-22: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Document the @file:Suppress annotation or remove unnecessary suppressions.

Per coding guidelines, suppressions should be avoided unless documented. The @file:Suppress here includes "ArrayInDataClass" and "EnumEntryName" which are not applicable to this file (no arrays, no enums). Consider adding a brief comment noting these are code-generation artifacts, or removing the inapplicable entries.

🤖 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/main/java/io/getstream/chat/android/network/models/ReactionRequest.kt`
around lines 17 - 22, Update the file-level `@file`:Suppress annotation in
ReactionRequest.kt by removing the inapplicable "ArrayInDataClass" and
"EnumEntryName" entries, or document them with a brief comment if they are
required code-generation artifacts; retain only necessary suppressions.

Source: Coding guidelines

stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/SendReactionRequest.kt (1)

17-22: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Document or remove unnecessary @file:Suppress annotations.

Per the project's coding guidelines, suppressions should be avoided unless documented. The suppressions "ArrayInDataClass" and "EnumEntryName" are not applicable to this file (no arrays or enums present), and none of the suppressions have accompanying documentation explaining why they are needed.

If this is generated from a template, consider adding a comment noting the code-generation origin, or remove the inapplicable suppressions for this file.

🤖 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/main/java/io/getstream/chat/android/network/models/SendReactionRequest.kt`
around lines 17 - 22, Remove the unnecessary `@file`:Suppress entries from
SendReactionRequest, particularly "ArrayInDataClass" and "EnumEntryName"; retain
only suppressions required by compiler warnings and document any retained
generated-code suppressions with an explanatory comment.

Source: Coding guidelines

stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/DtoMappingTest.kt (1)

241-256: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider explicit test coverage for both emojiCode branches.

The test relies on randomReaction() to determine whether emojiCode is null or non-null, so only one branch of the custom logic is exercised per run. Adding explicit test cases for both scenarios would improve coverage confidence.

🧪 Suggested additional test cases
`@Test`
fun `Reaction with null emojiCode maps custom to extraData only`() {
    val reaction = randomReaction().copy(emojiCode = null)
    val mapping = Fixture().get()
    val dto = with(mapping) { reaction.toDto() }
    val expected = ReactionRequest(
        type = reaction.type,
        createdAt = reaction.createdAt,
        score = reaction.score,
        updatedAt = reaction.updatedAt,
        custom = reaction.extraData,
    )
    dto shouldBeEqualTo expected
}

`@Test`
fun `Reaction with non-null emojiCode maps custom to extraData plus emoji_code`() {
    val reaction = randomReaction().copy(emojiCode = "smile")
    val mapping = Fixture().get()
    val dto = with(mapping) { reaction.toDto() }
    val expected = ReactionRequest(
        type = reaction.type,
        createdAt = reaction.createdAt,
        score = reaction.score,
        updatedAt = reaction.updatedAt,
        custom = reaction.extraData + ("emoji_code" to "smile"),
    )
    dto shouldBeEqualTo expected
}
🤖 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/mapping/DtoMappingTest.kt`
around lines 241 - 256, Expand the Reaction mapping tests to explicitly cover
both emojiCode branches instead of relying on randomReaction(). In the Reaction
is correctly mapped to Dto test or separate tests, create reactions with
emojiCode set to null and to a non-null value, then assert custom equals
extraData in the null case and extraData plus the emoji_code entry in the
non-null case.
🤖 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/main/java/io/getstream/chat/android/network/models/ReactionRequest.kt`:
- Around line 17-22: Update the file-level `@file`:Suppress annotation in
ReactionRequest.kt by removing the inapplicable "ArrayInDataClass" and
"EnumEntryName" entries, or document them with a brief comment if they are
required code-generation artifacts; retain only necessary suppressions.

In
`@stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/SendReactionRequest.kt`:
- Around line 17-22: Remove the unnecessary `@file`:Suppress entries from
SendReactionRequest, particularly "ArrayInDataClass" and "EnumEntryName"; retain
only suppressions required by compiler warnings and document any retained
generated-code suppressions with an explanatory comment.

In
`@stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/DtoMappingTest.kt`:
- Around line 241-256: Expand the Reaction mapping tests to explicitly cover
both emojiCode branches instead of relying on randomReaction(). In the Reaction
is correctly mapped to Dto test or separate tests, create reactions with
emojiCode set to null and to a non-null value, then assert custom equals
extraData in the null case and extraData plus the emoji_code entry in the
non-null case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3ad4d2b6-a697-485c-8912-6936d2df5d1d

📥 Commits

Reviewing files that changed from the base of the PR and between c962b26 and a03074d.

📒 Files selected for processing (11)
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/MoshiChatApi.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/endpoint/MessageApi.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/mapping/DtoMapping.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/ReactionDtos.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/ReactionRequest.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/CustomObjectDtoAdapter.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/ReactionDtoAdapters.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/ReactionRequest.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/SendReactionRequest.kt
  • stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/mapping/DtoMappingTest.kt
  • stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/testdata/ReactionDtoTestData.kt
💤 Files with no reviewable changes (2)
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/dto/ReactionDtos.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/model/requests/ReactionRequest.kt

@gpunto gpunto enabled auto-merge (squash) July 10, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:internal Internal changes / housekeeping

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant