observeUser - incomplete data set

Hi,

We are implementing the user observer like the doc shows :

 const [data, setUser] = useState<Amity.Snapshot<Amity.User>>();
  const { data: user, loading, error } = data ?? {};

  useEffect(() => observeUser(userId, setUser), [userId]);

…the observer works but the data set seems incomplete.

What we need is to be able to check who’s a moderator and who’s not. The issue is that the role array and the permission array are empty.

The only way to get channel members roles is to use the channelMemberQuery, but it would mean that I would need to send the query every X seconds, and then check wether the user id is included in the list.

Is there a fix coming soon?

Hi @jsharl sorry for late response, to get channel roles, you can also use this sample code below

const query = createQuery(queryCommunityMembers, { communityId: 'communityId', roles: ['community-moderator', 'channel-moderator'], }) runQuery(query, (membersResult) => console.log(JSON.stringify(membersResult)))

Please let us know, if you have further questions :pray:

1 Like

Thank you for the detailed answer.
I’ll try this asap and will let you informed.
However, I would rather use sockets for this task since I would like to get the real time update wether the member status changes.

[EDIT]: After discussing the issue with my team , our need is that each user should be able to detect in real time wether a role has been granted to their account in order to display the relevant possible actions on the UI given their userId.

Hope I’m being clear on what we 're trying to achieve.

[EDIT]: Finally, the user observer seems to work but only for global roles.
Roles and permissions arrays stay empty when promoting a user for a particular channel.

Hi @jsharl our team has suggested to use queryChannelMembers to get user details those are related to channels/communities, please see the link below

https://docs.amity.co/chat/typescript/channels/channel-participation#members-query