From d43a6da62bb77a4b47445f99d6c9563b4e78ea2f Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 5 Mar 2025 18:02:40 +0400 Subject: [PATCH] Fix sending bot commands in paid chats. --- .../SourceFiles/history/history_widget.cpp | 23 +++++++++++++++++-- Telegram/SourceFiles/history/history_widget.h | 4 ++++ .../view/history_view_replies_section.cpp | 22 +++++++++++++++++- .../view/history_view_replies_section.h | 5 ++++ 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 459b3951c..76353c79f 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -4917,13 +4917,32 @@ void HistoryWidget::mouseReleaseEvent(QMouseEvent *e) { } void HistoryWidget::sendBotCommand(const Bot::SendCommandRequest &request) { -// replyTo != 0 from ReplyKeyboardMarkup, == 0 from command links + sendBotCommand(request, {}); +} + +void HistoryWidget::sendBotCommand( + const Bot::SendCommandRequest &request, + Api::SendOptions options) { + // replyTo != 0 from ReplyKeyboardMarkup, == 0 from command links if (_peer != request.peer.get()) { return; } else if (showSlowmodeError()) { return; } + const auto withPaymentApproved = [=](int approved) { + auto copy = options; + copy.starsApproved = approved; + sendBotCommand(request, copy); + }; + const auto checked = checkSendPayment( + 1, + options.starsApproved, + withPaymentApproved); + if (!checked) { + return; + } + const auto forMsgId = _keyboard->forMsgId(); const auto lastKeyboardUsed = (forMsgId == request.replyTo.messageId) && (forMsgId == FullMsgId(_peer->id, _history->lastKeyboardId)); @@ -4933,7 +4952,7 @@ void HistoryWidget::sendBotCommand(const Bot::SendCommandRequest &request) { ? request.command : Bot::WrapCommandInChat(_peer, request.command, request.context); - auto message = Api::MessageToSend(prepareSendAction({})); + auto message = Api::MessageToSend(prepareSendAction(options)); message.textWithTags = { toSend, TextWithTags::Tags() }; message.action.replyTo = request.replyTo ? ((!_peer->isUser()/* && (botStatus == 0 || botStatus == 2)*/) diff --git a/Telegram/SourceFiles/history/history_widget.h b/Telegram/SourceFiles/history/history_widget.h index e8dbd4f8c..1b0a818bf 100644 --- a/Telegram/SourceFiles/history/history_widget.h +++ b/Telegram/SourceFiles/history/history_widget.h @@ -491,6 +491,10 @@ private: std::shared_ptr bundle, Api::SendOptions options); + void sendBotCommand( + const Bot::SendCommandRequest &request, + Api::SendOptions options); + void uploadFile(const QByteArray &fileContent, SendMediaType type); void itemRemoved(not_null item); diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp index 88f2b44a5..dfd94af4f 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.cpp @@ -2724,11 +2724,31 @@ bool RepliesWidget::listIsGoodForAroundPosition( void RepliesWidget::listSendBotCommand( const QString &command, const FullMsgId &context) { + sendBotCommandWithOptions(command, context, {}); +} + +void RepliesWidget::sendBotCommandWithOptions( + const QString &command, + const FullMsgId &context, + Api::SendOptions options) { + const auto withPaymentApproved = [=](int approved) { + auto copy = options; + copy.starsApproved = approved; + sendBotCommandWithOptions(command, context, copy); + }; + const auto checked = checkSendPayment( + 1, + options.starsApproved, + withPaymentApproved); + if (!checked) { + return; + } + const auto text = Bot::WrapCommandInChat( _history->peer, command, context); - auto message = Api::MessageToSend(prepareSendAction({})); + auto message = Api::MessageToSend(prepareSendAction(options)); message.textWithTags = { text }; session().api().sendMessage(std::move(message)); finishSending(); diff --git a/Telegram/SourceFiles/history/view/history_view_replies_section.h b/Telegram/SourceFiles/history/view/history_view_replies_section.h index d03f5c834..5d7758b7f 100644 --- a/Telegram/SourceFiles/history/view/history_view_replies_section.h +++ b/Telegram/SourceFiles/history/view/history_view_replies_section.h @@ -319,6 +319,11 @@ private: std::shared_ptr bundle, Api::SendOptions options); + void sendBotCommandWithOptions( + const QString &command, + const FullMsgId &context, + Api::SendOptions options); + bool sendExistingDocument( not_null document, Api::MessageToSend messageToSend,