Fix webview switch_inline to the same chat.

This commit is contained in:
John Preston 2023-03-08 16:48:23 +04:00
parent 05ffc79539
commit de9a757e7a
6 changed files with 40 additions and 50 deletions

View File

@ -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<Data::Thread*> thread) {
return controller->content()->inlineSwitchChosen(
return controller->switchInlineQuery(
thread,
botAndQuery);
bot,
query);
};
Window::ShowChooseRecipientBox(
controller,

View File

@ -1043,14 +1043,9 @@ void AttachWebView::show(
query);
}
} else {
const auto botAndQuery = '@'
+ _bot->username()
+ ' '
+ query;
const auto bot = _bot;
const auto done = [=](not_null<Data::Thread*> thread) {
return controller->content()->inlineSwitchChosen(
thread,
botAndQuery);
controller->switchInlineQuery(thread, bot, query);
};
ShowChooseBox(
controller,

View File

@ -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<Data::Thread*> 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<Data::Draft>(
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<Data::Thread*> thread,
const QStringList &paths) {

View File

@ -186,9 +186,6 @@ public:
bool filesOrForwardDrop(
not_null<Data::Thread*> thread,
not_null<const QMimeData*> data);
bool inlineSwitchChosen(
not_null<Data::Thread*> thread,
const QString &botAndQuery) const;
void sendBotCommand(Bot::SendCommandRequest request);
void hideSingleUseKeyboard(PeerData *peer, MsgId replyTo);

View File

@ -1184,7 +1184,7 @@ Dialogs::EntryState SessionController::currentDialogsEntryState() const {
return _currentDialogsEntryState;
}
void SessionController::switchInlineQuery(
bool SessionController::switchInlineQuery(
Dialogs::EntryState to,
not_null<UserData*> 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<Data::Thread*> thread,
not_null<UserData*> 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(

View File

@ -379,10 +379,14 @@ public:
void setCurrentDialogsEntryState(Dialogs::EntryState state);
[[nodiscard]] Dialogs::EntryState currentDialogsEntryState() const;
void switchInlineQuery(
bool switchInlineQuery(
Dialogs::EntryState to,
not_null<UserData*> bot,
const QString &query);
bool switchInlineQuery(
not_null<Data::Thread*> thread,
not_null<UserData*> bot,
const QString &query);
[[nodiscard]] Dialogs::RowDescriptor resolveChatNext(
Dialogs::RowDescriptor from = {}) const;