Skip to content

Commit

Permalink
fix(select): dont call hide without key
Browse files Browse the repository at this point in the history
dont use hide to determine if action can be triggered. The 
hitSelectButton does it by itself while checking for the specific key.
  • Loading branch information
EdJoPaTo committed Sep 16, 2018
1 parent a2c0ea5 commit c440a97
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 0 additions & 1 deletion inline-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ class TelegrafInlineMenu {
this.addHandler({
action: actionCodeBase.concat(/(.+)/),
middleware: hitSelectButton,
hide: additionalArgs.hide,
setMenuAfter: true
})

Expand Down
23 changes: 23 additions & 0 deletions test/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,26 @@ test('hidden key can not be set', async t => {

await bot.handleUpdate({callback_query: {data: 'a:b:c:a'}})
})

test('hide always has two args', async t => {
t.plan(2)
const menu = new TelegrafInlineMenu('foo')
menu.select('c', ['a', 'b'], {
setFunc: t.fail,
hide: (...args) => {
t.is(args.length, 2)
return false
}
})

const bot = new Telegraf()
bot.use(menu.init({actionCode: 'a:b'}))

bot.context.editMessageText = () => Promise.resolve()

// Calls hide for every option: +2
await bot.handleUpdate({callback_query: {data: 'a:b'}})

// Does not call hide
await bot.handleUpdate({callback_query: {data: 'c'}})
})

0 comments on commit c440a97

Please sign in to comment.