-
Notifications
You must be signed in to change notification settings - Fork 78
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
CRNS-317: handling deleted properties of user #727
Conversation
Size Change: +1.02 kB (0%) Total Size: 242 kB
|
src/client.ts
Outdated
|
||
// Remove deleted properties from user objects. | ||
for (const key in this.user) { | ||
if (key in event.user || ownUserProperties.includes(key)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we care about the ownUserProperties here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to remove those ownUserProperties ... they are kinda reserved fields!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i see and they are not in the event object, in that case maybe we should extract these fields and put them somewhere as a source of truth, in future, if we add more reserve fields and forgot to add them here it will cause hard to find issues
117b0d4
to
62e289a
Compare
src/utils.ts
Outdated
ChannelType, | ||
CommandType, | ||
UserType | ||
>() as string[]).includes(property); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is ts forcing you to cast here?
f80062c
to
95a5f3b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requested one change and had a question.
also, this is taking care of the problem where the event doesnt return deleted properties, right? asking cause remember hearing you guys talking about a similar problem the other day
src/client.ts
Outdated
} | ||
|
||
if (this.user?.[key]) { | ||
delete this.user[key]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey maybe create a shallow copy of user and delete properties on it instead of deleting this.user[key] directly? this way we can only set this.user in the end of the function so we will only mutate it once instead of manually deleting the keys during the function execution.
this is useful to avoid half-updated states in case this function fails in the middle of its execution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense :)
src/client.ts
Outdated
delete this.user[key]; | ||
} | ||
|
||
if (this._user?.[key]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats the difference between user and _user here? just a question, not really a review feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…am/stream-chat-js into vishal/user-deleted-property-fix
CLA
Description of the changes, What, Why and How?
When user gets updated on backend, the event handler for event
user.updated
doesn't take care of properties which were removed. Purpose of this PR is to remove such deleted properties fromclient.user
andclient._user
object.