From 72d94df9072e9a53cd827247f1c6921db84a5435 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Mon, 1 Mar 2021 22:14:36 +0100 Subject: [PATCH] FIX: new message loop will now correctly manage events and form switches --- TelegramBotBase/BotBase.cs | 39 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs index caba2c1..74f2e52 100644 --- a/TelegramBotBase/BotBase.cs +++ b/TelegramBotBase/BotBase.cs @@ -372,32 +372,33 @@ namespace TelegramBotBase } //Action Event - if (!ds.FormSwitched) + if (!ds.FormSwitched && e.IsAction) { - if (e.IsAction) + //Send Action event to controls + await activeForm.ActionControls(e); + + //Send Action event to form itself + await activeForm.Action(e); + + if (!e.Handled) { - //Send Action event to controls - await activeForm.ActionControls(e); + var uhc = new UnhandledCallEventArgs(e.Message.Text, e.RawData, ds.DeviceId, e.MessageId, e.Message, ds); + OnUnhandledCall(uhc); - //Send Action event to form itself - await activeForm.Action(e); - - if (!e.Handled) + if (uhc.Handled) { - var uhc = new UnhandledCallEventArgs(e.Message.Text, e.RawData, ds.DeviceId, e.MessageId, e.Message, ds); - OnUnhandledCall(uhc); - - if (uhc.Handled) + e.Handled = true; + if (!ds.FormSwitched) { - e.Handled = true; - if (!ds.FormSwitched) - { - break; - } + break; } } } + } + + if (!ds.FormSwitched) + { //Render Event await activeForm.RenderControls(e); @@ -433,10 +434,10 @@ namespace TelegramBotBase { DeviceSession ds = this.Sessions.GetSession(DeviceId); e.Device = ds; - + await Client_Loop(this, e); } - catch(Exception ex) + catch (Exception ex) { DeviceSession ds = this.Sessions.GetSession(DeviceId); OnException(new SystemExceptionEventArgs(e.Message.Text, DeviceId, ds, ex));