From f25058d8139644ba00bb875e5b6b887943a95c8a Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Fri, 10 Apr 2020 15:36:35 +0800 Subject: [PATCH] Core: allow re-connecting from same TelegramClient If the connection dropped, there was no way to reconnect from the same instance of TelegramClient. --- TLSharp.Core/TelegramClient.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/TLSharp.Core/TelegramClient.cs b/TLSharp.Core/TelegramClient.cs index 765ecbf5..2fcda88e 100644 --- a/TLSharp.Core/TelegramClient.cs +++ b/TLSharp.Core/TelegramClient.cs @@ -29,6 +29,8 @@ public class TelegramClient : IDisposable private string apiHash = String.Empty; private int apiId = 0; private Session session; + private string sessionUserId; + private ISessionStore store; private List dcOptions; private TcpClientConnectionHandler handler; private DataCenterIPVersion dcIpVersion; @@ -58,20 +60,22 @@ public TelegramClient(int apiId, string apiHash, if (store == null) store = new FileSessionStore(); + this.store = store; this.apiHash = apiHash; this.apiId = apiId; this.handler = handler; this.dcIpVersion = dcIpVersion; - - session = Session.TryLoadOrCreateNew(store, sessionUserId); - transport = new TcpTransport (session.DataCenter.Address, session.DataCenter.Port, this.handler); + this.sessionUserId = sessionUserId; } public async Task ConnectAsync(bool reconnect = false, CancellationToken token = default(CancellationToken)) { token.ThrowIfCancellationRequested(); + session = Session.TryLoadOrCreateNew (store, sessionUserId); + transport = new TcpTransport (session.DataCenter.Address, session.DataCenter.Port, this.handler); + if (session.AuthKey == null || reconnect) { var result = await Authenticator.DoAuthentication(transport, token).ConfigureAwait(false);