Sendbird Supergroup issue

Hi,

Can anyone help me with how I can retrieve the users who reacted on a message in a super group channel? Currently Sendbird returns only 10 of them in the members property so there is no way that I can reference all the reaction’s userId’s

Thanks

Hi there and welcome to the Sendbird community!!

Can you please share a snippet of how you are retrieving the members of a super group channel?
What happens if you try this below:

const getMembers = (channel) => {
    const memberListQuery = channel.createMemberListQuery();
    memberListQuery.limit = 10;

    const runMembersQuery = () => {
      memberListQuery.next((users, error) => {
        console.log(`memberListQuery ~ users (${users.length})`, users);
        if (memberListQuery.hasNext) {
          runMembersQuery();
        }
      });
    };
    runMembersQuery();
};

sendbird.GroupChannel.getChannel(channelUrl, (channel, error) => {
  this.getMembers(channel);
});

Hi Charis,

I’ve already implemented a paginated way of retrieving users for a super group. My issue is that if I want to show a screen with all the user and their reactions for a message, I can’t. The super group shows only 10 members and the reactions could be added by users that aren’t in those 10 retrieved by default. So I’m looking for a way to retrieve an array of users based on an array of userIds. I dont want to pre-download all the members and maybe the user won’t press the show message reactions button.

Thanks

To retrieve an array of users based on a userIds array you got from message.reactions[index].userIds, you can do the following:

  1. Save the userIds array in a custom attribute on the button you use to display all reactions. For example:
messageWithReactions.reactions.forEach(reaction => {
  const reactionButton = document.querySelector('.reaction-button')
  reactionButton.setAttribute('data-userIds-reactions', reaction.userIds.join(','))
  reactionButton.addEventListener('click', showReactions)
});

You should end up with something like this when you render your page:

<button onclick='showReactions' data-userIds-reactions='user1,user2,user3'
  1. Fetch the users list inside of the showReactions click handler. For example:
const showReactions = event => {
  const userIdsString = event.target.getAttribute('data-userIds-reactions')
  const userIds = userIdsString.split(',');
  const query = channel.createMemberListQuery();
  query.userIds = [...userIds];
  if (query.hasNext) {
    query.next(users => {
      // render all users that reacted here...
      console.log(users);
    });
  }
}

Let me know if this answers your question.

Can you please share the code you are using with the SDK function you are calling for this?
It should help me better understand if this is a Sendbird limitation or something that might be wrong in the code.

Thanks

Hi

Thanks for the proposed solution. Unfortunately, on iOS sdk I don’t see an userIds property for the SBDGroupChannelMemberListQuery object

I don’t have anything to share yet as I am still to find a solution for my issue. The code worked because we didn’t have supergroups and all the group members where returned in the group’s members property.

Thanks

Hi @Alexandru_Emil_Bofu, I just want to clarify on your last post. Are you saying that when using a standard group channel it returns all of the users but when using a supergroup, it only is returning 10?

Hi Tyler. Yes, it says in your docs too. Members property returns only 10 users for a supergroup so I need to do additional handling for showing the users who reacted for a message. The problem is that I don’t know how.

Hi @Alexandru_Emil_Bofu Correct me if I misunderstand your question. So you have a super group and you want to reference users who reacted on a message but super group’s member only returns 10 members (yes this is for scalability issue). If this is correct, there are two ways to fetch user list

if you want to fetch user list based on your super group channel, then you can paginate members through SBDGroupChannelMemberListQuery .

if you want to fetch user list based on list of user ids, then you can fetch these members through SBDApplicationUserListQuey with userIdsFilter

1 Like

Thanks a lot Woo. Indeed, SBDApplicationUserListQuery was what I was looking for. Have a nice day all of you and thanks for the assistance

1 Like

Any time :slight_smile: Have a nice day!