Fix switch_inline_query with same_peer in topics.

Fixes #27290.
This commit is contained in:
John Preston 2024-11-21 11:41:46 +04:00
parent 9532a2e3da
commit e3d9216b10
2 changed files with 14 additions and 22 deletions

View file

@ -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<Data::Draft>(
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();
}

View file

@ -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<Data::Draft>(
textWithTags,
to.currentReplyTo,