tdlib / td

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

getChats method seems not work properly! #56

Closed hatami57 closed 6 years ago

hatami57 commented 6 years ago

I've used getChats method with offset_order=2^63-1, offset_chat_id=0 and limit=100

getChats (std::int64_t offset_order_, std::int64_t offset_chat_id_, std::int32_t limit_)

It returns first 100 chats, but when I call it again to obtain next 100 chats with offset_order=(2^63-1) - 100, offset_chat_id=0 and limit=100, it returns the first 100 chats again! I've played with many different values for these parameters but it does not work! if I start offset_order from 0, it does not return any thing!

How should I use it to obtain all available chats in a Telegram account (even if there are thousands of chats)?

isopen commented 6 years ago

Try it. But I do not give any guarantees :) https://stackoverflow.com/questions/37782348/how-to-use-getchats-in-tdlib

hatami57 commented 6 years ago

Thank you! I've tried it but it does not work :-( For the first time I've set: offset_order=2^63-1, offset_chat_id=0, limit=1 For the next time: offset_order=(2^63-1) - 1, offset_chat_id=<last_received_chat_id>, limit=1 but it always returns the same chat_ids!

By the way, the getChats method just returns a list of chat_ids and not a pair of (order, chat_id)!

levlam commented 6 years ago

Chats are sorted in decreasing order by pairs (chat.order, chat.id) and returned in that order. To get chats from 99-th chat onward, you need to pass in getChats order and id of that chat, so the request should be

offset_order=<last_received_chat.order>, offset_chat_id=<last_received_chat.id>, limit=100

Also be aware that chats can change their order very often, so such iterative method may not work. You can find an example of a proper way of getting chat list in our Java example https://github.com/tdlib/td/blob/6c706f45e7a73c936b9f2f267785092c8a73348f/example/java/org/drinkless/tdlib/example/Example.java#L206.

hatami57 commented 6 years ago

Thank you! I thought the chat type is like telegram schema and has not order field. The example was useful :-)

rextable commented 2 years ago

I have try many time but getchats didn't work in python and tdjson always its send the last limit order