[v4] Fix CurrentUserController.setPushPreference not updating local state#4086
[v4] Fix CurrentUserController.setPushPreference not updating local state#4086
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Public Interface🚀 No changes affecting the public interface. |
SDK Size
|
SDK Performance
|
StreamChat XCSize
|
|



🔗 Issue Links
IOS-1570
🎯 Goal
CurrentUserController.setPushPreference(level:)succeeded against the API but the localcurrentUser.pushPreferencenever reflected the change, so UIs bound to it stayed stale until the app reconnected and re-fetched the current user. This PR makes the local round-trip work the way callers expect.📝 Summary
PushPreferenceDTOunder the actual current user id and wireCurrentUserDTO.pushPreference = savedDTO.selfinCurrentUserController.setPushPreferenceandsnoozePushNotificationscallbacks, matching the rest of the controller.CurrentUserUpdater_Tests(saved-id assertion +currentUser.pushPreferencewired up + regression check that no DTO is saved under the literal"currentUserId").🛠 Implementation
CurrentUserUpdater.setPushPreferencewas previously writing the DTO under the literal id"currentUserId". The remote-fetch path (CurrentUserDTO.saveCurrentUser) saves the same kind of DTO under the real user id and sets the inverse relationship toCurrentUserDTO. The local-save therefore created an orphanPushPreferenceDTOthat was never linked to the current user, which is why the model never refreshed.The fix reads
session.currentUserinside the existingdatabase.writeblock, saves withcurrentUserDTO.user.id, and explicitly setscurrentUserDTO.pushPreference = savedDTO. Core Data's inverse handling setspushPreferenceDTO.currentUser = currentUserDTOautomatically. If there is no current user in the DB the save is logged and skipped — the API success still propagates to the completion to preserve the existing public contract.The two
CurrentUserControllercallsites forcurrentUserUpdater.setPushPreference(_:)were the only methods on that controller that capturedselfweakly while routing throughself.callback { … }. They are now consistent withupdateUserData,addDevice,removeDevice, etc.🎨 Showcase
N/A — no UI surface in this SDK PR.
🧪 Manual Testing Notes
In the demo app or an integration test:
chatClient.currentUserController().setPushPreference(level: .none); assert success.chatClient.currentUserController().currentUser?.pushPreference?.level— should be.none..all; the observed value should flip to.allwithout restarting the client.Before this PR, step 3/4 reflected the value only after a fresh fetch of the current user; after this PR, it updates immediately.
☑️ Contributor Checklist
docs-contentrepo