tdlib / td

Cross-platform library for building Telegram clients
https://core.telegram.org/tdlib
Boost Software License 1.0
7.11k stars 1.44k forks source link

searchMessages: offset_chat_id and offset_message_id are ignored #2291

Closed ishimko closed 1 year ago

ishimko commented 1 year ago

When using searchMessages method, I am unable to "paginate" through results by providing offset chat and message, even when providing those, I keep getting the same results from the beginning. After the first request I take message and chat ids from the last returned message and provide them for the second request, but still getting same response from the beginning.

I use C# bindings for tdlib.

The first request:

[ 4][t 2][1675335401.119310617][MessagesManager.cpp:23853][#1][!SearchMessagesRequest]  Search all messages filtered by Empty with query = "*REDACTED*" from date 2147483647, chat 0, invalid message 0 and limit 100
[ 3][t 2][1675335401.119333982][NetQueryCreator.cpp:35][#1][!SearchMessagesRequest] Create query messages.searchGlobal {
  flags = 0
  q = "*REDACTED*"
  filter = inputMessagesFilterEmpty {
  }
  min_date = 0
  max_date = 0
  offset_rate = 2147483647
  offset_peer = inputPeerEmpty {
  }
  offset_id = 0
  limit = 100
}

The response for the first request:

[ 3][t 2][1675335401.707185983][Td.cpp:3991][#1][!Td][&td_requests] Sending result for request 121: messages {
  total_count = 2473
  messages = vector[100] {
    message {
      id = 702545920
. . .

The second request:

[ 3][t 2][1675335403.669348001][Td.cpp:2931][#1][!Td][&td_requests] Receive request 122: searchMessages {
  chat_list = null
  query = "*REDACTED*"
  offset_date = 0
  offset_chat_id = *REDACTED*
  offset_message_id = 663748608 // The last one from the previous response
  limit = 100
  filter = null
  min_date = 0
  max_date = 0
}
[ 4][t 2][1675335403.669373750][MessagesManager.cpp:23853][#1][!SearchMessagesRequest]  Search all messages filtered by Empty with query = "*REDACTED*" from date 2147483647, chat *REDACTED*, server message 633 and limit 100
[ 3][t 2][1675335403.669385671][NetQueryCreator.cpp:35][#1][!SearchMessagesRequest] Create query messages.searchGlobal {
  flags = 0
  q = "*REDACTED*"
  filter = inputMessagesFilterEmpty {
  }
  min_date = 0
  max_date = 0
  offset_rate = 2147483647
  offset_peer = inputPeerChannel {
    channel_id = *REDACTED*
    access_hash = 0
  }
  offset_id = 633
  limit = 100
}

The response for the second request:

[ 3][t 2][1675335404.102910757][Td.cpp:3991][#1][!Td][&td_requests] Sending result for request 122: messages {
  total_count = 2473
  messages = vector[100] {
    message {
      id = 702545920 // Same as in the first response

Am I doing something wrong?

levlam commented 1 year ago

TDLib 1.8.10 has a single parameter offset: "Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results" to simplify pagination.

ishimko commented 1 year ago

Thanks @levlam! Seems like the nuget package I use for .NET bindings is still on 1.8.9, I'll find another way then.