Skip to content

Migrate sendEvent request body to the generated SendEventRequest model - #6617

Open
gpunto wants to merge 1 commit into
developfrom
migrate/send-event
Open

Migrate sendEvent request body to the generated SendEventRequest model#6617
gpunto wants to merge 1 commit into
developfrom
migrate/send-event

Conversation

@gpunto

@gpunto gpunto commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Goal

Migrate the sendEvent request body to the generated SendEventRequest / EventRequest network models.

Part of AND-1291

Implementation

  • Add generated SendEventRequest and EventRequest; remove the hand-written SendEventRequest.
  • Add EventRequestAdapter so the event's custom map is flattened to the event object root, matching the v1 wire.
  • Retype ChannelApi.sendEvent() and its MoshiChatApi mapper to the generated models.

Testing

  • New EventRequestAdapterTest locks the wire shape, including the flattened custom fields.
  • Device-probed on the wire: a custom event serializes as {"event":{"type":"custom_probe_event","probe_key":"probe_value","probe_num":42}} (extra data at the event root, echoed back by the server), and a built-in typing.start as {"event":{"type":"typing.start"}}.
  • spotlessApply, apiDump (no public-API change), detekt, and the full client testDebugUnitTest suite pass.

Summary by CodeRabbit

  • Bug Fixes

    • Improved event requests so custom data is serialized correctly alongside the event type.
    • Added support for event payloads with and without additional custom fields.
    • Standardized event request handling across chat API operations.
  • Tests

    • Added coverage verifying event serialization and custom-field handling.

@gpunto gpunto added the pr:internal Internal changes / housekeeping label Aug 5, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

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 Aug 5, 2026

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.96 MB 5.96 MB 0.00 MB 🟢
stream-chat-android-ui-components 11.25 MB 11.24 MB -0.00 MB 🚀
stream-chat-android-compose 12.73 MB 12.73 MB 0.00 MB 🟢

@gpunto
gpunto force-pushed the migrate/send-event branch from 0c1aa06 to 2856304 Compare August 5, 2026 11:15
@gpunto
gpunto marked this pull request as ready for review August 5, 2026 12:29
@gpunto
gpunto requested a review from a team as a code owner August 5, 2026 12:29
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This change replaces map-based event payloads with typed network models. It adds Moshi serialization for EventRequest, updates sendEvent to build typed requests with string custom keys, and updates API imports and tests to match the new request shape.

Changes

Event request typing and serialization

Layer / File(s) Summary
Typed event request model and adapter
stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/EventRequest.kt, stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/SendEventRequest.kt, stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/MoshiChatParser.kt, stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/EventRequestAdapter.kt, stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/EventRequestAdapterTest.kt
Adds internal EventRequest. Updates SendEventRequest to use the typed event field. Registers EventRequestAdapter in Moshi. The adapter serializes type and flattened custom fields. Tests verify serialization with and without custom data.
Send-event request 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/ChannelApi.kt, stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTest.kt
MoshiChatApi.sendEvent now converts extraData keys to String and builds SendEventRequest(EventRequest(...)). ChannelApi and tests switch to the network-layer request types and the updated expected payload shape.

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

Suggested reviewers: velikovpetar, aleksandar-apostolov

Poem

I hopped through JSON late at night,
and packed each event shape just right.
With typed small paws and Moshi glue,
custom fields now travel true.
thump thump — the tests all softly sing,
for tidy bytes in early spring.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the migration of the sendEvent request body to the generated SendEventRequest model.
Description check ✅ Passed The description covers the goal, implementation, testing, wire format, issue, and validation results; omitted UI and checklist items are not critical for this change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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-event

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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTest.kt (1)

2352-2362: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover non-empty extraData mapping.

This test only verifies emptyMap(). Add a case with a non-String key and assert that ChannelApi.sendEvent receives the corresponding string key in EventRequest.custom. This protects the conversion added in MoshiChatApi.sendEvent.

As per coding guidelines, “add or refresh tests for changed behavior.”

Proposed test update
-        val extraData = emptyMap<Any, Any>()
+        val extraData = mapOf<Any, Any>(123 to "value")
...
         val expectedRequest = SendEventRequest(
-            event = EventRequest(type = eventType, custom = emptyMap()),
+            event = EventRequest(type = eventType, custom = mapOf("123" to "value")),
         )
🤖 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/MoshiChatApiTest.kt`
around lines 2352 - 2362, Update the sendEvent test around
MoshiChatApi.sendEvent to use non-empty extraData containing a non-String key,
then assert the verified ChannelApi.sendEvent request contains the corresponding
stringified key in EventRequest.custom. Preserve the existing result assertion
and Mockito verification while covering the new mapping behavior.

Source: Coding guidelines

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

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

Document or remove these suppressions.

The suppressions have no documented reason. Remove entries that are not required. Document any suppression that the Moshi generation or adapter signature requires.

  • stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/EventRequest.kt#L17-L22: remove unused file-level suppression entries or document why the generated model requires them.
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/SendEventRequest.kt#L17-L22: remove unused file-level suppression entries or document why the generated model requires them.
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/EventRequestAdapter.kt#L32-L34: replace the unused parameter name with _ if Moshi does not require the name, or document the suppression.

As per coding guidelines, “avoid suppressions unless documented.”

🤖 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/EventRequest.kt`
around lines 17 - 22, Remove any unused file-level suppressions from
EventRequest.kt and SendEventRequest.kt, and keep only the entries that
Moshi-generated models actually require with an inline note explaining the need;
for EventRequestAdapter.kt, update the adapter method signature to use an
underscore for any truly unused parameter name unless Moshi requires the named
parameter, in which case document the suppression at that symbol. Apply the fix
at
stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/EventRequest.kt#L17-L22,
stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/SendEventRequest.kt#L17-L22,
and
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/EventRequestAdapter.kt#L32-L34,
preserving only documented suppressions.

Source: Coding guidelines

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

Inline comments:
In
`@stream-chat-android-client/src/main/java/io/getstream/chat/android/client/api2/MoshiChatApi.kt`:
- Around line 1674-1681: Update serializeWithExtraData around the
extraData-to-custom mapping to reject reserved custom keys, at minimum the
"type" key, before constructing and sending SendEventRequest. Ensure
custom["type"] cannot override EventRequest(type = eventType), while preserving
all other custom data handling.

---

Nitpick comments:
In
`@stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/EventRequest.kt`:
- Around line 17-22: Remove any unused file-level suppressions from
EventRequest.kt and SendEventRequest.kt, and keep only the entries that
Moshi-generated models actually require with an inline note explaining the need;
for EventRequestAdapter.kt, update the adapter method signature to use an
underscore for any truly unused parameter name unless Moshi requires the named
parameter, in which case document the suppression at that symbol. Apply the fix
at
stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/EventRequest.kt#L17-L22,
stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/SendEventRequest.kt#L17-L22,
and
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/EventRequestAdapter.kt#L32-L34,
preserving only documented suppressions.

In
`@stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTest.kt`:
- Around line 2352-2362: Update the sendEvent test around MoshiChatApi.sendEvent
to use non-empty extraData containing a non-String key, then assert the verified
ChannelApi.sendEvent request contains the corresponding stringified key in
EventRequest.custom. Preserve the existing result assertion and Mockito
verification while covering the new mapping behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e87ef984-4ef9-4e68-88e6-5f26e9f41a1b

📥 Commits

Reviewing files that changed from the base of the PR and between 328cda3 and 2856304.

📒 Files selected for processing (8)
  • 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/ChannelApi.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/MoshiChatParser.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/parser2/adapters/EventRequestAdapter.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/EventRequest.kt
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/network/models/SendEventRequest.kt
  • stream-chat-android-client/src/test/java/io/getstream/chat/android/client/api2/MoshiChatApiTest.kt
  • stream-chat-android-client/src/test/java/io/getstream/chat/android/client/parser2/EventRequestAdapterTest.kt

@gpunto
gpunto force-pushed the migrate/send-event branch from 2856304 to cc407b0 Compare August 6, 2026 09:40
@sonarqubecloud

sonarqubecloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

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