diff --git a/Examples/Program_DownloadSavedMedia.cs b/Examples/Program_DownloadSavedMedia.cs index 62b6fad..f2cde0f 100644 --- a/Examples/Program_DownloadSavedMedia.cs +++ b/Examples/Program_DownloadSavedMedia.cs @@ -24,8 +24,11 @@ namespace WTelegramClientTest if (arg is not Updates { updates: var updates }) return; foreach (var update in updates) { - if (update is not UpdateNewMessage { message: Message message } || message.peer_id.ID != user.ID) - continue; // if it's not a new saved message, ignore it + if (update is not UpdateNewMessage { message: Message message }) + continue; // if it's not about a new message, ignore the update + if (message.peer_id.ID != user.ID) + continue; // if it's not in the "Saved messages" chat, ignore it + if (message.media is MessageMediaDocument { document: Document document }) { int slash = document.mime_type.IndexOf('/'); // quick & dirty conversion from MIME type to file extension @@ -44,7 +47,7 @@ namespace WTelegramClientTest fileStream.Close(); // necessary for the renaming Console.WriteLine("Download finished"); if (type is not Storage_FileType.unknown and not Storage_FileType.partial) - File.Move(filename, $"{photo.id}.{type}"); // rename extension + File.Move(filename, $"{photo.id}.{type}", true); // rename extension } } } diff --git a/src/Client.cs b/src/Client.cs index 2270e02..357e593 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -916,8 +916,10 @@ namespace WTelegram { if (prevUser.id == int.Parse(botToken.Split(':')[0])) { - var udpatesState = await this.Updates_GetState(); // this call enables incoming Updates - OnUpdate(udpatesState); + // Update our info about the user, and reenable incoming Updates + var users = await this.Users_GetUsers(new[] { InputUser.Self }); + if (users.Length > 0 && users[0] is User self) + _session.User = prevUser = self; return prevUser; } Helpers.Log(3, $"Current logged user {prevUser.id} mismatched bot_token. Logging out and in..."); @@ -965,8 +967,10 @@ namespace WTelegram if (sameUser) { // TODO: implement a more complete Updates gaps handling system? https://core.telegram.org/api/updates - var udpatesState = await this.Updates_GetState(); // this call enables incoming Updates - OnUpdate(udpatesState); + // Update our info about the user, and reenable incoming Updates + var users = await this.Users_GetUsers(new[] { InputUser.Self }); + if (users.Length > 0 && users[0] is User self) + _session.User = prevUser = self; return prevUser; } Helpers.Log(3, $"Current logged user {prevUser.id} mismatched user_id or phone_number. Logging out and in...");