From dcc8a64d37262ee4cd742be1d5d438a407c8c703 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 27 Jul 2021 02:45:01 +0300 Subject: [PATCH] Removed App::sendBotCommand. --- .../SourceFiles/chat_helpers/bot_keyboard.cpp | 2 +- Telegram/SourceFiles/facades.cpp | 25 ++++++++----------- Telegram/SourceFiles/facades.h | 18 +++---------- .../history/history_item_components.cpp | 8 ++++-- .../history/history_item_components.h | 5 ++-- 5 files changed, 23 insertions(+), 35 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp index 7f43c43cc..f6a59e656 100644 --- a/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp +++ b/Telegram/SourceFiles/chat_helpers/bot_keyboard.cpp @@ -192,7 +192,7 @@ bool BotKeyboard::moderateKeyActivate(int key) { if (!markup->rows.empty() && index >= 0 && index < int(markup->rows.front().size())) { - App::activateBotCommand(item, 0, index); + App::activateBotCommand(_controller, item, 0, index); return true; } } else if (const auto user = item->history()->peer->asUser()) { diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 0994844ac..9797bfcc9 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -58,15 +58,6 @@ namespace { namespace App { -void sendBotCommand( - not_null peer, - UserData *bot, - const QString &cmd, MsgId replyTo) { - if (const auto m = CheckMainWidget(&peer->session())) { - m->sendBotCommand({ peer, /*bot,*/ cmd, FullMsgId(), replyTo }); - } -} - void hideSingleUseKeyboard(not_null message) { if (const auto m = CheckMainWidget(&message->history()->session())) { m->hideSingleUseKeyboard(message->history()->peer, message->id); @@ -81,6 +72,7 @@ bool insertBotCommand(const QString &cmd) { } void activateBotCommand( + Window::SessionController *sessionController, not_null msg, int row, int column) { @@ -98,12 +90,15 @@ void activateBotCommand( case ButtonType::Default: { // Copy string before passing it to the sending method // because the original button can be destroyed inside. - MsgId replyTo = (msg->id > 0) ? msg->id : 0; - sendBotCommand( - msg->history()->peer, - msg->fromOriginal()->asUser(), - QString(button->text), - replyTo); + if (sessionController) { + MsgId replyTo = (msg->id > 0) ? msg->id : 0; + sessionController->content()->sendBotCommand({ + .peer = msg->history()->peer, + .command = QString(button->text), + .context = msg->fullId(), + .replyTo = replyTo, + }); + } } break; case ButtonType::Callback: diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index 72655e3c8..c4ce8f050 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -14,15 +14,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL class History; -namespace Data { -struct FileOrigin; -} // namespace Data - -namespace InlineBots { -namespace Layout { -class ItemBase; -} // namespace Layout -} // namespace InlineBots +namespace Window { +class SessionController; +} // namespace Window namespace App { @@ -37,13 +31,9 @@ template }; } -void sendBotCommand( - not_null peer, - UserData *bot, - const QString &cmd, - MsgId replyTo = 0); bool insertBotCommand(const QString &cmd); void activateBotCommand( + Window::SessionController *sessionController, not_null msg, int row, int column); diff --git a/Telegram/SourceFiles/history/history_item_components.cpp b/Telegram/SourceFiles/history/history_item_components.cpp index 6bd10b360..54b5bf6e4 100644 --- a/Telegram/SourceFiles/history/history_item_components.cpp +++ b/Telegram/SourceFiles/history/history_item_components.cpp @@ -447,9 +447,13 @@ auto ReplyMarkupClickHandler::getUrlButton() const return nullptr; } -void ReplyMarkupClickHandler::onClickImpl() const { +void ReplyMarkupClickHandler::onClick(ClickContext context) const { + if (context.button != Qt::LeftButton) { + return; + } if (const auto item = _owner->message(_itemId)) { - App::activateBotCommand(item, _row, _column); + const auto my = context.other.value(); + App::activateBotCommand(my.sessionWindow.get(), item, _row, _column); } } diff --git a/Telegram/SourceFiles/history/history_item_components.h b/Telegram/SourceFiles/history/history_item_components.h index d8076a189..7acae7c72 100644 --- a/Telegram/SourceFiles/history/history_item_components.h +++ b/Telegram/SourceFiles/history/history_item_components.h @@ -246,7 +246,7 @@ private: }; -class ReplyMarkupClickHandler : public LeftButtonClickHandler { +class ReplyMarkupClickHandler : public ClickHandler { public: ReplyMarkupClickHandler( not_null owner, @@ -278,8 +278,7 @@ public: _itemId = msgId; } -protected: - void onClickImpl() const override; + void onClick(ClickContext context) const override; private: const not_null _owner;