Flutter SDK GroupChannelListQuery Order and pagination acting weird

I have a query as follows:

final GroupChannelListQuery query = GroupChannelListQuery()
  ..customTypeStartsWithFilter = 'my channel custom type'
  ..myMemberStateFilter = MyMemberStateFilter.joined
  ..limit = 5;

When I set the order to GroupChannelListQueryOrder.latestLastMessage (the default value), the results of the query are abnormal. There are instances where the same channel appears more than once, and the total count of channels is incorrect.

Taking my app as an example, a group channel with the custom type ‘mytype’ should have 13 channels. In the first query, I get five channels as result. When calling next() again, only two channels are retrieved, and query.hasNext is false. Additionally, one of the channels obtained in the second query is a duplicate of those obtained in the first query.

However, when I change the order to GroupChannelListQueryOrder.channelNameAlphabetical, the query works perfectly fine, and I get the correct 13 channels without duplicates.

[SDK Version] Flutter SDK version 4

[Reproduction Steps]
set query with limit and order by default, get incorrect result.

[Frequency] always

[Current impact] couldn’t get correct result

Hello @shayne25

The abnormal behavior you’re experiencing with the GroupChannelListQuery is likely due to the combination of the custom type filter and the latestLastMessage order. This can cause duplicate channels to appear in the results and an incorrect total count.

To resolve this issue, you can try using the GroupChannelListQueryOrder.channelNameAlphabetical order instead. This should give you the correct results without any duplicates.

Here’s an example of how you can modify your code:

final GroupChannelListQuery query = GroupChannelListQuery()
  ..customTypeStartsWithFilter = 'my channel custom type'
  ..myMemberStateFilter = MyMemberStateFilter.joined
  ..limit = 5
  ..order = GroupChannelListQueryOrder.channelNameAlphabetical;

By setting the order to GroupChannelListQueryOrder.channelNameAlphabetical, you should be able to retrieve the correct channels without any duplicates.

Let me know if this helps in resolving your issue.

Hello @Chinmaya_Gupta ,

Yes, I did figure out that if I order with GroupChannelListQueryOrder.channelNameAlphabetical , everything works fine.
However, for my application, I need to order the channels based on the latestLastMessage, similar to how most chat apps do.

So, I’m wondering if you have recently addressed or fixed this issue?