-
Notifications
You must be signed in to change notification settings - Fork 4
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
Set default values on ProUser data class #1116
Conversation
@jigar-f I think we could put out a new release right away with this fix and then another release tomorrow with your change.. if that's okay with you? |
@atavism Could you please just give me an hour, this issue is with purchase, let me look into it now. |
Oh, sure. Thanks for taking a look! |
@atavism I think you know better on this, So the issue is this events never gets a callback, It only gets callbacks when user install the app for the first time After that is never callback, Due to that issue currency list never gets updated. So while purchasing it always sends USD, and this is an issue. |
Do you mind taking a look at it, Since you work on these event flows, I tried to see what's going on, not able to find issue. |
Thanks for the information. I am just about done testing the changes here so I can look into this next |
It turns out there was another issue: the GSON library that we are using "turns missing fields into null values": https://medium.com/@clay07g/gson-will-assign-missing-values-as-null-3f02f19f2145 "Obviously, this doesn’t use Kotlin’s default values. As far as I know, there isn’t a way to access them via reflection. Unfortunately, either way, the solution is very clunky." I updated this PR to use kotlinx.serialization, and I confirmed the default values are being properly set now on ProUser: 07-03 12:06:04.045 14641 14882 D org.getlantern.lantern.model.LanternSessionManager:
Storing user data ProUser(userId=372784204, token=kI3.., referral=8YXPUN, email=, userStatus=,
code=8YXPUN, locale=en_US, subscription=, expiration=0, devices=[], userLevel=) |
@jigar-f Ok, the changes to use
Do you wanna take it for a spin and see how it works for you? |
@atavism Taking a look now |
android/app/src/main/kotlin/org/getlantern/lantern/model/LanternSessionManager.kt
Show resolved
Hide resolved
cb.onSuccess(response!!, user) | ||
} catch (e: SerializationException) { | ||
// If for some reason we get error return user with basic string | ||
Logger.error(TAG, "Unable to parse user from JSON", e) |
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.
So I found that is you pass devices as null then you still crash, So I added this, so even if we get an exception we catch it and then return some basic details, So at least the app does not crash.
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.
To test this, I set devices to null in the user data JSON response, and another exception is thrown in the catch block (it looks like the email is missing):
07-04 07:21:42.640 1501 1790 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.gson.JsonElement.getAsString()' on a null object reference
07-04 07:21:42.640 1501 1790 E AndroidRuntime: at org.getlantern.lantern.model.LanternHttpClient$userData$1.onSuccess(LanternHttpClient.kt:104)
07-04 07:21:42.640 1501 1790 E AndroidRuntime: at org.getlantern.lantern.model.LanternHttpClient$proRequest$1.onResponse(LanternHttpClient.kt:321)
07-04 07:21:42.640 1501 1790 E AndroidRuntime: at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
07-04 07:21:42.640 1501 1790 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
07-04 07:21:42.640 1501 1790 E AndroidRuntime: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
07-04 07:21:42.640 1501 1790 E AndroidRuntime: at java.lang.Thread.run(Thread.java:1012)
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.
@atavism Added a more few changes on top of your changes, Do take look at them and let me know, I am happy to merge this and upload the build. Let me know. |
@atavism Also if all changes look good, You can go ahead and merge, if needed you can upload the build as well, |
Thanks, @jigar-f! Yep, the changes here LGTM. I will put out a 7.8.9 release today |
* Add tryParseJson utility method * formatting
The changes from #1114 minus the db-android upgrade.
Resolves https://github.com/getlantern/engineering/issues/1476