Skip to content

Conversation

@VelikovPetar
Copy link
Contributor

🎯 Goal

This PR includes several changes related to the DeleteDevice operation:

  • Decouples the automatic deleteDevice invocation from the flushPersistence flag. It introduces a new deleteDevice: Boolean flag on the disconnect() method to control whether the deleteDevice call will be performed in the disconnect operation. For backwards compatibility, this flags defaults to the flushPersistence value.
  • Remove the automatic invocation of deleteDevice when the web socket terminates with an UnrecoverableError. This aligns it to the iOS SDK, and prevents unwanted invocations to deleteDevice. Now, the only place where deleteDevice is called, is as part of disconnect or switchUser.
  • Rework the PushTokenUpdateHandler: It no longer relies on SharedPreference storage, but rather on the current User.devices. It no longer has debouncing logic too, because the only place from where it can be invoked is disconnect/switchUser.

🛠 Implementation details

  • Add deleteDevice to the disconnect method in addition to flushPersistence controlling the automatic invocation of the deleteDevice endpoint
  • Remove the automatic invocation of deleteDevice when the web socket terminates with an UnrecoverableError
  • Rework the PushTokenUpdateHandler: It no longer relies on SharedPreference storage, but rather on the current User.devices

🎨 UI Changes

NA

🧪 Testing

Test different scenarios related to registering/unregistering push devices, for example: Login with one user, receive push notifications. Then logout, login with different user and ensure that notifications are still received for the correct user. Play around with the disconnect - deleteDevice flag and ensure the SDK properly handles the push processes.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 22, 2025

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 3.23 MB 3.23 MB 0.00 MB 🟢
stream-chat-android-offline 3.45 MB 3.45 MB 0.00 MB 🟢
stream-chat-android-ui-components 10.54 MB 10.54 MB -0.00 MB 🚀
stream-chat-android-compose 12.77 MB 12.76 MB -0.00 MB 🚀

@VelikovPetar VelikovPetar requested a review from Copilot October 22, 2025 16:14
@VelikovPetar VelikovPetar marked this pull request as ready for review October 22, 2025 16:15
@VelikovPetar VelikovPetar requested a review from a team as a code owner October 22, 2025 16:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the DeleteDevice operation by decoupling device deletion from persistence flushing, removing automatic deletion on unrecoverable errors, and simplifying the push token update handler to rely on user device state instead of SharedPreferences.

Key changes:

  • Added a deleteDevice parameter to the disconnect() method to explicitly control device deletion behavior, defaulting to flushPersistence for backwards compatibility
  • Removed automatic deleteDevice invocation when WebSocket encounters an UnrecoverableError, aligning with iOS SDK behavior
  • Refactored PushTokenUpdateHandler to use User.devices instead of SharedPreferences and removed debouncing logic

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
PushTokenUpdateHandler.kt Simplified to track device state in-memory and check registration against user devices
PushTokenUpdateHandlerTest.kt Added comprehensive unit tests for add/delete device operations
ChatNotifications.kt Updated to pass user context and removed persistence-based device cleanup
ChatClient.kt Added deleteDevice parameter to disconnect method and explicit deletion on user switch
stream-chat-android-client.api Updated public API surface with new disconnect overload

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…roid/client/notifications/PushTokenUpdateHandlerTest.kt

Co-authored-by: Copilot <[email protected]>
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant