[Improvement] Query parameter for tg://resolve links

This commit is contained in:
Eric Kotato 2022-09-11 06:19:58 +03:00 committed by Eric Kotato
parent a00aa9a032
commit 5862f16ce7
2 changed files with 36 additions and 4 deletions

View file

@ -338,6 +338,12 @@ bool ResolveUsernameOrPhone(
if (domain == qsl("telegrampassport")) {
return ShowPassportForm(controller, params);
} else if (!validDomain(domain) && !validPhone(phone)) {
const auto searchParam = params.value(qsl("query"));
if (!searchParam.isEmpty()) {
controller->content()->searchMessages(
searchParam + ' ',
Dialogs::Key());
}
return false;
}
using ResolveType = Window::ResolveType;
@ -403,6 +409,7 @@ bool ResolveUsernameOrPhone(
? std::make_optional(params.value(u"voicechat"_q))
: std::nullopt),
.clickFromMessageId = myContext.itemId,
.searchQuery = params.value(qsl("query")),
});
controller->window().activate();
return true;

View file

@ -372,6 +372,16 @@ void SessionNavigation::showPeerByLinkResolved(
const auto user = peer->asUser();
const auto bot = (user && user->isBot()) ? user : nullptr;
const auto &replies = info.repliesInfo;
const auto searchQuery = info.searchQuery;
const auto applySearchQuery = [=] {
parentController()->content()->searchMessages(
searchQuery + ' ',
(peer && !peer->isUser())
? peer->owner().history(peer).get()
: Dialogs::Key());
};
if (const auto threadId = std::get_if<ThreadId>(&replies)) {
showRepliesForMessage(
session().data().history(peer),
@ -407,6 +417,14 @@ void SessionNavigation::showPeerByLinkResolved(
if (bot || peer->isChannel()) {
crl::on_main(this, [=] {
showPeerHistory(peer->id, params);
if (!searchQuery.isEmpty()) {
applySearchQuery();
}
});
} else if (!searchQuery.isEmpty()) {
crl::on_main(this, [=] {
showPeerHistory(peer->id, params);
applySearchQuery();
});
} else {
showPeerInfo(peer, params);
@ -428,10 +446,14 @@ void SessionNavigation::showPeerByLinkResolved(
if (!attachBotUsername.isEmpty()) {
crl::on_main(this, [=] {
showPeerHistory(peer->id, params, msgId);
peer->session().attachWebView().request(
peer,
attachBotUsername,
info.attachBotToggleCommand.value_or(QString()));
if (searchQuery.isEmpty()) {
peer->session().attachWebView().request(
peer,
attachBotUsername,
info.attachBotToggleCommand.value_or(QString()));
} else {
applySearchQuery();
}
});
} else if (bot && info.attachBotToggleCommand) {
const auto itemId = info.clickFromMessageId;
@ -451,6 +473,9 @@ void SessionNavigation::showPeerByLinkResolved(
} else {
crl::on_main(this, [=] {
showPeerHistory(peer->id, params, msgId);
if (!searchQuery.isEmpty()) {
applySearchQuery();
}
});
}
}