From ff352d76478a5635fbda5f319dee009e4fe60400 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 2 Nov 2022 18:36:26 +0400 Subject: [PATCH] Fix password request box closing in bot button callback. --- Telegram/SourceFiles/api/api_bot.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/api/api_bot.cpp b/Telegram/SourceFiles/api/api_bot.cpp index b6a24afad..d961063ed 100644 --- a/Telegram/SourceFiles/api/api_bot.cpp +++ b/Telegram/SourceFiles/api/api_bot.cpp @@ -45,6 +45,7 @@ void SendBotCallbackData( int row, int column, std::optional password, + Fn done = nullptr, Fn handleError = nullptr) { if (!item->isRegular()) { return; @@ -92,6 +93,11 @@ void SendBotCallbackData( MTP_bytes(sendData), password ? password->result : MTP_inputCheckPasswordEmpty() )).done([=](const MTPmessages_BotCallbackAnswer &result) { + const auto guard = gsl::finally([&] { + if (done) { + done(); + } + }); const auto item = owner->message(fullId); if (!item) { return; @@ -139,6 +145,11 @@ void SendBotCallbackData( show->hideLayer(); } }).fail([=](const MTP::Error &error) { + const auto guard = gsl::finally([&] { + if (handleError) { + handleError(error.type()); + } + }); const auto item = owner->message(fullId); if (!item) { return; @@ -148,9 +159,6 @@ void SendBotCallbackData( button->requestId = 0; owner->requestItemRepaint(item); } - if (handleError) { - handleError(error.type()); - } }).send(); session->changes().messageUpdated( @@ -204,7 +212,8 @@ void SendBotCallbackDataWithPassword( api->cloudPassword().reload(); const auto weak = base::make_weak(controller); const auto show = std::make_shared(controller); - SendBotCallbackData(controller, item, row, column, std::nullopt, [=](const QString &error) { + SendBotCallbackData(controller, item, row, column, {}, {}, [=]( + const QString &error) { auto box = PrePasswordErrorBox( error, session, @@ -250,7 +259,11 @@ void SendBotCallbackDataWithPassword( if (!strongController) { return; } - SendBotCallbackData(strongController, item, row, column, result, [=](const QString &error) { + SendBotCallbackData(strongController, item, row, column, result, [=] { + if (*box) { + (*box)->closeBox(); + } + }, [=](const QString &error) { if (*box) { (*box)->handleCustomCheckError(error); }