diff --git a/README.md b/README.md index ff40e98..8ddcfd2 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ If the account already exists and has enabled two-step verification (2FA) a **pa All these login scenarios are handled automatically within the call to `LoginUserIfNeeded`. And that's it, you now have access to the **[full range of Telegram Client APIs](https://corefork.telegram.org/methods)**. -All those API methods are available in the `TL` namespace *(with an underscore in the method name, instead of a dot)*, like this: `await client.Method_Name(...)` +All those API methods require `using TL;` namespace and are called with an underscore instead of a dot in the method name, like this: `await client.Method_Name(...)` # Saved session If you run this program again, you will notice that only **api_hash** is requested, the other prompts are gone and you are automatically logged-on and ready to go. diff --git a/src/Client.cs b/src/Client.cs index 6f62533..b330d0c 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -164,6 +164,8 @@ namespace WTelegram GC.SuppressFinalize(this); } + public void DisableUpdates(bool disable = true) => _dcSession.DisableUpdates(disable); + /// Disconnect from Telegram (shouldn't be needed in normal usage) /// Forget about logged-in user /// Disconnect secondary sessions with other DCs @@ -902,7 +904,7 @@ namespace WTelegram { try { - var users = await this.Users_GetUsers(new[] { InputUser.Self }); // this calls also reenable incoming Updates + var users = await this.Users_GetUsers(new[] { InputUser.Self }); // this call also reenable incoming Updates var self = users[0] as User; // check user_id or phone_number match currently logged-in user if ((long.TryParse(_config("user_id"), out long id) && (id == -1 || self.id == id)) || @@ -1135,6 +1137,8 @@ namespace WTelegram /// Wait for the reply and return the resulting object, or throws an RpcException if an error was replied public async Task Invoke(IMethod query) { + if (_dcSession.WithoutUpdates && query is not IMethod) + query = new TL.Methods.InvokeWithoutUpdates { query = query }; bool got503 = false; retry: var rpc = new Rpc { type = typeof(T) }; diff --git a/src/Session.cs b/src/Session.cs index 09d5a61..dee39b2 100644 --- a/src/Session.cs +++ b/src/Session.cs @@ -28,12 +28,14 @@ namespace WTelegram public long ServerTicksOffset; public long LastSentMsgId; public TL.DcOption DataCenter; + public bool WithoutUpdates; internal Client Client; internal int DcID => DataCenter?.id ?? 0; internal IPEndPoint EndPoint => DataCenter == null ? null : new(IPAddress.Parse(DataCenter.ip_address), DataCenter.port); internal void Renew() { Helpers.Log(3, $"Renewing session on DC {DcID}..."); Id = Helpers.RandomLong(); Seqno = 0; LastSentMsgId = 0; } - + public void DisableUpdates(bool disable = true) { if (WithoutUpdates != disable) { WithoutUpdates = disable; Renew(); } } + const int msgIdsN = 512; private long[] msgIds; private int msgIdsHead;