From 138199e8114e55cafeefefe57afd4e6153412574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexei=20Ag=C3=BCero=20Alba?= Date: Mon, 5 Dec 2022 17:12:53 -0500 Subject: [PATCH 1/3] Correctly implement Dispose pattern in FormBase for use on derived classes --- TelegramBotBase/Base/FormBase.cs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/TelegramBotBase/Base/FormBase.cs b/TelegramBotBase/Base/FormBase.cs index 291e733..d3c2cba 100644 --- a/TelegramBotBase/Base/FormBase.cs +++ b/TelegramBotBase/Base/FormBase.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; -using System.Text; using System.Threading.Tasks; using TelegramBotBase.Args; using TelegramBotBase.Base; @@ -17,7 +16,6 @@ namespace TelegramBotBase.Form /// public class FormBase : IDisposable { - public NavigationController NavigationController { get; set; } public DeviceSession Device { get; set; } @@ -432,14 +430,29 @@ namespace TelegramBotBase.Form } } + protected virtual void Dispose(bool disposing) + { + if (this.IsDisposed) + { + return; + } + + if (disposing) + { + this.Client = null; + this.Device = null; + } + + this.IsDisposed = true; + } + /// /// Cleanup /// public void Dispose() { - this.Client = null; - this.Device = null; - this.IsDisposed = true; + Dispose(true); + GC.SuppressFinalize(this); } } } From 6343a8a719b094cf188df736d7e33c1fcf273bf4 Mon Sep 17 00:00:00 2001 From: Palash Jhabak Date: Sat, 21 Jan 2023 09:47:28 +0530 Subject: [PATCH 2/3] Add Web App Inline Keyboard Button --- TelegramBotBase/Form/WebAppButtonBase.cs | 48 ++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 TelegramBotBase/Form/WebAppButtonBase.cs diff --git a/TelegramBotBase/Form/WebAppButtonBase.cs b/TelegramBotBase/Form/WebAppButtonBase.cs new file mode 100644 index 0000000..7bd0de1 --- /dev/null +++ b/TelegramBotBase/Form/WebAppButtonBase.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Telegram.Bot.Types; +using Telegram.Bot.Types.ReplyMarkups; + +namespace TelegramBotBase.Form +{ + public class WebAppButtonBase : ButtonBase + { + public WebAppInfo WebAppInfo { get; set; } + + public WebAppButtonBase() + { + + } + + public WebAppButtonBase(String Text, WebAppInfo WebAppInfo) + { + this.Text = Text; + this.WebAppInfo = WebAppInfo; + } + + /// + /// Returns an inline Button + /// + /// + /// + public override InlineKeyboardButton ToInlineButton(ButtonForm form) + { + return InlineKeyboardButton.WithWebApp(this.Text, this.WebAppInfo); + } + + + /// + /// Returns a KeyBoardButton + /// + /// + /// + public override KeyboardButton ToKeyboardButton(ButtonForm form) + { + return KeyboardButton.WithWebApp(this.Text, this.WebAppInfo); + } + + } +} From c0e67d626242ee9a2011fe32e7b349df1243ef1e Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Fri, 27 Jan 2023 20:11:45 +0100 Subject: [PATCH 3/3] Fixing AutoCleanForm and NavigationController - AutoCleanForm does not work properly inside a NavigationController (Some messages wont get deleted) --- TelegramBotBase/Form/Navigation/NavigationController.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TelegramBotBase/Form/Navigation/NavigationController.cs b/TelegramBotBase/Form/Navigation/NavigationController.cs index d1858b9..3f4c927 100644 --- a/TelegramBotBase/Form/Navigation/NavigationController.cs +++ b/TelegramBotBase/Form/Navigation/NavigationController.cs @@ -134,6 +134,9 @@ namespace TelegramBotBase.Form.Navigation /// public virtual async Task PushAsync(FormBase form, params object[] args) { + //Leave current form (needed for AutoCleanForm to work properly) + await CurrentForm.OnClosed(new EventArgs()); + form.Client = this.Client; form.Device = this.Device; form.NavigationController = this;