mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix webview switch_inline to the same chat.
This commit is contained in:
parent
05ffc79539
commit
de9a757e7a
6 changed files with 40 additions and 50 deletions
|
@ -456,14 +456,12 @@ void ActivateBotCommand(ClickHandlerContext context, int row, int column) {
|
||||||
return false;
|
return false;
|
||||||
}();
|
}();
|
||||||
if (!fastSwitchDone) {
|
if (!fastSwitchDone) {
|
||||||
const auto botAndQuery = '@'
|
const auto query = QString::fromUtf8(button->data);
|
||||||
+ bot->username()
|
|
||||||
+ ' '
|
|
||||||
+ QString::fromUtf8(button->data);
|
|
||||||
const auto chosen = [=](not_null<Data::Thread*> thread) {
|
const auto chosen = [=](not_null<Data::Thread*> thread) {
|
||||||
return controller->content()->inlineSwitchChosen(
|
return controller->switchInlineQuery(
|
||||||
thread,
|
thread,
|
||||||
botAndQuery);
|
bot,
|
||||||
|
query);
|
||||||
};
|
};
|
||||||
Window::ShowChooseRecipientBox(
|
Window::ShowChooseRecipientBox(
|
||||||
controller,
|
controller,
|
||||||
|
|
|
@ -1043,14 +1043,9 @@ void AttachWebView::show(
|
||||||
query);
|
query);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const auto botAndQuery = '@'
|
const auto bot = _bot;
|
||||||
+ _bot->username()
|
|
||||||
+ ' '
|
|
||||||
+ query;
|
|
||||||
const auto done = [=](not_null<Data::Thread*> thread) {
|
const auto done = [=](not_null<Data::Thread*> thread) {
|
||||||
return controller->content()->inlineSwitchChosen(
|
controller->switchInlineQuery(thread, bot, query);
|
||||||
thread,
|
|
||||||
botAndQuery);
|
|
||||||
};
|
};
|
||||||
ShowChooseBox(
|
ShowChooseBox(
|
||||||
controller,
|
controller,
|
||||||
|
|
|
@ -354,7 +354,12 @@ MainWidget::MainWidget(
|
||||||
session().changes().entryUpdates(
|
session().changes().entryUpdates(
|
||||||
Data::EntryUpdate::Flag::LocalDraftSet
|
Data::EntryUpdate::Flag::LocalDraftSet
|
||||||
) | rpl::start_with_next([=](const Data::EntryUpdate &update) {
|
) | 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();
|
controller->hideLayer();
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
@ -609,37 +614,6 @@ bool MainWidget::shareUrl(
|
||||||
return true;
|
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(
|
bool MainWidget::sendPaths(
|
||||||
not_null<Data::Thread*> thread,
|
not_null<Data::Thread*> thread,
|
||||||
const QStringList &paths) {
|
const QStringList &paths) {
|
||||||
|
|
|
@ -186,9 +186,6 @@ public:
|
||||||
bool filesOrForwardDrop(
|
bool filesOrForwardDrop(
|
||||||
not_null<Data::Thread*> thread,
|
not_null<Data::Thread*> thread,
|
||||||
not_null<const QMimeData*> data);
|
not_null<const QMimeData*> data);
|
||||||
bool inlineSwitchChosen(
|
|
||||||
not_null<Data::Thread*> thread,
|
|
||||||
const QString &botAndQuery) const;
|
|
||||||
|
|
||||||
void sendBotCommand(Bot::SendCommandRequest request);
|
void sendBotCommand(Bot::SendCommandRequest request);
|
||||||
void hideSingleUseKeyboard(PeerData *peer, MsgId replyTo);
|
void hideSingleUseKeyboard(PeerData *peer, MsgId replyTo);
|
||||||
|
|
|
@ -1184,7 +1184,7 @@ Dialogs::EntryState SessionController::currentDialogsEntryState() const {
|
||||||
return _currentDialogsEntryState;
|
return _currentDialogsEntryState;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionController::switchInlineQuery(
|
bool SessionController::switchInlineQuery(
|
||||||
Dialogs::EntryState to,
|
Dialogs::EntryState to,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
const QString &query) {
|
const QString &query) {
|
||||||
|
@ -1192,6 +1192,12 @@ void SessionController::switchInlineQuery(
|
||||||
|
|
||||||
using Section = Dialogs::EntryState::Section;
|
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 history = to.key.owningHistory();
|
||||||
const auto textWithTags = TextWithTags{
|
const auto textWithTags = TextWithTags{
|
||||||
'@' + bot->username() + ' ' + query,
|
'@' + bot->username() + ' ' + query,
|
||||||
|
@ -1214,6 +1220,7 @@ void SessionController::switchInlineQuery(
|
||||||
params);
|
params);
|
||||||
} else {
|
} else {
|
||||||
history->setLocalDraft(std::move(draft));
|
history->setLocalDraft(std::move(draft));
|
||||||
|
history->clearLocalEditDraft(to.rootId);
|
||||||
if (to.section == Section::Replies) {
|
if (to.section == Section::Replies) {
|
||||||
const auto commentId = MsgId();
|
const auto commentId = MsgId();
|
||||||
showRepliesForMessage(history, to.rootId, commentId, params);
|
showRepliesForMessage(history, to.rootId, commentId, params);
|
||||||
|
@ -1221,6 +1228,21 @@ void SessionController::switchInlineQuery(
|
||||||
showPeerHistory(history->peer, params);
|
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(
|
Dialogs::RowDescriptor SessionController::resolveChatNext(
|
||||||
|
|
|
@ -379,10 +379,14 @@ public:
|
||||||
|
|
||||||
void setCurrentDialogsEntryState(Dialogs::EntryState state);
|
void setCurrentDialogsEntryState(Dialogs::EntryState state);
|
||||||
[[nodiscard]] Dialogs::EntryState currentDialogsEntryState() const;
|
[[nodiscard]] Dialogs::EntryState currentDialogsEntryState() const;
|
||||||
void switchInlineQuery(
|
bool switchInlineQuery(
|
||||||
Dialogs::EntryState to,
|
Dialogs::EntryState to,
|
||||||
not_null<UserData*> bot,
|
not_null<UserData*> bot,
|
||||||
const QString &query);
|
const QString &query);
|
||||||
|
bool switchInlineQuery(
|
||||||
|
not_null<Data::Thread*> thread,
|
||||||
|
not_null<UserData*> bot,
|
||||||
|
const QString &query);
|
||||||
|
|
||||||
[[nodiscard]] Dialogs::RowDescriptor resolveChatNext(
|
[[nodiscard]] Dialogs::RowDescriptor resolveChatNext(
|
||||||
Dialogs::RowDescriptor from = {}) const;
|
Dialogs::RowDescriptor from = {}) const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue