Skip to content

Commit

Permalink
Fix switch_inline_query with same_peer in topics.
Browse files Browse the repository at this point in the history
Fixes #27290.
  • Loading branch information
john-preston committed Nov 21, 2024
1 parent 9532a2e commit e3d9216
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
32 changes: 10 additions & 22 deletions Telegram/SourceFiles/history/history_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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({});
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions Telegram/SourceFiles/window/window_session_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e3d9216

Please sign in to comment.