use Users_GetUsers instead of Updates_GetState in login so we update our User info

This commit is contained in:
Wizou 2021-11-04 20:10:44 +01:00
parent 42348166f0
commit b872e58e28
2 changed files with 14 additions and 7 deletions

View file

@ -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
}
}
}

View file

@ -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...");