fix: sync relationship changes for users not in the local cache - #189
Merged
Dadadah merged 1 commit intoAug 28, 2026
Merged
Conversation
UserRelationship events are re-dispatched as UserUpdate, which only applies changes to users already present in the collection (getOrPartial returns undefined for unknown ids when partials are disabled, the default). As a result, a relationship change (friend request accepted/received, block, unblock, etc.) made on another client is silently dropped on this client if it has never cached that user, until the next full resync. Ensure the user exists in the collection via getOrCreate using the data already included in the event, matching how Ready hydrates users on initial sync. Signed-off-by: aashish00021 <aashishbhardwaj07@icloud.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This was reported and root-caused against
stoatchat/for-web(the web client that consumes this SDK as a submodule), see stoatchat/for-web#1504 for the original bug report and repro ("friends aren't synced up correctly between clients"). The root cause lives here in the SDK's event handling, not in the web client, so the fix belongs in this repo.UserRelationshipevents are re-dispatched internally asUserUpdateevents. TheUserUpdatehandler only applies changes to a user that's already in the local collection it looks the user up withgetOrPartial, which returnsundefinedfor an unknown id whenpartialsis disabled (the default this SDK's clients use).So a relationship change made on another client accepting/receiving a friend request, blocking, unblocking, removing a friend is silently dropped here if this client has never cached that user before. It stays out of sync until the next full
Readyresync (e.g. a page reload), which hydrates users unconditionally viagetOrCreate.Fix: ensure the user exists in the collection via
getOrCreatebefore delegating toUserUpdate, using the data already included in theUserRelationshipevent payload the same dataReadyalready uses to hydrate users on initial sync, so no extra request is introduced.Related to stoatchat/for-web#1504. This won't automatically close that issue, since
for-webvendors this package as a submodule and will need itsstoat.jsreference updated after this lands.How was this PR tested?
prettierandeslintpass on the changed filetsc --noEmitpassesclient no way to trigger a real
UserRelationshipeventwithout two authenticated sessions and an unknown-to-each-other
user pair. Traced the fix against the
Readyhandler'sequivalent
getOrCreatepath as the reference behavior.Checklist:
Please declare, if any, LLM usage involved in creating this PR