mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Added method to DisableUpdates
This commit is contained in:
parent
4f1a6610aa
commit
1299e27cab
|
|
@ -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`.
|
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)**.
|
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
|
# 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.
|
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.
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,8 @@ namespace WTelegram
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DisableUpdates(bool disable = true) => _dcSession.DisableUpdates(disable);
|
||||||
|
|
||||||
/// <summary>Disconnect from Telegram <i>(shouldn't be needed in normal usage)</i></summary>
|
/// <summary>Disconnect from Telegram <i>(shouldn't be needed in normal usage)</i></summary>
|
||||||
/// <param name="resetUser">Forget about logged-in user</param>
|
/// <param name="resetUser">Forget about logged-in user</param>
|
||||||
/// <param name="resetSessions">Disconnect secondary sessions with other DCs</param>
|
/// <param name="resetSessions">Disconnect secondary sessions with other DCs</param>
|
||||||
|
|
@ -902,7 +904,7 @@ namespace WTelegram
|
||||||
{
|
{
|
||||||
try
|
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;
|
var self = users[0] as User;
|
||||||
// check user_id or phone_number match currently logged-in 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)) ||
|
if ((long.TryParse(_config("user_id"), out long id) && (id == -1 || self.id == id)) ||
|
||||||
|
|
@ -1135,6 +1137,8 @@ namespace WTelegram
|
||||||
/// <returns>Wait for the reply and return the resulting object, or throws an RpcException if an error was replied</returns>
|
/// <returns>Wait for the reply and return the resulting object, or throws an RpcException if an error was replied</returns>
|
||||||
public async Task<T> Invoke<T>(IMethod<T> query)
|
public async Task<T> Invoke<T>(IMethod<T> query)
|
||||||
{
|
{
|
||||||
|
if (_dcSession.WithoutUpdates && query is not IMethod<Pong>)
|
||||||
|
query = new TL.Methods.InvokeWithoutUpdates<T> { query = query };
|
||||||
bool got503 = false;
|
bool got503 = false;
|
||||||
retry:
|
retry:
|
||||||
var rpc = new Rpc { type = typeof(T) };
|
var rpc = new Rpc { type = typeof(T) };
|
||||||
|
|
|
||||||
|
|
@ -28,12 +28,14 @@ namespace WTelegram
|
||||||
public long ServerTicksOffset;
|
public long ServerTicksOffset;
|
||||||
public long LastSentMsgId;
|
public long LastSentMsgId;
|
||||||
public TL.DcOption DataCenter;
|
public TL.DcOption DataCenter;
|
||||||
|
public bool WithoutUpdates;
|
||||||
|
|
||||||
internal Client Client;
|
internal Client Client;
|
||||||
internal int DcID => DataCenter?.id ?? 0;
|
internal int DcID => DataCenter?.id ?? 0;
|
||||||
internal IPEndPoint EndPoint => DataCenter == null ? null : new(IPAddress.Parse(DataCenter.ip_address), DataCenter.port);
|
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; }
|
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;
|
const int msgIdsN = 512;
|
||||||
private long[] msgIds;
|
private long[] msgIds;
|
||||||
private int msgIdsHead;
|
private int msgIdsHead;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue