diff --git a/Examples/Program_DownloadSavedMedia.cs b/Examples/Program_DownloadSavedMedia.cs index c65c13a..186ddbb 100644 --- a/Examples/Program_DownloadSavedMedia.cs +++ b/Examples/Program_DownloadSavedMedia.cs @@ -18,10 +18,9 @@ namespace WTelegramClientTest client.OnUpdate += Client_OnUpdate; Console.ReadKey(); - async Task Client_OnUpdate(IObject arg) + async Task Client_OnUpdate(UpdatesBase updates) { - if (arg is not Updates { updates: var updates } upd) return; - foreach (var update in updates) + foreach (var update in updates.UpdateList) { if (update is not UpdateNewMessage { message: Message message }) continue; // if it's not about a new message, ignore the update diff --git a/Examples/Program_Heroku.cs b/Examples/Program_Heroku.cs index 70fffdf..23555ae 100644 --- a/Examples/Program_Heroku.cs +++ b/Examples/Program_Heroku.cs @@ -39,9 +39,8 @@ namespace WTelegramClientTest } } - private static async Task Client_OnUpdate(IObject arg) + private static async Task Client_OnUpdate(UpdatesBase updates) { - if (arg is not UpdatesBase updates) return; updates.CollectUsersChats(Users, Chats); foreach (var update in updates.UpdateList) { diff --git a/Examples/Program_ListenUpdates.cs b/Examples/Program_ListenUpdates.cs index b94165e..c69ebb0 100644 --- a/Examples/Program_ListenUpdates.cs +++ b/Examples/Program_ListenUpdates.cs @@ -33,9 +33,8 @@ namespace WTelegramClientTest } // if not using async/await, we could just return Task.CompletedTask - private static async Task Client_OnUpdate(IObject arg) + private static async Task Client_OnUpdate(UpdatesBase updates) { - if (arg is not UpdatesBase updates) return; updates.CollectUsersChats(Users, Chats); foreach (var update in updates.UpdateList) switch (update) diff --git a/Examples/Program_SecretChats.cs b/Examples/Program_SecretChats.cs index 4b0edf0..637ead7 100644 --- a/Examples/Program_SecretChats.cs +++ b/Examples/Program_SecretChats.cs @@ -76,9 +76,8 @@ Type a command, or a message to send to the active secret chat:"); } while (true); } - private static async Task Client_OnUpdate(IObject arg) + private static async Task Client_OnUpdate(UpdatesBase updates) { - if (arg is not UpdatesBase updates) return; updates.CollectUsersChats(Users, Chats); foreach (var update in updates.UpdateList) switch (update) diff --git a/src/Client.cs b/src/Client.cs index c9006a5..ecf75a7 100644 --- a/src/Client.cs +++ b/src/Client.cs @@ -25,7 +25,9 @@ namespace WTelegram { /// This event will be called when unsollicited updates/messages are sent by Telegram servers /// Make your handler , or return or
See Examples/Program_ListenUpdate.cs for how to use this
- public event Func OnUpdate; + public event Func OnUpdate; + /// This event is called for other types of notifications (login states, reactor errors, ...) + public event Func OnOther; /// Used to create a TcpClient connected to the given address/port, or throw an exception on failure public TcpFactory TcpHandler { get; set; } = DefaultTcpHandler; public delegate Task TcpFactory(string host, int port); @@ -646,7 +648,7 @@ namespace WTelegram } break; case 48: // incorrect server salt (in this case, the bad_server_salt response is received with the correct salt, and the message is to be re-sent with it) - _dcSession.Salt = ((BadServerSalt)badMsgNotification).new_server_salt; + _dcSession.Salt = ((BadServerSalt)badMsgNotification).new_server_salt; //TODO: GetFutureSalts break; default: retryLast = false; @@ -688,7 +690,7 @@ namespace WTelegram { try { - var task = OnUpdate?.Invoke(obj); + var task = obj is UpdatesBase updates ? OnUpdate?.Invoke(updates) : OnOther?.Invoke(obj); if (task != null) await task; } catch (Exception ex)