stream-chat-js icon indicating copy to clipboard operation
stream-chat-js copied to clipboard

Cannot get descending sort to work in message search

Open tarnas14 opened this issue 1 year ago • 1 comments

I'm trying to figure out why descending sorting doesn't seem to work in messages search.

I've read the documentation 10 times, but I'm 99.999% sure that I'm passing the sort property correctly to search()

I'm on stream-chat version 4.1.0 - this could possibly have caused the issue, but I've gone through client.ts and utils.ts code in the installed node_modules and they seem to be doing pretty much the same thing as the newest code on https://github.com/GetStream/stream-chat-js/ .

I feel like the same code used to work a week or 2 ago. Although at this point I don't believe anything, anymore.

code snippet of what I'm trying to do: (notice that -1 or 1 doesn't seem to change anything in the results, which are returned in ascending order)

    const { results: descendingResults } = await chatService.getClient().search(
      {
        id: channelId,
      },
      {
        messageType: { $eq: 'myCustomMessageType' },
      },
      {
        sort: [{ created_at: -1 }],
      },
    );
    
    const { results: ascendingResults } = await chatService.getClient().search(
      {
        id: channelId,
      },
      {
        messageType: { $eq: 'myCustomMessageType' },
      },
      {
        sort: [{ created_at: 1 }],
      },
    );
    
    console.log({
      descending: (descendingResults ?? []).map(r => ({
        created_at: r.message.created_at,
      })),
      ascending: (ascendingResults ?? []).map(r => ({
        created_at: r.message.created_at,
      })),
    });

results:

{                                                                          
  descending: [                                                            
    { created_at: '2023-05-08T11:52:27.323888Z' },
    { created_at: '2023-05-08T11:52:18.757874Z' },
    { created_at: '2023-05-08T11:52:21.79231Z' }, 
    { created_at: '2023-05-08T11:53:27.459933Z' },
    { created_at: '2023-05-08T13:29:46.033821Z' },
    { created_at: '2023-05-11T09:37:37.113285Z' },
    { created_at: '2023-05-11T10:01:48.862315Z' },
    { created_at: '2023-05-11T10:03:28.181307Z' },
    { created_at: '2023-05-11T10:03:36.497051Z' },
    { created_at: '2023-05-11T10:06:19.245816Z' },
    { created_at: '2023-05-11T10:20:02.283142Z' },
    { created_at: '2023-05-11T10:22:57.563862Z' },
    { created_at: '2023-05-11T10:31:34.8587Z' },  
    { created_at: '2023-05-11T10:33:30.329329Z' },
    { created_at: '2023-05-12T12:27:22.249549Z' },
    { created_at: '2023-05-12T12:29:24.547221Z' },
    { created_at: '2023-05-14T20:26:29.730223Z' },
    { created_at: '2023-05-14T20:37:03.832326Z' },
    { created_at: '2023-05-14T20:37:29.337398Z' },
    { created_at: '2023-05-14T20:52:48.184526Z' }
  ],                                                                       
  ascending: [     
    { created_at: '2023-05-08T11:52:27.323888Z' },
    { created_at: '2023-05-08T11:52:18.757874Z' },
    { created_at: '2023-05-08T11:52:21.79231Z' },
    { created_at: '2023-05-08T11:53:27.459933Z' },
    { created_at: '2023-05-08T13:29:46.033821Z' },
    { created_at: '2023-05-11T09:37:37.113285Z' },
    { created_at: '2023-05-11T10:01:48.862315Z' },
    { created_at: '2023-05-11T10:03:28.181307Z' },
    { created_at: '2023-05-11T10:03:36.497051Z' },
    { created_at: '2023-05-11T10:06:19.245816Z' },
    { created_at: '2023-05-11T10:20:02.283142Z' },
    { created_at: '2023-05-11T10:22:57.563862Z' },
    { created_at: '2023-05-11T10:31:34.8587Z' },
    { created_at: '2023-05-11T10:33:30.329329Z' },
    { created_at: '2023-05-12T12:27:22.249549Z' },
    { created_at: '2023-05-12T12:29:24.547221Z' },
    { created_at: '2023-05-14T20:26:29.730223Z' },
    { created_at: '2023-05-14T20:37:03.832326Z' },
    { created_at: '2023-05-14T20:37:29.337398Z' },
    { created_at: '2023-05-14T20:52:48.184526Z' }
  ]                            
} 

tarnas14 avatar May 14 '23 22:05 tarnas14