Skip to content

[v4] Fix CurrentUserController.setPushPreference not updating local state#4086

Merged
laevandus merged 2 commits intov4from
fix/user-push-preferences
May 6, 2026
Merged

[v4] Fix CurrentUserController.setPushPreference not updating local state#4086
laevandus merged 2 commits intov4from
fix/user-push-preferences

Conversation

@laevandus
Copy link
Copy Markdown
Contributor

🔗 Issue Links

IOS-1570

🎯 Goal

CurrentUserController.setPushPreference(level:) succeeded against the API but the local currentUser.pushPreference never 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

  • Save the PushPreferenceDTO under the actual current user id and wire CurrentUserDTO.pushPreference = savedDTO.
  • Strongly capture self in CurrentUserController.setPushPreference and snoozePushNotifications callbacks, matching the rest of the controller.
  • Cover the round-trip in CurrentUserUpdater_Tests (saved-id assertion + currentUser.pushPreference wired up + regression check that no DTO is saved under the literal "currentUserId").

🛠 Implementation

CurrentUserUpdater.setPushPreference was 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 to CurrentUserDTO. The local-save therefore created an orphan PushPreferenceDTO that was never linked to the current user, which is why the model never refreshed.

The fix reads session.currentUser inside the existing database.write block, saves with currentUserDTO.user.id, and explicitly sets currentUserDTO.pushPreference = savedDTO. Core Data's inverse handling sets pushPreferenceDTO.currentUser = currentUserDTO automatically. 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 CurrentUserController callsites for currentUserUpdater.setPushPreference(_:) were the only methods on that controller that captured self weakly while routing through self.callback { … }. They are now consistent with updateUserData, addDevice, removeDevice, etc.

🎨 Showcase

N/A — no UI surface in this SDK PR.

🧪 Manual Testing Notes

In the demo app or an integration test:

  1. Sign in.
  2. Call chatClient.currentUserController().setPushPreference(level: .none); assert success.
  3. Read chatClient.currentUserController().currentUser?.pushPreference?.level — should be .none.
  4. Call again with .all; the observed value should flip to .all without 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

  • I have signed the Stream CLA (required)
  • This change should be manually QAed
  • Changelog is updated with client-facing changes
  • Changelog is updated with new localization keys
  • New code is covered by unit tests
  • Documentation has been updated in the docs-content repo

@laevandus laevandus requested a review from a team as a code owner May 5, 2026 23:27
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b0acc1d1-3902-40ed-9eb9-d53c2092aeee

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/user-push-preferences

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 and usage tips.

@laevandus laevandus changed the title Fix CurrentUserController.setPushPreference not updating local state [v4] Fix CurrentUserController.setPushPreference not updating local state May 5, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Public Interface

🚀 No changes affecting the public interface.

@Stream-SDK-Bot
Copy link
Copy Markdown
Collaborator

SDK Size

title v4 branch diff status
StreamChat 8.6 MB 8.6 MB 0 KB 🟢
StreamChatUI 4.94 MB 4.94 MB 0 KB 🟢

@Stream-SDK-Bot
Copy link
Copy Markdown
Collaborator

SDK Performance

target metric benchmark branch performance status
MessageList Hitches total duration 10 ms 13.35 ms -33.5% 🔽 🔴
Duration 2.6 s 2.54 s 2.31% 🔼 🟢
Hitch time ratio 4 ms per s 5.25 ms per s -31.25% 🔽 🔴
Frame rate 75 fps 77.75 fps 3.67% 🔼 🟢
Number of hitches 1 1.2 -20.0% 🔽 🔴

@Stream-SDK-Bot
Copy link
Copy Markdown
Collaborator

StreamChat XCSize

Object Diff (bytes)
CurrentUserUpdater.o +1558
CurrentUserController.o -312

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

@laevandus laevandus merged commit 8d4d73c into v4 May 6, 2026
15 checks passed
@laevandus laevandus deleted the fix/user-push-preferences branch May 6, 2026 07:35
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.

3 participants