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

CRNS-317: handling deleted properties of user #727

Merged
merged 9 commits into from
Jul 28, 2021

Conversation

vishalnarkhede
Copy link
Contributor

@vishalnarkhede vishalnarkhede commented Jul 28, 2021

CLA

  • I have signed the Stream CLA (required).
  • Code changes are tested

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 from client.user and client._user object.

@vishalnarkhede vishalnarkhede linked an issue Jul 28, 2021 that may be closed by this pull request
@github-actions
Copy link
Contributor

github-actions bot commented Jul 28, 2021

Size Change: +1.02 kB (0%)

Total Size: 242 kB

Filename Size Change
dist/browser.es.js 52.9 kB +263 B (0%)
dist/browser.full-bundle.min.js 29.5 kB +53 B (0%)
dist/browser.js 53.5 kB +222 B (0%)
dist/index.es.js 53 kB +263 B (0%)
dist/index.js 53.5 kB +224 B (0%)

compressed-size-action

src/client.ts Outdated

// Remove deleted properties from user objects.
for (const key in this.user) {
if (key in event.user || ownUserProperties.includes(key)) {
Copy link
Contributor

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?

Copy link
Contributor Author

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!!

Copy link
Contributor

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

@vishalnarkhede vishalnarkhede force-pushed the vishal/user-deleted-property-fix branch from 117b0d4 to 62e289a Compare July 28, 2021 13:17
src/utils.ts Outdated Show resolved Hide resolved
src/utils.ts Outdated Show resolved Hide resolved
src/utils.ts Outdated
ChannelType,
CommandType,
UserType
>() as string[]).includes(property);
Copy link
Contributor

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?

@vishalnarkhede vishalnarkhede force-pushed the vishal/user-deleted-property-fix branch from f80062c to 95a5f3b Compare July 28, 2021 13:51
mahboubii
mahboubii previously approved these changes Jul 28, 2021
Copy link
Contributor

@tsirlucas tsirlucas left a 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];
Copy link
Contributor

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.

Copy link
Contributor Author

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]) {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2021-07-28 at 18 14 34

This comment might answer this one!!

@vishalnarkhede vishalnarkhede merged commit 031e096 into master Jul 28, 2021
@vishalnarkhede vishalnarkhede deleted the vishal/user-deleted-property-fix branch July 28, 2021 16:48
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.

Bug: client.user will never have properties removed
3 participants