-adding HideKeyboardOnCleanup and DeletePreviousMessage on ButtonGrid Control
This commit is contained in:
parent
5b38f2e1e2
commit
1561c1dd08
@ -37,6 +37,10 @@ namespace TelegramBotBase.Controls
|
|||||||
|
|
||||||
public bool OneTimeKeyboard { get; set; } = false;
|
public bool OneTimeKeyboard { get; set; } = false;
|
||||||
|
|
||||||
|
public bool HideKeyboardOnCleanup { get; set; } = true;
|
||||||
|
|
||||||
|
public bool DeletePreviousMessage { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines which type of Button Keyboard should be rendered.
|
/// Defines which type of Button Keyboard should be rendered.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -72,6 +76,12 @@ namespace TelegramBotBase.Controls
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ButtonGrid(eKeyboardType type) : this()
|
||||||
|
{
|
||||||
|
m_eKeyboardType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ButtonGrid(ButtonForm form)
|
public ButtonGrid(ButtonForm form)
|
||||||
{
|
{
|
||||||
this.ButtonsForm = form;
|
this.ButtonsForm = form;
|
||||||
@ -101,13 +111,17 @@ namespace TelegramBotBase.Controls
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
var button = ButtonsForm.ToList().FirstOrDefault(a => a.Text == result.MessageText);
|
var button = ButtonsForm.ToList().FirstOrDefault(a => a.Text.Trim() == result.MessageText);
|
||||||
|
|
||||||
if (button == null)
|
if (button == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OnButtonClicked(new ButtonClickedEventArgs(button));
|
OnButtonClicked(new ButtonClickedEventArgs(button));
|
||||||
|
|
||||||
|
//Remove button click message
|
||||||
|
if (this.DeletePreviousMessage)
|
||||||
|
await Device.DeleteMessage(result.MessageId);
|
||||||
|
|
||||||
result.Handled = true;
|
result.Handled = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -170,6 +184,7 @@ namespace TelegramBotBase.Controls
|
|||||||
{
|
{
|
||||||
throw new MaximumColsException() { Value = ButtonsForm.Rows, Maximum = 12 };
|
throw new MaximumColsException() { Value = ButtonsForm.Rows, Maximum = 12 };
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +202,9 @@ namespace TelegramBotBase.Controls
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (this.DeletePreviousMessage)
|
||||||
|
await this.Device.DeleteMessage(this.MessageId.Value);
|
||||||
|
|
||||||
var rkm = (ReplyKeyboardMarkup)this.ButtonsForm;
|
var rkm = (ReplyKeyboardMarkup)this.ButtonsForm;
|
||||||
rkm.ResizeKeyboard = this.ResizeKeyboard;
|
rkm.ResizeKeyboard = this.ResizeKeyboard;
|
||||||
rkm.OneTimeKeyboard = this.OneTimeKeyboard;
|
rkm.OneTimeKeyboard = this.OneTimeKeyboard;
|
||||||
@ -229,6 +247,15 @@ namespace TelegramBotBase.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tells the control that it has been updated.
|
||||||
|
/// </summary>
|
||||||
|
public void Updated()
|
||||||
|
{
|
||||||
|
this.RenderNecessary = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public async override Task Cleanup()
|
public async override Task Cleanup()
|
||||||
{
|
{
|
||||||
if (this.MessageId == null)
|
if (this.MessageId == null)
|
||||||
@ -238,9 +265,9 @@ namespace TelegramBotBase.Controls
|
|||||||
|
|
||||||
this.MessageId = null;
|
this.MessageId = null;
|
||||||
|
|
||||||
if (this.KeyboardType == eKeyboardType.ReplyKeyboard)
|
if (this.KeyboardType == eKeyboardType.ReplyKeyboard && this.HideKeyboardOnCleanup)
|
||||||
{
|
{
|
||||||
await this.Device.HideReplyKeyboard(autoDeleteResponse: false);
|
await this.Device.HideReplyKeyboard();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user