2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Parameter query in tg://resolve links

This commit is contained in:
RadRussianRus
2020-04-19 21:10:31 +03:00
parent f2b5b36ad4
commit ae5f1638f6
3 changed files with 46 additions and 13 deletions

View File

@@ -34,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwidget.h"
#include "main/main_session.h"
#include "apiwrap.h"
#include "facades.h"
#include "app.h"
namespace Core {
@@ -257,6 +258,10 @@ bool ResolveUsername(
if (domain == qsl("telegrampassport")) {
return ShowPassportForm(params);
} else if (!valid(domain)) {
const auto searchParam = params.value(qsl("query"));
if (!searchParam.isEmpty()) {
App::searchByHashtag(searchParam, nullptr);
}
return false;
}
auto start = qsl("start");
@@ -281,11 +286,13 @@ bool ResolveUsername(
post = ShowAtGameShareMsgId;
}
const auto clickFromMessageId = context.value<FullMsgId>();
const auto searchParam = params.value(qsl("query"));
App::main()->openPeerByName(
domain,
post,
startToken,
clickFromMessageId);
clickFromMessageId,
searchParam);
return true;
}

View File

@@ -3256,7 +3256,8 @@ void MainWidget::openPeerByName(
const QString &username,
MsgId msgId,
const QString &startToken,
FullMsgId clickFromMessageId) {
FullMsgId clickFromMessageId,
const QString &searchQuery) {
Core::App().hideMediaView();
if (const auto peer = session().data().peerByUsername(username)) {
@@ -3267,10 +3268,13 @@ void MainWidget::openPeerByName(
_controller,
peer->asUser());
} else {
InvokeQueued(this, [this, peer] {
InvokeQueued(this, [this, peer, searchQuery] {
_controller->showPeerHistory(
peer->id,
SectionShow::Way::Forward);
if (!searchQuery.isEmpty()) {
App::searchByHashtag(searchQuery, peer);
}
});
}
} else if (msgId == ShowAtProfileMsgId && !peer->isChannel()) {
@@ -3281,13 +3285,20 @@ void MainWidget::openPeerByName(
peer->asUser());
} else if (peer->isUser() && peer->asUser()->isBot()) {
// Always open bot chats, even from mention links.
InvokeQueued(this, [this, peer] {
InvokeQueued(this, [this, peer, searchQuery] {
_controller->showPeerHistory(
peer->id,
SectionShow::Way::Forward);
if (!searchQuery.isEmpty()) {
App::searchByHashtag(searchQuery, peer);
}
});
} else {
_controller->showPeerInfo(peer);
if (searchQuery.isEmpty()) {
_controller->showPeerInfo(peer);
} else {
App::searchByHashtag(searchQuery, peer);
}
}
} else {
if (msgId == ShowAtProfileMsgId || !peer->isChannel()) { // show specific posts only in channels / supergroups
@@ -3311,10 +3322,13 @@ void MainWidget::openPeerByName(
peer->id,
SectionShow::Way::Forward,
msgId);
if (!searchQuery.isEmpty()) {
App::searchByHashtag(searchQuery, peer);
}
});
}
} else {
MTP::send(MTPcontacts_ResolveUsername(MTP_string(username)), rpcDone(&MainWidget::usernameResolveDone, qMakePair(msgId, startToken)), rpcFail(&MainWidget::usernameResolveFail, username));
MTP::send(MTPcontacts_ResolveUsername(MTP_string(username)), rpcDone(&MainWidget::usernameResolveDone, qMakePair(msgId, qMakePair(startToken, searchQuery))), rpcFail(&MainWidget::usernameResolveFail, username));
}
}
@@ -3324,7 +3338,7 @@ bool MainWidget::contentOverlapped(const QRect &globalRect) {
|| (_playerVolume && _playerVolume->overlaps(globalRect)));
}
void MainWidget::usernameResolveDone(QPair<MsgId, QString> msgIdAndStartToken, const MTPcontacts_ResolvedPeer &result) {
void MainWidget::usernameResolveDone(QPair<MsgId, QPair<QString, QString>> msgIdAndStartToken, const MTPcontacts_ResolvedPeer &result) {
Ui::hideLayer();
if (result.type() != mtpc_contacts_resolvedPeer) return;
@@ -3336,7 +3350,8 @@ void MainWidget::usernameResolveDone(QPair<MsgId, QString> msgIdAndStartToken, c
PeerData *peer = session().data().peer(peerId);
MsgId msgId = msgIdAndStartToken.first;
QString startToken = msgIdAndStartToken.second;
QString startToken = msgIdAndStartToken.second.first;
QString searchQuery = msgIdAndStartToken.second.second;
if (msgId == ShowAtProfileMsgId && !peer->isChannel()) {
if (peer->isUser() && peer->asUser()->isBot() && !peer->asUser()->botInfo->cantJoinGroups && !startToken.isEmpty()) {
peer->asUser()->botInfo->startGroupToken = startToken;
@@ -3345,13 +3360,20 @@ void MainWidget::usernameResolveDone(QPair<MsgId, QString> msgIdAndStartToken, c
peer->asUser());
} else if (peer->isUser() && peer->asUser()->isBot()) {
// Always open bot chats, even from mention links.
InvokeQueued(this, [this, peer] {
InvokeQueued(this, [this, peer, searchQuery] {
_controller->showPeerHistory(
peer->id,
SectionShow::Way::Forward);
if (!searchQuery.isEmpty()) {
App::searchByHashtag(searchQuery, peer);
}
});
} else {
_controller->showPeerInfo(peer);
if (searchQuery.isEmpty()) {
_controller->showPeerInfo(peer);
} else {
App::searchByHashtag(searchQuery, peer);
}
}
} else {
if (msgId == ShowAtProfileMsgId || !peer->isChannel()) { // show specific posts only in channels / supergroups
@@ -3364,11 +3386,14 @@ void MainWidget::usernameResolveDone(QPair<MsgId, QString> msgIdAndStartToken, c
_history->updateControlsGeometry();
}
}
InvokeQueued(this, [this, peer, msgId] {
InvokeQueued(this, [this, peer, msgId, searchQuery] {
_controller->showPeerHistory(
peer->id,
SectionShow::Way::Forward,
msgId);
if (!searchQuery.isEmpty()) {
App::searchByHashtag(searchQuery, peer);
}
});
}
}

View File

@@ -125,7 +125,8 @@ public:
const QString &name,
MsgId msgId = ShowAtUnreadMsgId,
const QString &startToken = QString(),
FullMsgId clickFromMessageId = FullMsgId());
FullMsgId clickFromMessageId = FullMsgId(),
const QString &searchQuery = QString());
bool started();
@@ -403,7 +404,7 @@ private:
// Doesn't call sendHistoryChangeNotifications itself.
void feedUpdate(const MTPUpdate &update);
void usernameResolveDone(QPair<MsgId, QString> msgIdAndStartToken, const MTPcontacts_ResolvedPeer &result);
void usernameResolveDone(QPair<MsgId, QPair<QString, QString>> msgIdAndStartToken, const MTPcontacts_ResolvedPeer &result);
bool usernameResolveFail(QString name, const RPCError &error);
int getMainSectionTop() const;