Skip to content

fix: sync relationship changes for users not in the local cache - #189

Merged
Dadadah merged 1 commit into
stoatchat:mainfrom
aashish00021:fix/relationship-sync-unknown-user
Aug 28, 2026
Merged

fix: sync relationship changes for users not in the local cache#189
Dadadah merged 1 commit into
stoatchat:mainfrom
aashish00021:fix/relationship-sync-unknown-user

Conversation

@aashish00021

@aashish00021 aashish00021 commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

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.

UserRelationship events are re-dispatched internally as UserUpdate events. The UserUpdate handler only applies changes to a user that's already in the local collection it looks the user up with getOrPartial, which returns undefined for an unknown id when partials is 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 Ready resync (e.g. a page reload), which hydrates users unconditionally via getOrCreate.

Fix: ensure the user exists in the collection via getOrCreate before delegating to UserUpdate, using the data already included in the UserRelationship event payload the same data Ready already 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-web vendors this package as a submodule and will need its stoat.js reference updated after this lands.

How was this PR tested?

  • prettier and eslint pass on the changed file
  • tsc --noEmit passes
  • Couldn't exercise this end-to-end against a live server/second
    client no way to trigger a real UserRelationship event
    without two authenticated sessions and an unknown-to-each-other
    user pair. Traced the fix against the Ready handler's
    equivalent getOrCreate path as the reference behavior.

Checklist:

  • I have carefully read the contributing guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation if applicable
  • I have no unrelated changes in the PR
  • I have confirmed that any new dependencies are strictly necessary
  • I have written tests for new code (if applicable)
  • I have followed naming conventions/patterns in the surrounding code

Please declare, if any, LLM usage involved in creating this PR

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>
@aashish00021
aashish00021 marked this pull request as ready for review August 27, 2026 09:10
@Dadadah
Dadadah merged commit 119107b into stoatchat:main Aug 28, 2026
4 checks passed
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.

2 participants