From 2d5acbd1124c9bfc864b82824392c505f48e46f3 Mon Sep 17 00:00:00 2001 From: surdeus Date: Tue, 23 Jul 2024 18:08:39 +0500 Subject: [PATCH] fix: fixed the infinite call loop in WidgetGo.Serve . --- cmd/test/main.go | 4 ++++ cmd/test/start.go | 1 + context.go | 3 ++- go.go | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/test/main.go b/cmd/test/main.go index 5cf81e4..76663c7 100644 --- a/cmd/test/main.go +++ b/cmd/test/main.go @@ -19,6 +19,10 @@ func ExtractSessionData(c tg.Context) *SessionData { return c.SessionData().(*SessionData) } +var BackWidget = tg.RenderFunc(func(c tg.Context) tg.UI{ + return c.GoRet(tg.Back) +}) + var beh = tg.NewBehaviour().SetInit(tg.Func(func(c tg.Context) { // The session initialization. c.SetSessionData(&SessionData{}) diff --git a/cmd/test/start.go b/cmd/test/start.go index 6403f5b..367a15f 100644 --- a/cmd/test/start.go +++ b/cmd/test/start.go @@ -24,6 +24,7 @@ var StartWidget = tg.RenderFunc(func(c tg.Context) tg.UI { tg.Messagef("Choose your interest").Reply( tg.NewKeyboard().List( + tg.Buttonf("Back").Go(BackWidget), tg.Buttonf("Inc/Dec").Go(IncDecWidget), tg.Buttonf("Mutate messages").Go(MutateMessagesWidget), tg.Buttonf("Send location").Go(LocationWidget), diff --git a/context.go b/context.go index cdf42f1..6a8c423 100644 --- a/context.go +++ b/context.go @@ -6,6 +6,7 @@ import ( "net/http" tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" //"path" + //"log" ) @@ -316,7 +317,7 @@ func (c Context) Go(pth Widget) error { var back bool if pth == Back { - if len(c.session.pathHistory) < 2 { + if len(c.session.pathHistory) <= 1 { return c.Go(nil) } pth = c.session.pathHistory[len(c.session.pathHistory)-2] diff --git a/go.go b/go.go index c2354a4..b18e459 100644 --- a/go.go +++ b/go.go @@ -21,7 +21,7 @@ func (w WidgetGo) Act(c Context) { // Implementing the Server interface. func (widget WidgetGo) Serve(c Context) { c.input.Close() - c.Go(widget) + c.WithArg(widget.Path).Go(widget.Path) } func (widget WidgetGo) Render(c Context) UI {