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 bool Handled { get; set; } = false;
|
||||||
|
|
||||||
public String RawData
|
public String RawData
|
||||||
|
|||||||
@ -8,6 +8,7 @@ using Telegram.Bot;
|
|||||||
using TelegramBotBase.Args;
|
using TelegramBotBase.Args;
|
||||||
using TelegramBotBase.Base;
|
using TelegramBotBase.Base;
|
||||||
using TelegramBotBase.Form;
|
using TelegramBotBase.Form;
|
||||||
|
using TelegramBotBase.Interfaces;
|
||||||
using TelegramBotBase.Sessions;
|
using TelegramBotBase.Sessions;
|
||||||
|
|
||||||
namespace TelegramBotBase
|
namespace TelegramBotBase
|
||||||
@ -170,6 +171,7 @@ namespace TelegramBotBase
|
|||||||
this.Client.TelegramClient.StartReceiving();
|
this.Client.TelegramClient.StartReceiving();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stop your Bot
|
/// Stop your Bot
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -212,7 +214,7 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
if (LogAllMessages)
|
if (LogAllMessages)
|
||||||
{
|
{
|
||||||
OnMessage(new MessageIncomeResult(e.DeviceId, ds, e));
|
OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message));
|
ds?.OnMessageReceived(new MessageReceivedEventArgs(e.Message));
|
||||||
@ -240,7 +242,7 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
ds.LastMessage = e.Message;
|
ds.LastMessage = e.Message;
|
||||||
|
|
||||||
OnSessionBegins(new SessionBeginResult(e.DeviceId, ds));
|
OnSessionBegins(new SessionBeginEventArgs(e.DeviceId, ds));
|
||||||
}
|
}
|
||||||
|
|
||||||
ds.LastAction = DateTime.Now;
|
ds.LastAction = DateTime.Now;
|
||||||
@ -289,15 +291,16 @@ namespace TelegramBotBase
|
|||||||
//Render Event
|
//Render Event
|
||||||
if (!ds.FormSwitched)
|
if (!ds.FormSwitched)
|
||||||
{
|
{
|
||||||
|
|
||||||
await activeForm.RenderControls(e);
|
await activeForm.RenderControls(e);
|
||||||
|
|
||||||
await activeForm.Render(e);
|
await activeForm.Render(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.IsFirstHandler = false;
|
||||||
|
|
||||||
} while (ds.FormSwitched && i < NavigationMaximum);
|
} while (ds.FormSwitched && i < NavigationMaximum);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Client_Action(object sender, MessageResult e)
|
private void Client_Action(object sender, MessageResult e)
|
||||||
@ -309,7 +312,7 @@ namespace TelegramBotBase
|
|||||||
|
|
||||||
if (LogAllMessages)
|
if (LogAllMessages)
|
||||||
{
|
{
|
||||||
OnMessage(new MessageIncomeResult(e.DeviceId, ds, e));
|
OnMessage(new MessageIncomeEventArgs(e.DeviceId, ds, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
Client_TryAction(sender, e);
|
Client_TryAction(sender, e);
|
||||||
@ -394,6 +397,8 @@ namespace TelegramBotBase
|
|||||||
await activeForm.Render(e);
|
await activeForm.Render(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
e.IsFirstHandler = false;
|
||||||
|
|
||||||
} while (ds.FormSwitched && i < NavigationMaximum);
|
} while (ds.FormSwitched && i < NavigationMaximum);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -402,7 +407,7 @@ namespace TelegramBotBase
|
|||||||
/// Will be called if a session/context gets started
|
/// Will be called if a session/context gets started
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
public event EventHandler<SessionBeginResult> SessionBegins
|
public event EventHandler<SessionBeginEventArgs> SessionBegins
|
||||||
{
|
{
|
||||||
add
|
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>
|
/// <summary>
|
||||||
/// Will be called on incomming message
|
/// Will be called on incomming message
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler<MessageIncomeResult> Message
|
public event EventHandler<MessageIncomeEventArgs> Message
|
||||||
{
|
{
|
||||||
add
|
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
|
get
|
||||||
{
|
{
|
||||||
|
|
||||||
return m_eKeyboardType;
|
return m_eKeyboardType;
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
@ -111,6 +110,8 @@ namespace TelegramBotBase.Controls
|
|||||||
if (this.KeyboardType != eKeyboardType.ReplyKeyboard)
|
if (this.KeyboardType != eKeyboardType.ReplyKeyboard)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!result.IsFirstHandler)
|
||||||
|
return;
|
||||||
|
|
||||||
var button = ButtonsForm.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText);
|
var button = ButtonsForm.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText);
|
||||||
|
|
||||||
@ -132,6 +133,9 @@ namespace TelegramBotBase.Controls
|
|||||||
if (result.Handled)
|
if (result.Handled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!result.IsFirstHandler)
|
||||||
|
return;
|
||||||
|
|
||||||
await result.ConfirmAction();
|
await result.ConfirmAction();
|
||||||
|
|
||||||
//Find clicked button depending on Text or Value (depending on markup type)
|
//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>
|
/// <summary>
|
||||||
/// Tells the control that it has been updated.
|
/// Tells the control that it has been updated.
|
||||||
@ -256,21 +268,35 @@ namespace TelegramBotBase.Controls
|
|||||||
this.RenderNecessary = true;
|
this.RenderNecessary = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async override Task Cleanup()
|
public async override Task Cleanup()
|
||||||
{
|
{
|
||||||
if (this.MessageId == null)
|
if (this.MessageId == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
switch (this.KeyboardType)
|
||||||
|
{
|
||||||
|
case eKeyboardType.InlineKeyBoard:
|
||||||
|
|
||||||
await this.Device.DeleteMessage(this.MessageId.Value);
|
await this.Device.DeleteMessage(this.MessageId.Value);
|
||||||
|
|
||||||
this.MessageId = null;
|
this.MessageId = null;
|
||||||
|
|
||||||
if (this.KeyboardType == eKeyboardType.ReplyKeyboard && this.HideKeyboardOnCleanup)
|
break;
|
||||||
|
case eKeyboardType.ReplyKeyboard:
|
||||||
|
|
||||||
|
if (this.HideKeyboardOnCleanup)
|
||||||
{
|
{
|
||||||
await this.Device.HideReplyKeyboard();
|
await this.Device.HideReplyKeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.MessageId = null;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user