Skip to content

IdentityManager.configure: warn on empty App User ID and convert it to anonymous#384

Merged
NachoSoto merged 3 commits into
mainfrom
empty-user-id
Nov 29, 2021
Merged

IdentityManager.configure: warn on empty App User ID and convert it to anonymous#384
NachoSoto merged 3 commits into
mainfrom
empty-user-id

Conversation

@NachoSoto

Copy link
Copy Markdown
Contributor

Fixes [sc-10159].
See also RevenueCat/purchases-ios#995 for iOS equivalent.

@NachoSoto NachoSoto requested review from a team and vegaro November 29, 2021 21:40
@NachoSoto

Copy link
Copy Markdown
Contributor Author

Kotlin and Android are obviously not my areas of expertise, so please don't be easy on me :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I imagine there's nothing weird with Kotlin here and this only evaluates to true if the result is not null and true.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the right way of doing it :)

@shortcut-integration

Copy link
Copy Markdown

@taquitos taquitos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎈🐐 LGTM but I don't have enough experience to approve.

return if (this.isBlank()) {
null
} else {
this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WHAT IS THIS? JAVASCRIPT? 🙃

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be written as:

this.ifBlank { null }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh nice 😍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is the right way of doing it :)

return if (this.isBlank()) {
null
} else {
this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be written as:

this.ifBlank { null }

}

val appUserIDToUse = appUserID
?.notEmpty

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of doing the extension, this can be written as "appUserID?.takeUnless { it.isBlank() }", which it feels more Kotlin to me.

I had to see what notEmpty was doing to understand what it meant. empty in Kotlin is typically used for "". Something is blank when it's either the empty string or if it consist solely of whitespace character. And notEmpty is actually checking if it's not blank.

Maybe calling the function nullIfBlank(). Also if you look into the standard library extension functions for string, they are normally extension functions and not extension properties.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's exactly the type of feedback I was looking for, thanks! I'll use appUserID?.takeUnless { it.isBlank() }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I really like this. Seems like Kotlin's STL is wider than Swift's.

@NachoSoto NachoSoto requested a review from vegaro November 29, 2021 22:48
@NachoSoto NachoSoto merged commit 1d4308b into main Nov 29, 2021
@NachoSoto NachoSoto deleted the empty-user-id branch November 29, 2021 23:12
@aboedo aboedo mentioned this pull request Dec 1, 2021
tonidero added a commit that referenced this pull request Jan 25, 2023
### Description
Attempt at dealing with
[CSDK-531](https://revenuecats.atlassian.net/browse/CSDK-531)

Back in #384, we
added checks to make sure we don't allow blank user ids. However, before
that was added, user ids could be empty and could have subscriber
attributes. Those could remain in SharedPreferences unless users
uninstall which could cause some issues when syncing user attributes.

This is an attempt of solving that issue by just ignoring those old user
ids when syncing subscriber attributes.


[CSDK-531]:
https://revenuecats.atlassian.net/browse/CSDK-531?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
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.

3 participants