User metadata is empty after app reinstall (React Native)

I’m using user metadata to store some state as it was suggested in I need store another state basically same as CometChat.markAsRead (but it's already used).

But when I do
const metadata = chatUser.getMetadata()
after app reinstall, metadata is empty.

Any ideas what is wrong here?
@mayur.bhandari

    "@cometchat-pro/react-native-calls": "2.0.2-beta1",
    "@cometchat-pro/react-native-chat": "2.3.1-beta1",

Hello @dimaportenko,

You are fetching metadata of the logged-in user, right? Can you please share the whole code snippet? Are you facing this issue for all the users or any particular user?

Warm Regards,

CometChat Pro
Mayur Bhandari

yes

Basically, code looks like this

  const [chatUser, setChatUser] = useState<CometChat.User | null | undefined>(null);

  const login = async (uid: string) => {
    const loggedUser = await CometChat.login(uid, CometChatConfig.apiKey);
    setChatUser(loggedUser);
  }

  useEffect(() => {
    const metadata = chatUser?.getMetadata() as
      | {[key in 'notiRead']?: {[key in string]: boolean}}
      | undefined;
    if (Object.keys(notificationsReadState).length === 0 && metadata?.notiRead) {
      dispatch(setReadState(metadata.notiRead));
    } else if (Object.keys(notificationsReadState).length > 0) {
      chatUser?.setMetadata({
        notiRead: notificationsReadState,
      });
    }
  }, [chatUser, notificationsReadState]);

Any particular user.

Hello @dimaportenko,

I have checked this on my end and I am not able to reproduce the issue on our end.

Steps I followed,

  1. Updated the metadata of logged-in user using CometChat.updateCurrentUserDetails()
  2. Uninstalled the app.
  3. Reinstalled the app.
  4. In the success of CometChat.login(), I was able to get the metadata. The metadata was the same as what I updated before uninstalling the app.

I have used the following CometChat SDK versions,

"@cometchat-pro/react-native-calls": "2.0.3-beta1",
"@cometchat-pro/react-native-chat": "2.3.2"

The metadata once updated, will be persistent since it is stored in a persistent database.

Can you please share a code snippet of how you are updating the metadata & check if you are clearing the metadata while updating the user?

Also, as I mentioned in my reply on this thread. You should be storing this data inside a @private key inside the metadata. Whatever you store inside the @private key will not be visible to other users (when they fetch the user list). Whatever data you store outside the @private key will be visible to other users (when they fetch the user list).

Warm Regards,

CometChat Pro
Mayur Bhandari

is it just not covered in TS?

Hello @dimaportenko,

This is covered in TS as well. You would have to update the SDK to 2.3.1+. The latest SDK version is 2.3.2. The updateCurrentUserDetails() was added in v2.3.1. You can check the changelog here.

Warm Regards,

CometChat Pro
Mayur Bhandari

@mayur.bhandari I’ve done an update of dependencies and use updateCurrentUserDetails. Looks like working good. Thank you for your quick support.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.