chat-sdk / chat-sdk-android

Chat SDK Android - Open Source Mobile Messenger

Home Page:https://chatsdk.co

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

User Meta Values are reset on login with no cached user

ChatWave opened this issue · comments

  1. Is the bug present in the demo Chat SDK project? Yes it is. The ChatSDK on google play does the exact same thing.

  2. What modifications have you made to the Chat SDK? Tons of modifications, but there is nothing that effects the meta values. This still happens on a fresh zip from github.

  3. Android Version: 7.1.1 - I will see if others do it to, but i doubt it.

  4. Steps taken to reproduce the problem:

Edit your profile status or anything and save it.
You can see the data pushed to firebase.
Exit the app and clear the data + cache
Log back into your account

  1. Expected result:

All users meta should be the same as read from the db in firebase

  1. Actual result:

It seems to completely reset everything in user that's not tied to FirebaseUser

  1. Comments:

I found exactly when it happens.

In
public Completable authenticateWithUser(final FirebaseUser user)
In the class FirebaseAuthenticationHandler

When the cached user is null it does this

UserWrapper userWrapper = UserWrapper.initWithAuthData(user);
return userWrapper.push().doOnComplete(() -> {
completeAuthentication(userWrapper.getModel());
});

and it pushes the user with model = ChatSDK.db().fetchOrCreateEntityWithEntityID(User.class, authData.getUid());
which seems to just return a new user? it does find the entity id though because it doesn't create a new one

Im stumped atm... I should figure it out eventually, but I thought i'd post this here

So it's just a universal loading issue with GreenDao
All the others are having loading issues with threads and users also don't load at first
I was able to prevent the meta data from getting reset, but it still doesn't load.
When you're logged in as another user you can still get others data, but not see your own until you log into another account and go into your profile, then log back into the original
Guess it's just how it loads
I will be experimenting and ill leave anything i find

Alright so if a user has replied to a public thread and you join it, it starts to load their data.
I am not having loading issues with threads so something is wrong with user loading on it's own.
Breaking it down lol sorry for the spam I need logs

Fixed it
I can't tell what exactly fixed it but..

calling model.refresh();

in private UserWrapper(FirebaseUser authData){
after the model is initialized grabs the fresh data from the database

I'm also looking into daoSession.clear(); but i think it's a little extreme
idk why refresh works or how the caching works but it does 👍

Just remember

By default GreenDAO caches and returns cached entity instances to improve performance. To prevent this behaviour, you need to call:

daoSession.clear()

to update an entity with fresh data from the database

objectDao.refresh()

Learn about greendao if you're having issues like this

Hi I need little guidance, I am pushing some custom meta values at sign-up in user tag, but when i try to login again after clearing cache, my custom meta values are removed from the firebase then i have to push those values again. Is there any proper solution for this?