New channels out of order with `GroupChannelCollection`

I’ve recently started migrating over to local caching from sendbird-syncmanager. It’s going really well.

The only remaining hitch is that when we create new a channel (done by our back-end), our connected front-end receives the new channel through the onChannelsAdded handler callback. The channelList on the GroupChannelCollection is updated and contains the new channel. Unfortunately, the new channel is not in the order specified when creating the group channel collection.

We currently have the collection created as follows:

const channelFilter = new GroupChannelFilter();
channelFilter.customTypesFilter = ['SENDBIRD_DESK_CHANNEL_CUSTOM_TYPE'];

const groupChannelCollection = GroupChannel.createGroupChannelCollection()
  .setOrder(GroupChannelCollection.GroupChannelOrder.LATEST_LAST_MESSAGE)
  .setFilter(channelFilter)
  .setLimit(100)
  .build();

In the handler, we update our view as follows:

groupChannelCollection.setGroupChannelCollectionHandler({
  onChannelsAdded(_, addedChannels) {
    updateViewWithAllChannels(groupChannelCollection.channelList);
  }
});

Before creating the new channel, groupChannelCollection.channelList contains all the expected channels with the channel having the latest last message showing up first. This is desired.

After creating the new channel, groupChannelCollection.channelList in the handler above, has all the channels as before in the same order but with the new channel appended to the end, making the newest channel and message appear last. Recreating the GroupChannelCollection fixes this issue.

According to your docs, the order should be updated.

By default, cached channels are listed in reverse chronological order, meaning the channel that most recently received a message appears at the top of the list. The channel order is automatically updated in the local cache when a new message arrives.

I think this is a bug, unless we should not be using the GroupChannelCollection as a source of truth. I’m using sendbird v3.1.7. Note, this only happens when LATEST_LAST_MESSAGE is the selected order. With CHRONOLOGICAL and CHANNEL_NAME_ALPHABETICAL, the order of the updated channelList is correct.

Submitted to Support. Update will be posted with outcome.

The issue was resolved by v3.1.9(link)

1 Like