diff --git a/Telegram/SourceFiles/api/api_bot.cpp b/Telegram/SourceFiles/api/api_bot.cpp index 72105bc9e..4c19b4c85 100644 --- a/Telegram/SourceFiles/api/api_bot.cpp +++ b/Telegram/SourceFiles/api/api_bot.cpp @@ -456,14 +456,12 @@ void ActivateBotCommand(ClickHandlerContext context, int row, int column) { return false; }(); if (!fastSwitchDone) { - const auto botAndQuery = '@' - + bot->username() - + ' ' - + QString::fromUtf8(button->data); + const auto query = QString::fromUtf8(button->data); const auto chosen = [=](not_null thread) { - return controller->content()->inlineSwitchChosen( + return controller->switchInlineQuery( thread, - botAndQuery); + bot, + query); }; Window::ShowChooseRecipientBox( controller, diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index a78d46567..30927307f 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -1043,14 +1043,9 @@ void AttachWebView::show( query); } } else { - const auto botAndQuery = '@' - + _bot->username() - + ' ' - + query; + const auto bot = _bot; const auto done = [=](not_null thread) { - return controller->content()->inlineSwitchChosen( - thread, - botAndQuery); + controller->switchInlineQuery(thread, bot, query); }; ShowChooseBox( controller, diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index e82289ce3..0ca07a17e 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -354,7 +354,12 @@ MainWidget::MainWidget( session().changes().entryUpdates( Data::EntryUpdate::Flag::LocalDraftSet ) | rpl::start_with_next([=](const Data::EntryUpdate &update) { - controller->showThread(update.entry->asThread(), ShowAtUnreadMsgId); + auto params = Window::SectionShow(); + params.reapplyLocalDraft = true; + controller->showThread( + update.entry->asThread(), + ShowAtUnreadMsgId, + params); controller->hideLayer(); }, lifetime()); @@ -609,37 +614,6 @@ bool MainWidget::shareUrl( return true; } -bool MainWidget::inlineSwitchChosen( - not_null thread, - const QString &botAndQuery) const { - if (!Data::CanSend(thread, ChatRestriction::SendInline)) { - _controller->show(Ui::MakeInformBox(tr::lng_inline_switch_cant())); - return false; - } - const auto textWithTags = TextWithTags{ - botAndQuery, - TextWithTags::Tags(), - }; - const auto cursor = MessageCursor{ - int(botAndQuery.size()), - int(botAndQuery.size()), - QFIXED_MAX - }; - const auto history = thread->owningHistory(); - const auto topicRootId = thread->topicRootId(); - history->setLocalDraft(std::make_unique( - textWithTags, - 0, // replyTo - topicRootId, - cursor, - Data::PreviewState::Allowed)); - history->clearLocalEditDraft(topicRootId); - thread->session().changes().entryUpdated( - thread, - Data::EntryUpdate::Flag::LocalDraftSet); - return true; -} - bool MainWidget::sendPaths( not_null thread, const QStringList &paths) { diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index 2dd9f3aa2..5fc904207 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -186,9 +186,6 @@ public: bool filesOrForwardDrop( not_null thread, not_null data); - bool inlineSwitchChosen( - not_null thread, - const QString &botAndQuery) const; void sendBotCommand(Bot::SendCommandRequest request); void hideSingleUseKeyboard(PeerData *peer, MsgId replyTo); diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index c95ab613d..3d8a1eeeb 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -1184,7 +1184,7 @@ Dialogs::EntryState SessionController::currentDialogsEntryState() const { return _currentDialogsEntryState; } -void SessionController::switchInlineQuery( +bool SessionController::switchInlineQuery( Dialogs::EntryState to, not_null bot, const QString &query) { @@ -1192,6 +1192,12 @@ void SessionController::switchInlineQuery( using Section = Dialogs::EntryState::Section; + const auto thread = to.key.thread(); + if (!thread || !Data::CanSend(thread, ChatRestriction::SendInline)) { + show(Ui::MakeInformBox(tr::lng_inline_switch_cant())); + return false; + } + const auto history = to.key.owningHistory(); const auto textWithTags = TextWithTags{ '@' + bot->username() + ' ' + query, @@ -1214,6 +1220,7 @@ void SessionController::switchInlineQuery( params); } else { history->setLocalDraft(std::move(draft)); + history->clearLocalEditDraft(to.rootId); if (to.section == Section::Replies) { const auto commentId = MsgId(); showRepliesForMessage(history, to.rootId, commentId, params); @@ -1221,6 +1228,21 @@ void SessionController::switchInlineQuery( showPeerHistory(history->peer, params); } } + return true; +} + +bool SessionController::switchInlineQuery( + not_null thread, + not_null bot, + const QString &query) { + const auto entryState = Dialogs::EntryState{ + .key = thread, + .section = (thread->asTopic() + ? Dialogs::EntryState::Section::Replies + : Dialogs::EntryState::Section::History), + .rootId = thread->topicRootId(), + }; + return switchInlineQuery(entryState, bot, query); } Dialogs::RowDescriptor SessionController::resolveChatNext( diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index 8014765f6..5500fddf0 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -379,10 +379,14 @@ public: void setCurrentDialogsEntryState(Dialogs::EntryState state); [[nodiscard]] Dialogs::EntryState currentDialogsEntryState() const; - void switchInlineQuery( + bool switchInlineQuery( Dialogs::EntryState to, not_null bot, const QString &query); + bool switchInlineQuery( + not_null thread, + not_null bot, + const QString &query); [[nodiscard]] Dialogs::RowDescriptor resolveChatNext( Dialogs::RowDescriptor from = {}) const;