From 1877c9061c0e8e8033cb68f9257bc75fa3fb18c4 Mon Sep 17 00:00:00 2001 From: Afshin Arani Date: Thu, 9 Nov 2017 04:21:10 -0800 Subject: [PATCH 1/2] Handle Import & Export Authorization While Reconnecting closes #624 --- TLSharp.Core/TelegramClient.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 126370d..f1c8692 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -85,6 +85,13 @@ namespace TLSharp.Core { if (dcOptions == null || !dcOptions.Any()) throw new InvalidOperationException($"Can't reconnect. Establish initial connection first."); + + TLExportedAuthorization exported = null; + if (_session.TLUser != null) + { + TLRequestExportAuthorization exportAuthorization = new TLRequestExportAuthorization() { DcId = dcId }; + exported = await SendRequestAsync(exportAuthorization); + } var dc = dcOptions.First(d => d.Id == dcId); @@ -92,7 +99,14 @@ namespace TLSharp.Core _session.ServerAddress = dc.IpAddress; _session.Port = dc.Port; - await ConnectAsync(true); + await ConnectAsync(true); + + if (_session.TLUser != null) + { + TLRequestImportAuthorization importAuthorization = new TLRequestImportAuthorization() { Id = exported.Id, Bytes = exported.Bytes }; + var imported = await SendRequestAsync(importAuthorization); + OnUserAuthenticated(((TLUser)imported.User)); + } } private async Task RequestWithDcMigration(TLMethod request) From d15d87833e93f91b5d9de48b274c5afc83fde924 Mon Sep 17 00:00:00 2001 From: Afshin Arani Date: Thu, 16 Nov 2017 00:34:01 +0330 Subject: [PATCH 2/2] Remove Old FileMigrationException Handler this catch block could never be reached anymore because of changes proposed in #622 --- TLSharp.Core/TelegramClient.cs | 39 +++++----------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index f1c8692..b1aafa1 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -300,41 +300,12 @@ namespace TLSharp.Core public async Task GetFile(TLAbsInputFileLocation location, int filePartSize, int offset = 0) { TLFile result = null; - try + result = await SendRequestAsync(new TLRequestGetFile() { - result = await SendRequestAsync(new TLRequestGetFile() - { - Location = location, - Limit = filePartSize, - Offset = offset - }); - } - catch (FileMigrationException ex) - { - var exportedAuth = await SendRequestAsync(new TLRequestExportAuthorization() { DcId = ex.DC }); - - var authKey = _session.AuthKey; - var timeOffset = _session.TimeOffset; - var serverAddress = _session.ServerAddress; - var serverPort = _session.Port; - - await ReconnectToDcAsync(ex.DC); - var auth = await SendRequestAsync(new TLRequestImportAuthorization - { - Bytes = exportedAuth.Bytes, - Id = exportedAuth.Id - }); - result = await GetFile(location, filePartSize, offset); - - _session.AuthKey = authKey; - _session.TimeOffset = timeOffset; - _transport = new TcpTransport(serverAddress, serverPort); - _session.ServerAddress = serverAddress; - _session.Port = serverPort; - await ConnectAsync(); - - } - + Location = location, + Limit = filePartSize, + Offset = offset + }); return result; }