mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Fix #335 GetAllDialogs infinite loop when last dialogs' messages are unavailable
Some checks failed
Dev build / build (push) Has been cancelled
Some checks failed
Dev build / build (push) Has been cancelled
This commit is contained in:
parent
4578dea3a3
commit
3f1036a559
|
|
@ -8,7 +8,7 @@
|
|||
This library allows you to connect to Telegram and control a user programmatically (or a bot, but [WTelegramBot](https://www.nuget.org/packages/WTelegramBot) is much easier for that).
|
||||
All the Telegram Client APIs (MTProto) are supported so you can do everything the user could do with a full Telegram GUI client.
|
||||
|
||||
Library was developed solely by one unemployed guy. [Donations are welcome](https://buymeacoffee.com/wizou).
|
||||
Library was developed solely by one unemployed guy. [Donations](https://buymeacoffee.com/wizou) or [Patreon memberships are welcome](https://patreon.com/wizou).
|
||||
|
||||
This ReadMe is a **quick but important tutorial** to learn the fundamentals about this library. Please read it all.
|
||||
|
||||
|
|
|
|||
|
|
@ -535,18 +535,20 @@ namespace WTelegram
|
|||
case Messages_DialogsSlice mds:
|
||||
var dialogList = new List<DialogBase>();
|
||||
var messageList = new List<MessageBase>();
|
||||
while (dialogs.Dialogs.Length != 0)
|
||||
int skip = 0;
|
||||
while (dialogs.Dialogs.Length > skip)
|
||||
{
|
||||
dialogList.AddRange(dialogs.Dialogs);
|
||||
dialogList.AddRange(skip == 0 ? dialogs.Dialogs : dialogs.Dialogs[skip..]);
|
||||
messageList.AddRange(dialogs.Messages);
|
||||
skip = 0;
|
||||
int last = dialogs.Dialogs.Length - 1;
|
||||
var lastDialog = dialogs.Dialogs[last];
|
||||
retryDate:
|
||||
var lastPeer = dialogs.UserOrChat(lastDialog).ToInputPeer();
|
||||
var lastMsgId = lastDialog.TopMessage;
|
||||
retryDate:
|
||||
var lastDate = dialogs.Messages.LastOrDefault(m => m.Peer.ID == lastDialog.Peer.ID && m.ID == lastDialog.TopMessage)?.Date ?? default;
|
||||
if (lastDate == default)
|
||||
if (--last < 0) break; else { lastDialog = dialogs.Dialogs[last]; goto retryDate; }
|
||||
if (--last < 0) break; else { ++skip; lastDialog = dialogs.Dialogs[last]; goto retryDate; }
|
||||
dialogs = await this.Messages_GetDialogs(lastDate, lastMsgId, lastPeer, folder_id: folder_id);
|
||||
if (dialogs is not Messages_Dialogs md) break;
|
||||
foreach (var (key, value) in md.chats) mds.chats[key] = value;
|
||||
|
|
|
|||
Loading…
Reference in a new issue