Updates and fixes
- adding IsFirstHandler to allow controls to skip Actions which has been invoked already (i.e. due to navigation) - adding Hidden method to ButtonGrid to fix re-rendering Buttons after opening a Modal form and comming back - improving and fixing the Cleanup method for ButtonGrid to prevent "Keyboard jumping" for ReplyKeyboard on mobile devices. - renaming some old *Result objects to *EventArgs for more clear definitions
This commit is contained in:
parent
d5a9a5f7a4
commit
fba922049f
@ -113,6 +113,11 @@ namespace TelegramBotBase.Base
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns if this message will be used on the first form or not.
|
||||
/// </summary>
|
||||
public bool IsFirstHandler { get; set; } = true;
|
||||
|
||||
public bool Handled { get; set; } = false;
|
||||
|
||||
public String RawData
|
||||
|
||||
@ -8,6 +8,7 @@ using Telegram.Bot;
|
||||
using TelegramBotBase.Args;
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
using TelegramBotBase.Interfaces;
|
||||
using TelegramBotBase.Sessions;
|
||||
|
||||
namespace TelegramBotBase
|
||||
@ -170,6 +171,7 @@ namespace TelegramBotBase
|
||||
this.Client.TelegramClient.StartReceiving();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Stop your Bot
|
||||
/// </summary>
|
||||
@ -212,7 +214,7 @@ namespace TelegramBotBase
|
||||
|
||||
if (LogAllMessages)
|
||||
{
|
||||
OnMessage(new MessageIncomeResult(e.DeviceId, ds, e));
|
||||
OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e));
|
||||
}
|
||||
|
||||
ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message));
|
||||
@ -240,7 +242,7 @@ namespace TelegramBotBase
|
||||
|
||||
ds.LastMessage = e.Message;
|
||||
|
||||
OnSessionBegins(new SessionBeginResult(e.DeviceId, ds));
|
||||
OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
|
||||
}
|
||||
|
||||
ds.LastAction = DateTime.Now;
|
||||
@ -289,15 +291,16 @@ namespace TelegramBotBase
|
||||
//Render Event
|
||||
if (!ds.FormSwitched)
|
||||
{
|
||||
|
||||
await activeForm.RenderControls(e);
|
||||
|
||||
await activeForm.Render(e);
|
||||
}
|
||||
|
||||
e.IsFirstHandler = false;
|
||||
|
||||
} while (ds.FormSwitched && i < NavigationMaximum);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Client_Action(object sender, MessageResult e)
|
||||
@ -309,7 +312,7 @@ namespace TelegramBotBase
|
||||
|
||||
if (LogAllMessages)
|
||||
{
|
||||
OnMessage(new MessageIncomeResult(e.DeviceId, ds, e));
|
||||
OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e));
|
||||
}
|
||||
|
||||
Client_TryAction(sender, e);
|
||||
@ -394,6 +397,8 @@ namespace TelegramBotBase
|
||||
await activeForm.Render(e);
|
||||
}
|
||||
|
||||
e.IsFirstHandler = false;
|
||||
|
||||
} while (ds.FormSwitched && i < NavigationMaximum);
|
||||
|
||||
}
|
||||
@ -402,7 +407,7 @@ namespace TelegramBotBase
|
||||
/// Will be called if a session/context gets started
|
||||
/// </summary>
|
||||
|
||||
public event EventHandler<SessionBeginResult> SessionBegins
|
||||
public event EventHandler<SessionBeginEventArgs> SessionBegins
|
||||
{
|
||||
add
|
||||
{
|
||||
@ -414,16 +419,16 @@ namespace TelegramBotBase
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSessionBegins(SessionBeginResult e)
|
||||
public void OnSessionBegins(SessionBeginEventArgs e)
|
||||
{
|
||||
(this.__Events[__evSessionBegins] as EventHandler<SessionBeginResult>)?.Invoke(this, e);
|
||||
(this.__Events[__evSessionBegins] as EventHandler<SessionBeginEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will be called on incomming message
|
||||
/// </summary>
|
||||
public event EventHandler<MessageIncomeResult> Message
|
||||
public event EventHandler<MessageIncomeEventArgs> Message
|
||||
{
|
||||
add
|
||||
{
|
||||
@ -435,9 +440,9 @@ namespace TelegramBotBase
|
||||
}
|
||||
}
|
||||
|
||||
public void OnMessage(MessageIncomeResult e)
|
||||
public void OnMessage(MessageIncomeEventArgs e)
|
||||
{
|
||||
(this.__Events[__evMessage] as EventHandler<MessageIncomeResult>)?.Invoke(this, e);
|
||||
(this.__Events[__evMessage] as EventHandler<MessageIncomeEventArgs>)?.Invoke(this, e);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -49,7 +49,6 @@ namespace TelegramBotBase.Controls
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
return m_eKeyboardType;
|
||||
}
|
||||
set
|
||||
@ -111,6 +110,8 @@ namespace TelegramBotBase.Controls
|
||||
if (this.KeyboardType != eKeyboardType.ReplyKeyboard)
|
||||
return;
|
||||
|
||||
if (!result.IsFirstHandler)
|
||||
return;
|
||||
|
||||
var button = ButtonsForm.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText);
|
||||
|
||||
@ -132,6 +133,9 @@ namespace TelegramBotBase.Controls
|
||||
if (result.Handled)
|
||||
return;
|
||||
|
||||
if (!result.IsFirstHandler)
|
||||
return;
|
||||
|
||||
await result.ConfirmAction();
|
||||
|
||||
//Find clicked button depending on Text or Value (depending on markup type)
|
||||
@ -247,6 +251,14 @@ namespace TelegramBotBase.Controls
|
||||
|
||||
}
|
||||
|
||||
public override async Task Hidden(bool FormClose)
|
||||
{
|
||||
//Prepare for opening Modal, and comming back
|
||||
if (!FormClose)
|
||||
{
|
||||
this.Updated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tells the control that it has been updated.
|
||||
@ -256,21 +268,35 @@ namespace TelegramBotBase.Controls
|
||||
this.RenderNecessary = true;
|
||||
}
|
||||
|
||||
|
||||
public async override Task Cleanup()
|
||||
{
|
||||
if (this.MessageId == null)
|
||||
return;
|
||||
|
||||
await this.Device.DeleteMessage(this.MessageId.Value);
|
||||
|
||||
this.MessageId = null;
|
||||
|
||||
if (this.KeyboardType == eKeyboardType.ReplyKeyboard && this.HideKeyboardOnCleanup)
|
||||
switch (this.KeyboardType)
|
||||
{
|
||||
await this.Device.HideReplyKeyboard();
|
||||
case eKeyboardType.InlineKeyBoard:
|
||||
|
||||
await this.Device.DeleteMessage(this.MessageId.Value);
|
||||
|
||||
this.MessageId = null;
|
||||
|
||||
break;
|
||||
case eKeyboardType.ReplyKeyboard:
|
||||
|
||||
if (this.HideKeyboardOnCleanup)
|
||||
{
|
||||
await this.Device.HideReplyKeyboard();
|
||||
}
|
||||
|
||||
this.MessageId = null;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user