From e3d9216b10ec21a445c6a185567e0b36dc431ebc Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 21 Nov 2024 11:41:46 +0400 Subject: [PATCH] Fix switch_inline_query with same_peer in topics. Fixes #27290. --- .../SourceFiles/history/history_widget.cpp | 32 ++++++------------- .../window/window_session_controller.cpp | 4 +++ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 33eec2d34..e9d097a27 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -1947,24 +1947,12 @@ bool HistoryWidget::notify_switchInlineBotButtonReceived( UserData *samePeerBot, MsgId samePeerReplyTo) { if (samePeerBot) { - if (_history) { - const auto textWithTags = TextWithTags{ - '@' + samePeerBot->username() + ' ' + query, - TextWithTags::Tags(), - }; - MessageCursor cursor = { - int(textWithTags.text.size()), - int(textWithTags.text.size()), - Ui::kQFixedMax, - }; - _history->setLocalDraft(std::make_unique( - textWithTags, - FullReplyTo(), - cursor, - Data::WebPageDraft())); - applyDraft(); - return true; + const auto to = controller()->currentDialogsEntryState(); + if (!to.key.owningHistory()) { + return false; } + controller()->switchInlineQuery(to, samePeerBot, query); + return true; } else if (const auto bot = _peer ? _peer->asUser() : nullptr) { const auto to = bot->isBot() ? bot->botInfo->inlineReturnTo @@ -2192,7 +2180,7 @@ void HistoryWidget::showHistory( _showAtMsgHighlightPart = {}; _showAtMsgHighlightPartOffsetHint = 0; - const auto wasDialogsEntryState = computeDialogsEntryState(); + const auto wasState = controller()->currentDialogsEntryState(); const auto startBot = (showAtMsgId == ShowAndStartBotMsgId); if (startBot) { showAtMsgId = ShowAtTheEndMsgId; @@ -2297,8 +2285,8 @@ void HistoryWidget::showHistory( if (const auto user = _peer->asUser()) { if (const auto &info = user->botInfo) { if (startBot) { - if (wasDialogsEntryState.key) { - info->inlineReturnTo = wasDialogsEntryState; + if (wasState.key) { + info->inlineReturnTo = wasState; } sendBotStartCommand(); _history->clearLocalDraft({}); @@ -2533,8 +2521,8 @@ void HistoryWidget::showHistory( if (const auto user = _peer->asUser()) { if (const auto &info = user->botInfo) { if (startBot) { - if (wasDialogsEntryState.key) { - info->inlineReturnTo = wasDialogsEntryState; + if (wasState.key) { + info->inlineReturnTo = wasState; } sendBotStartCommand(); } diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 912d663aa..afc99326b 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1866,6 +1866,10 @@ bool SessionController::switchInlineQuery( int(textWithTags.text.size()), Ui::kQFixedMax }; + if (to.currentReplyTo.messageId.msg == to.currentReplyTo.topicRootId + && to.currentReplyTo.quote.empty()) { + to.currentReplyTo.messageId.msg = MsgId(); + } auto draft = std::make_unique( textWithTags, to.currentReplyTo,