EdJoPaTo / grammy-inline-menu

Inline Menus for Telegram made simple. Successor of telegraf-inline-menu.
MIT License
357 stars 44 forks source link

loosing ctx.match data in 'hide' function of submenu #108

Closed eedea closed 4 years ago

eedea commented 4 years ago

Hi there, first of all thanks for your great work, I have a dynamic menu which has a submenu in it, I'm using some data based on content of ctx.match to show/hide this submenu. something like this:

A | B | C |__ D

in which both button 'B' and submenu 'C' have exact same 'hide' function. 'B' is ok and showing/hiding of 'C' button is works fine as well, but when I tap on it to open it, the 'hide' function runs again and this time ctx.match is 'undefined' so I end up with a fatal error. P.S: I temporary disabled the ctx.match related codes in that function to open the menu and ctx.match is correctly available in button 'D'; so it's only related to that second (unneccery) run of 'hide' function! P.P.S: I'm using V4.0.1

eedea commented 4 years ago

I was checking things and find out 'It' (hide function of C menu in above example) is running when I tap at 'D' button, whether 'setParentMenuAfter' of it is true or false!

EdJoPaTo commented 4 years ago

When checking the hide function on displaying buttons it happened based on button clicks. Then the ctx.callbackQuery is available which is used to generate the ctx.match. When the hide menu is called for a potential submenu the problem with version 4 was that it could be any middleware, not just a callbackQuery. As only callbackQueries have the data (and thus the ctx.match) it could not be said generally there. (menu.question for example used a general middleware) Once you end up in a button its a callbackQuery related thing again, not a general middleware so ctx.match is available again there.

Version 5 removed this "could be a general middleware" case as everything is now a callbackQuery. Due to this the hide function always has also a ctx.match in version 5.

Im not sure regarding the setParentMenuAfter and calls of a different hide function. But as this was reworked with version 5 it is differently anyway now.

EdJoPaTo commented 4 years ago

I'll just close this due to inactivity. If you have any questions feel free to ask ahead!