Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: client.user will never have properties removed #655

Closed
wmadden opened this issue Mar 29, 2021 · 2 comments · Fixed by #727
Closed

Bug: client.user will never have properties removed #655

wmadden opened this issue Mar 29, 2021 · 2 comments · Fixed by #727
Assignees

Comments

@wmadden
Copy link

wmadden commented Mar 29, 2021

The following line means that if a property is removed from a user on the server side, it will never be removed from the client's copy of the user:

https://github.com/GetStream/stream-chat-js/blob/master/src/client.ts#L1199

    // update the client.state with any changes to users
    if (
      event.user &&
      (event.type === 'user.presence.changed' || event.type === 'user.updated')
    ) {
      if (event.user?.id === this.userID) {
        this.user = this.user && { ...this.user, ...event.user }; // <-- the problem is here
        // Updating only available properties in _user object.
        Object.keys(event.user).forEach(function (key) {
          if (client._user && key in client._user) {
            // @ts-expect-error
            client._user[key] = event.user[key];
          }
        });
      }
      client.state.updateUser(event.user);
      client._updateUserReferences(event.user);
    }

To be clear:

  • If a property is present on this.user
  • and a subsequent update on the backend dispatches a 'user.updated' event with the updated representation of the user in which the property is absent
  • the object spread {...this.user, will cause the deleted property to be retained despite it being removed in the serialized user on the event object

gz#10673

@shodgetts
Copy link

Agent comment from Anders Lund in Zendesk ticket #10673:

Hi there,

Thanks for the details, we'll take a look into this just as soon as we're able

@vishalnarkhede vishalnarkhede self-assigned this Mar 30, 2021
@vishalnarkhede
Copy link
Contributor

Hey @wmadden thanks for bringing this up. We will handle this soon :)

@vishalnarkhede vishalnarkhede linked a pull request Jul 28, 2021 that will close this issue
2 tasks
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 a pull request may close this issue.

3 participants