ObserveUser not triggers on metadata change

Hello,

I’m trying to listen to metadata changes in the user data. but when updating the user metadata the observeUser doesn’t get triggered.

Does the observeUser not listen to changes in the metadata ?

I’m using the observeUser from the typescript SDK in expo react native.

code for listening

        return observeUser(postedUserId, ({ data: updatedUser }) => {
            setPostedUser(updatedUser);
            if(updatedUser?.metadata){
              console.log(updatedUser.metadata)
            }

code for updating user

        const query = createQuery(updateUser, user.id, {
            metadata: {
                data: data
            }
        });
        runQuery(query, updateResult => console.log(updateResult));

Hey,
Few details on the internal implementation. All observers listen for google pub/sub events, updates come from there. To receive the update, you need to subscribe to user updates first. Few observeXXX things are still working without explicit subscription, but it will be changed in future.
https://docs.amity.co/social/typescript-react-native/realtime-events

import { getUserTopic, subscribeTopic } from '@amityco/ts-sdk';

const topic = getUserTopic(user);

const unsubscribe = subscribeTopic(topic, (error) => {
  if (error) {
    console.error('failed to subscribe');
  }
});

I see 2 ways to resolve you issue:

const [postedUser, setPostedUser] = React.useState();

React.useEffect(() => {
  return observeUser(postedUserId, ({ data: updatedUser }) => setPostedUser(updatedUser ));
}, [postedUserId]);

React.useEffect(() => {
  if (!postedUser) {
    return;
  }

  return subsribeTopic(getUserTopic(postedUser));
}, [postedUser?.userId]

There is a limitation right now., you can subscribe only to yourself.

or use runQuery's callback to update the user in state

const query = createQuery(updateUser, user.id, {...});

runQuery(query, updateResult => setPostedUser(updateResult.data));

p.s. Can you pls let us know how you feel about getting topic, subscribing to topic. Is it convenient to use for you?

Personally the documentation on it is not very clear to me. but thanks to your git repo I was able to get to grips with it quite quickly.

It also seems to work very fast on the parts where i got it working. with not a lot of code.