Retrieve a list of all users a specific user has contacted, sorted alphabetically by nickname

Hi

We are on online marketplace where users can book services with each other. We use Sendbird as our communication channel between users (each booking is a chat and so therefore there are several chats between the same 2 users).

It would be very useful for us (and I guess other marketplaces where there is repeat and which work in a similar way) if we could retrieve a list of all other users that a logged in user has contacted in the past so that we can create a list of “contacts”.

I understand that there is a User List Query function but this seems to be only for “users blocked by the currently logged in user”.

Right now, we have to:

  1. Fetch all group channels
  2. Parse out the unique user ids in these
  3. Where a user ID is not equal to the ID of the logged-in user then that user becomes a contact.
  4. We then sort this list alphabetically.
  5. As the logged in user scrolls his contacts we add more to the list.

However, given this is a workaround it results in a rather odd UX, as not all new users are added to the bottom of the contact list - sometimes they can be added in the middle or even at the top of the list when the names of the newly parsed users say begin with “A”.

It would be great if we could have a function whereby we can retrieve these contacts directly, sorted name alphabetically.

If there’s a way this can already be done which I may have missed please let me know.

Best
Nicholas

Could this be helpful?

If you have 2 or more users chatting on a channel, you can search those channels by the ID of your logged user.

That result will show other users in the channel so you know who this user was talking to.

Filter channels by user IDs

To filter group channels by user IDs, use the userIdsExactFilter or userIdsIncludeFilter . Let’s assume the ID of the current user is Harry and the user is a member of two group channels:

  • channelA consists of Harry , John , and Jay .
  • channelB consists of Harry , John , Jay , and Jin .

A userIdsExactFilter returns a list of the current user’s group channels containing exactly the queried user IDs. In case you specify only one user ID in the filter, the filter returns a list of the current user’s one (distinct) or more 1-on-1 group channels with the specified user.

Light Color Skin

Copy

var filteredQuery = sb.GroupChannel.createMyGroupChannelListQuery();
filteredQuery.userIdsExactFilter = ['John', 'Jay'];
filteredQuery.next(function(groupChannels, error) {
    ...
    // Only 'channelA' is returned.
});

A userIdsIncludeFilter returns a list of the current user’s group channels including the queried user IDs partially and exactly. Two different results can be returned according to the value of the queryType parameter.

Light Color Skin

Copy

var filteredQuery = sb.GroupChannel.createMyGroupChannelListQuery();
filteredQuery.userIdsIncludeFilter = ['John', 'Jay', 'Jin'];
filteredQuery.next(function(groupChannels, error) {
    ...
    // Only 'channelB' that include the ids {'John', 'Jay', 'Jin'} as a subset is returned.
});

filteredQuery.queryType = sb.GroupChannelListQuery.QueryType.OR;
filteredQuery.next(function(groupChannels, err) {
    ...
    // 'channelA' and 'channelB' that include {'John'}, plus 'channelA' and 'channelB' that include {'Jay'}, plus 'channelB' that include {'Jin'}.
    // Actually 'channelA' and 'channelB' are returned.
});
1 Like

Hi Walter

Thanks for the suggestion, but no unfortunately it doesn’t help. We already use that to get the Group Channels the logged in user is part of and from that we parse out the other users to build a list of “contacts”. What we want to get is a list of all the IDs users with which the logged in user is at least in one Group channel with, without having to first fetch all the Group channels and then parse out the other user IDs.

If you call my_group_channels for a user (your logged user) you can get all his channels:

/v3/users/**my-user-id**/my_group_channels/?show_member=true

The response will show all the channels and the members inside.

Hi Walter,

Thanks again but this is essentially what we do. We would rather not have to fetch all the channels first. Every booking is a separate channel so we very often have several channels which involve the same two people as we have a lot of repeat.

Consequently we would still have to loop over the channels and parse out the unique “other members”. What we are looking for is a query where we would get an array of other members the logged in user has been in contact with, without having to fetch the channels first.