2018-11-26 15:55:02 +04:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "core/local_url_handlers.h"
|
|
|
|
|
2019-09-16 14:14:06 +03:00
|
|
|
#include "api/api_text_entities.h"
|
2018-11-26 15:55:02 +04:00
|
|
|
#include "base/qthelp_regex.h"
|
|
|
|
#include "base/qthelp_url.h"
|
|
|
|
#include "lang/lang_cloud_manager.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "core/update_checker.h"
|
2019-04-04 13:33:41 +04:00
|
|
|
#include "core/application.h"
|
2018-11-26 15:55:02 +04:00
|
|
|
#include "boxes/confirm_phone_box.h"
|
2019-02-07 19:36:30 +03:00
|
|
|
#include "boxes/background_preview_box.h"
|
2018-11-26 15:55:02 +04:00
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/share_box.h"
|
|
|
|
#include "boxes/connection_box.h"
|
|
|
|
#include "boxes/sticker_set_box.h"
|
|
|
|
#include "passport/passport_form_controller.h"
|
2019-06-06 13:21:40 +03:00
|
|
|
#include "window/window_session_controller.h"
|
2019-01-18 16:27:37 +04:00
|
|
|
#include "data/data_session.h"
|
2019-09-06 17:24:22 +03:00
|
|
|
#include "data/data_cloud_themes.h"
|
2019-04-04 13:33:41 +04:00
|
|
|
#include "data/data_channel.h"
|
2018-11-26 15:55:02 +04:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "mainwidget.h"
|
2019-07-24 13:45:24 +02:00
|
|
|
#include "main/main_session.h"
|
2018-11-26 15:55:02 +04:00
|
|
|
#include "apiwrap.h"
|
2019-09-13 09:06:02 +03:00
|
|
|
#include "app.h"
|
2018-11-26 15:55:02 +04:00
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using Match = qthelp::RegularExpressionMatch;
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool JoinGroupByHash(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
|
|
|
if (!session) {
|
2018-11-26 15:55:02 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto hash = match->captured(1);
|
2019-07-24 16:00:30 +02:00
|
|
|
session->api().checkChatInvite(hash, [=](const MTPChatInvite &result) {
|
2019-01-21 17:42:21 +04:00
|
|
|
Core::App().hideMediaView();
|
2018-11-26 15:55:02 +04:00
|
|
|
result.match([=](const MTPDchatInvite &data) {
|
2019-07-24 16:00:30 +02:00
|
|
|
Ui::show(Box<ConfirmInviteBox>(session, data, [=] {
|
|
|
|
session->api().importChatInvite(hash);
|
2018-11-26 15:55:02 +04:00
|
|
|
}));
|
|
|
|
}, [=](const MTPDchatInviteAlready &data) {
|
2019-07-24 16:00:30 +02:00
|
|
|
if (const auto chat = session->data().processChat(data.vchat())) {
|
2019-06-06 13:21:40 +03:00
|
|
|
App::wnd()->sessionController()->showPeerHistory(
|
2018-11-26 15:55:02 +04:00
|
|
|
chat,
|
|
|
|
Window::SectionShow::Way::Forward);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, [=](const RPCError &error) {
|
|
|
|
if (error.code() != 400) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-21 17:42:21 +04:00
|
|
|
Core::App().hideMediaView();
|
2019-06-19 17:09:03 +02:00
|
|
|
Ui::show(Box<InformBox>(tr::lng_group_invite_bad_link(tr::now)));
|
2018-11-26 15:55:02 +04:00
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool ShowStickerSet(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
|
|
|
if (!session) {
|
2018-11-26 15:55:02 +04:00
|
|
|
return false;
|
|
|
|
}
|
2019-01-21 17:42:21 +04:00
|
|
|
Core::App().hideMediaView();
|
2018-11-26 15:55:02 +04:00
|
|
|
Ui::show(Box<StickerSetBox>(
|
2019-06-24 17:09:37 +02:00
|
|
|
App::wnd()->sessionController(),
|
2018-11-26 15:55:02 +04:00
|
|
|
MTP_inputStickerSetShortName(MTP_string(match->captured(1)))));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-05 21:49:02 +03:00
|
|
|
bool ShowTheme(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
|
|
|
if (!session) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-06 17:24:22 +03:00
|
|
|
const auto clickFromMessageId = context.value<FullMsgId>();
|
2019-09-05 21:49:02 +03:00
|
|
|
Core::App().hideMediaView();
|
2019-09-06 17:24:22 +03:00
|
|
|
session->data().cloudThemes().resolve(
|
|
|
|
match->captured(1),
|
|
|
|
clickFromMessageId);
|
2019-09-05 21:49:02 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool SetLanguage(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
2018-12-07 12:42:48 +04:00
|
|
|
const auto languageId = match->captured(1);
|
|
|
|
Lang::CurrentCloudManager().switchWithWarning(languageId);
|
2018-11-26 15:55:02 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool ShareUrl(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
|
|
|
if (!session) {
|
2018-11-26 15:55:02 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto params = url_parse_params(
|
|
|
|
match->captured(1),
|
|
|
|
qthelp::UrlParamNameTransform::ToLower);
|
|
|
|
auto url = params.value(qsl("url"));
|
|
|
|
if (url.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
App::main()->shareUrlLayer(url, params.value("text"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool ConfirmPhone(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
|
|
|
if (!session) {
|
2018-11-26 15:55:02 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto params = url_parse_params(
|
|
|
|
match->captured(1),
|
|
|
|
qthelp::UrlParamNameTransform::ToLower);
|
|
|
|
auto phone = params.value(qsl("phone"));
|
|
|
|
auto hash = params.value(qsl("hash"));
|
|
|
|
if (phone.isEmpty() || hash.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ConfirmPhoneBox::start(phone, hash);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool ShareGameScore(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
|
|
|
if (!session) {
|
2018-11-26 15:55:02 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto params = url_parse_params(
|
|
|
|
match->captured(1),
|
|
|
|
qthelp::UrlParamNameTransform::ToLower);
|
2019-07-25 20:55:11 +02:00
|
|
|
ShareGameScoreByHash(session, params.value(qsl("hash")));
|
2018-11-26 15:55:02 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool ApplySocksProxy(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
2018-11-26 15:55:02 +04:00
|
|
|
auto params = url_parse_params(
|
|
|
|
match->captured(1),
|
|
|
|
qthelp::UrlParamNameTransform::ToLower);
|
|
|
|
ProxiesBoxController::ShowApplyConfirmation(ProxyData::Type::Socks5, params);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool ApplyMtprotoProxy(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
2018-11-26 15:55:02 +04:00
|
|
|
auto params = url_parse_params(
|
|
|
|
match->captured(1),
|
|
|
|
qthelp::UrlParamNameTransform::ToLower);
|
|
|
|
ProxiesBoxController::ShowApplyConfirmation(ProxyData::Type::Mtproto, params);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShowPassportForm(const QMap<QString, QString> ¶ms) {
|
|
|
|
const auto botId = params.value("bot_id", QString()).toInt();
|
|
|
|
const auto scope = params.value("scope", QString());
|
|
|
|
const auto callback = params.value("callback_url", QString());
|
|
|
|
const auto publicKey = params.value("public_key", QString());
|
|
|
|
const auto nonce = params.value(
|
|
|
|
Passport::NonceNameByScope(scope),
|
|
|
|
QString());
|
|
|
|
const auto errors = params.value("errors", QString());
|
|
|
|
if (const auto window = App::wnd()) {
|
2019-06-06 13:21:40 +03:00
|
|
|
if (const auto controller = window->sessionController()) {
|
2018-11-26 15:55:02 +04:00
|
|
|
controller->showPassportForm(Passport::FormRequest(
|
|
|
|
botId,
|
|
|
|
scope,
|
|
|
|
callback,
|
|
|
|
publicKey,
|
|
|
|
nonce,
|
|
|
|
errors));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool ShowPassport(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
2018-11-26 15:55:02 +04:00
|
|
|
return ShowPassportForm(url_parse_params(
|
|
|
|
match->captured(1),
|
|
|
|
qthelp::UrlParamNameTransform::ToLower));
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool ShowWallPaper(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
|
|
|
if (!session) {
|
2019-01-17 12:18:23 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto params = url_parse_params(
|
|
|
|
match->captured(1),
|
|
|
|
qthelp::UrlParamNameTransform::ToLower);
|
|
|
|
return BackgroundPreviewBox::Start(
|
2019-07-24 16:00:30 +02:00
|
|
|
session,
|
2019-01-17 12:18:23 +04:00
|
|
|
params.value(qsl("slug")),
|
2019-01-29 10:29:38 +03:00
|
|
|
params);
|
2019-01-17 12:18:23 +04:00
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool ResolveUsername(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
|
|
|
if (!session) {
|
2018-11-26 15:55:02 +04:00
|
|
|
return false;
|
|
|
|
}
|
2019-01-17 12:18:23 +04:00
|
|
|
const auto params = url_parse_params(
|
2018-11-26 15:55:02 +04:00
|
|
|
match->captured(1),
|
|
|
|
qthelp::UrlParamNameTransform::ToLower);
|
|
|
|
const auto domain = params.value(qsl("domain"));
|
|
|
|
const auto valid = [](const QString &domain) {
|
|
|
|
return qthelp::regex_match(
|
2018-11-30 13:25:08 +04:00
|
|
|
qsl("^[a-zA-Z0-9\\.\\_]+$"),
|
2018-11-26 15:55:02 +04:00
|
|
|
domain,
|
|
|
|
{}
|
|
|
|
).valid();
|
|
|
|
};
|
|
|
|
if (domain == qsl("telegrampassport")) {
|
|
|
|
return ShowPassportForm(params);
|
|
|
|
} else if (!valid(domain)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto start = qsl("start");
|
|
|
|
auto startToken = params.value(start);
|
|
|
|
if (startToken.isEmpty()) {
|
|
|
|
start = qsl("startgroup");
|
|
|
|
startToken = params.value(start);
|
|
|
|
if (startToken.isEmpty()) {
|
|
|
|
start = QString();
|
|
|
|
}
|
|
|
|
}
|
2019-04-04 13:33:41 +04:00
|
|
|
auto post = (start == qsl("startgroup"))
|
|
|
|
? ShowAtProfileMsgId
|
|
|
|
: ShowAtUnreadMsgId;
|
2018-11-26 15:55:02 +04:00
|
|
|
auto postParam = params.value(qsl("post"));
|
|
|
|
if (auto postId = postParam.toInt()) {
|
|
|
|
post = postId;
|
|
|
|
}
|
2019-04-04 13:33:41 +04:00
|
|
|
const auto gameParam = params.value(qsl("game"));
|
2018-11-26 15:55:02 +04:00
|
|
|
if (!gameParam.isEmpty() && valid(gameParam)) {
|
|
|
|
startToken = gameParam;
|
|
|
|
post = ShowAtGameShareMsgId;
|
|
|
|
}
|
|
|
|
const auto clickFromMessageId = context.value<FullMsgId>();
|
|
|
|
App::main()->openPeerByName(
|
|
|
|
domain,
|
|
|
|
post,
|
|
|
|
startToken,
|
|
|
|
clickFromMessageId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool ResolvePrivatePost(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
|
|
|
if (!session) {
|
2019-04-04 13:33:41 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto params = url_parse_params(
|
|
|
|
match->captured(1),
|
|
|
|
qthelp::UrlParamNameTransform::ToLower);
|
|
|
|
const auto channelId = params.value(qsl("channel")).toInt();
|
|
|
|
const auto msgId = params.value(qsl("post")).toInt();
|
|
|
|
if (!channelId || !IsServerMsgId(msgId)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto done = [=](not_null<PeerData*> peer) {
|
2019-06-06 13:21:40 +03:00
|
|
|
App::wnd()->sessionController()->showPeerHistory(
|
2019-04-04 13:33:41 +04:00
|
|
|
peer->id,
|
|
|
|
Window::SectionShow::Way::Forward,
|
|
|
|
msgId);
|
|
|
|
};
|
|
|
|
const auto fail = [=] {
|
2019-06-19 17:09:03 +02:00
|
|
|
Ui::show(Box<InformBox>(tr::lng_error_post_link_invalid(tr::now)));
|
2019-04-04 13:33:41 +04:00
|
|
|
};
|
2019-07-24 16:00:30 +02:00
|
|
|
if (const auto channel = session->data().channelLoaded(channelId)) {
|
2019-04-04 13:33:41 +04:00
|
|
|
done(channel);
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-24 16:00:30 +02:00
|
|
|
session->api().request(MTPchannels_GetChannels(
|
2019-04-04 13:33:41 +04:00
|
|
|
MTP_vector<MTPInputChannel>(
|
|
|
|
1,
|
|
|
|
MTP_inputChannel(MTP_int(channelId), MTP_long(0)))
|
|
|
|
)).done([=](const MTPmessages_Chats &result) {
|
|
|
|
result.match([&](const auto &data) {
|
2019-07-24 16:00:30 +02:00
|
|
|
const auto peer = session->data().processChats(data.vchats());
|
2019-04-04 13:33:41 +04:00
|
|
|
if (peer && peer->id == peerFromChannel(channelId)) {
|
|
|
|
done(peer);
|
|
|
|
} else {
|
|
|
|
fail();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}).fail([=](const RPCError &error) {
|
|
|
|
fail();
|
|
|
|
}).send();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
bool HandleUnknown(
|
|
|
|
Main::Session *session,
|
|
|
|
const Match &match,
|
|
|
|
const QVariant &context) {
|
|
|
|
if (!session) {
|
2018-11-26 15:55:02 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto request = match->captured(1);
|
|
|
|
const auto callback = [=](const MTPDhelp_deepLinkInfo &result) {
|
|
|
|
const auto text = TextWithEntities{
|
2019-07-05 15:38:38 +02:00
|
|
|
qs(result.vmessage()),
|
2019-09-16 14:14:06 +03:00
|
|
|
Api::EntitiesFromMTP(result.ventities().value_or_empty())
|
2018-11-26 15:55:02 +04:00
|
|
|
};
|
|
|
|
if (result.is_update_app()) {
|
|
|
|
const auto box = std::make_shared<QPointer<BoxContent>>();
|
|
|
|
const auto callback = [=] {
|
|
|
|
Core::UpdateApplication();
|
|
|
|
if (*box) (*box)->closeBox();
|
|
|
|
};
|
|
|
|
*box = Ui::show(Box<ConfirmBox>(
|
|
|
|
text,
|
2019-06-19 17:09:03 +02:00
|
|
|
tr::lng_menu_update(tr::now),
|
2018-11-26 15:55:02 +04:00
|
|
|
callback));
|
|
|
|
} else {
|
|
|
|
Ui::show(Box<InformBox>(text));
|
|
|
|
}
|
|
|
|
};
|
2019-07-24 16:00:30 +02:00
|
|
|
session->api().requestDeepLinkInfo(request, callback);
|
2018-11-26 15:55:02 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
const std::vector<LocalUrlHandler> &LocalUrlHandlers() {
|
|
|
|
static auto Result = std::vector<LocalUrlHandler>{
|
|
|
|
{
|
|
|
|
qsl("^join/?\\?invite=([a-zA-Z0-9\\.\\_\\-]+)(&|$)"),
|
|
|
|
JoinGroupByHash
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qsl("^addstickers/?\\?set=([a-zA-Z0-9\\.\\_]+)(&|$)"),
|
|
|
|
ShowStickerSet
|
|
|
|
},
|
2019-09-05 21:49:02 +03:00
|
|
|
{
|
|
|
|
qsl("^addtheme/?\\?slug=([a-zA-Z0-9\\.\\_]+)(&|$)"),
|
|
|
|
ShowTheme
|
|
|
|
},
|
2018-11-26 15:55:02 +04:00
|
|
|
{
|
|
|
|
qsl("^setlanguage/?\\?lang=([a-zA-Z0-9\\.\\_\\-]+)(&|$)"),
|
|
|
|
SetLanguage
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qsl("^msg_url/?\\?(.+)(#|$)"),
|
|
|
|
ShareUrl
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qsl("^confirmphone/?\\?(.+)(#|$)"),
|
|
|
|
ConfirmPhone
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qsl("^share_game_score/?\\?(.+)(#|$)"),
|
|
|
|
ShareGameScore
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qsl("^socks/?\\?(.+)(#|$)"),
|
|
|
|
ApplySocksProxy
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qsl("^proxy/?\\?(.+)(#|$)"),
|
|
|
|
ApplyMtprotoProxy
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qsl("^passport/?\\?(.+)(#|$)"),
|
|
|
|
ShowPassport
|
|
|
|
},
|
2019-01-17 12:18:23 +04:00
|
|
|
{
|
|
|
|
qsl("^bg/?\\?(.+)(#|$)"),
|
|
|
|
ShowWallPaper
|
|
|
|
},
|
2018-11-26 15:55:02 +04:00
|
|
|
{
|
|
|
|
qsl("^resolve/?\\?(.+)(#|$)"),
|
|
|
|
ResolveUsername
|
|
|
|
},
|
2019-04-04 13:33:41 +04:00
|
|
|
{
|
|
|
|
qsl("^privatepost/?\\?(.+)(#|$)"),
|
|
|
|
ResolvePrivatePost
|
|
|
|
},
|
2018-11-26 15:55:02 +04:00
|
|
|
{
|
|
|
|
qsl("^([^\\?]+)(\\?|#|$)"),
|
|
|
|
HandleUnknown
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2019-08-06 15:43:26 +01:00
|
|
|
QString TryConvertUrlToLocal(QString url) {
|
|
|
|
if (url.size() > 8192) {
|
|
|
|
url = url.mid(0, 8192);
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace qthelp;
|
|
|
|
auto matchOptions = RegExOption::CaseInsensitive;
|
2019-08-06 15:54:44 +01:00
|
|
|
auto telegramMeMatch = regex_match(qsl("^(https?://)?(www\\.)?(telegram\\.(me|dog)|t\\.me)/(.+)$"), url, matchOptions);
|
2019-08-06 15:43:26 +01:00
|
|
|
if (telegramMeMatch) {
|
2019-08-06 15:54:44 +01:00
|
|
|
auto query = telegramMeMatch->capturedRef(5);
|
2019-08-06 15:43:26 +01:00
|
|
|
if (auto joinChatMatch = regex_match(qsl("^joinchat/([a-zA-Z0-9\\.\\_\\-]+)(\\?|$)"), query, matchOptions)) {
|
|
|
|
return qsl("tg://join?invite=") + url_encode(joinChatMatch->captured(1));
|
|
|
|
} else if (auto stickerSetMatch = regex_match(qsl("^addstickers/([a-zA-Z0-9\\.\\_]+)(\\?|$)"), query, matchOptions)) {
|
|
|
|
return qsl("tg://addstickers?set=") + url_encode(stickerSetMatch->captured(1));
|
2019-09-05 21:49:02 +03:00
|
|
|
} else if (auto themeMatch = regex_match(qsl("^addtheme/([a-zA-Z0-9\\.\\_]+)(\\?|$)"), query, matchOptions)) {
|
|
|
|
return qsl("tg://addtheme?slug=") + url_encode(themeMatch->captured(1));
|
2019-08-06 15:43:26 +01:00
|
|
|
} else if (auto languageMatch = regex_match(qsl("^setlanguage/([a-zA-Z0-9\\.\\_\\-]+)(\\?|$)"), query, matchOptions)) {
|
|
|
|
return qsl("tg://setlanguage?lang=") + url_encode(languageMatch->captured(1));
|
|
|
|
} else if (auto shareUrlMatch = regex_match(qsl("^share/url/?\\?(.+)$"), query, matchOptions)) {
|
|
|
|
return qsl("tg://msg_url?") + shareUrlMatch->captured(1);
|
|
|
|
} else if (auto confirmPhoneMatch = regex_match(qsl("^confirmphone/?\\?(.+)"), query, matchOptions)) {
|
|
|
|
return qsl("tg://confirmphone?") + confirmPhoneMatch->captured(1);
|
|
|
|
} else if (auto ivMatch = regex_match(qsl("^iv/?\\?(.+)(#|$)"), query, matchOptions)) {
|
|
|
|
//
|
|
|
|
// We need to show our t.me page, not the url directly.
|
|
|
|
//
|
|
|
|
//auto params = url_parse_params(ivMatch->captured(1), UrlParamNameTransform::ToLower);
|
|
|
|
//auto previewedUrl = params.value(qsl("url"));
|
|
|
|
//if (previewedUrl.startsWith(qstr("http://"), Qt::CaseInsensitive)
|
|
|
|
// || previewedUrl.startsWith(qstr("https://"), Qt::CaseInsensitive)) {
|
|
|
|
// return previewedUrl;
|
|
|
|
//}
|
|
|
|
return url;
|
|
|
|
} else if (auto socksMatch = regex_match(qsl("^socks/?\\?(.+)(#|$)"), query, matchOptions)) {
|
|
|
|
return qsl("tg://socks?") + socksMatch->captured(1);
|
|
|
|
} else if (auto proxyMatch = regex_match(qsl("^proxy/?\\?(.+)(#|$)"), query, matchOptions)) {
|
|
|
|
return qsl("tg://proxy?") + proxyMatch->captured(1);
|
|
|
|
} else if (auto bgMatch = regex_match(qsl("^bg/([a-zA-Z0-9\\.\\_\\-]+)(\\?(.+)?)?$"), query, matchOptions)) {
|
|
|
|
const auto params = bgMatch->captured(3);
|
|
|
|
return qsl("tg://bg?slug=") + bgMatch->captured(1) + (params.isEmpty() ? QString() : '&' + params);
|
|
|
|
} else if (auto postMatch = regex_match(qsl("^c/(\\-?\\d+)/(\\d+)(#|$)"), query, matchOptions)) {
|
|
|
|
return qsl("tg://privatepost?channel=%1&post=%2").arg(postMatch->captured(1)).arg(postMatch->captured(2));
|
|
|
|
} else if (auto usernameMatch = regex_match(qsl("^([a-zA-Z0-9\\.\\_]+)(/?\\?|/?$|/(\\d+)/?(?:\\?|$))"), query, matchOptions)) {
|
|
|
|
auto params = query.mid(usernameMatch->captured(0).size()).toString();
|
|
|
|
auto postParam = QString();
|
|
|
|
if (auto postMatch = regex_match(qsl("^/\\d+/?(?:\\?|$)"), usernameMatch->captured(2))) {
|
|
|
|
postParam = qsl("&post=") + usernameMatch->captured(3);
|
|
|
|
}
|
|
|
|
return qsl("tg://resolve/?domain=") + url_encode(usernameMatch->captured(1)) + postParam + (params.isEmpty() ? QString() : '&' + params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2019-01-21 17:42:21 +04:00
|
|
|
bool InternalPassportLink(const QString &url) {
|
|
|
|
const auto urlTrimmed = url.trimmed();
|
|
|
|
if (!urlTrimmed.startsWith(qstr("tg://"), Qt::CaseInsensitive)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto command = urlTrimmed.midRef(qstr("tg://").size());
|
|
|
|
|
|
|
|
using namespace qthelp;
|
|
|
|
const auto matchOptions = RegExOption::CaseInsensitive;
|
|
|
|
const auto authMatch = regex_match(
|
|
|
|
qsl("^passport/?\\?(.+)(#|$)"),
|
|
|
|
command,
|
|
|
|
matchOptions);
|
|
|
|
const auto usernameMatch = regex_match(
|
|
|
|
qsl("^resolve/?\\?(.+)(#|$)"),
|
|
|
|
command,
|
|
|
|
matchOptions);
|
|
|
|
const auto usernameValue = usernameMatch->hasMatch()
|
|
|
|
? url_parse_params(
|
|
|
|
usernameMatch->captured(1),
|
|
|
|
UrlParamNameTransform::ToLower).value(qsl("domain"))
|
|
|
|
: QString();
|
|
|
|
const auto authLegacy = (usernameValue == qstr("telegrampassport"));
|
|
|
|
return authMatch->hasMatch() || authLegacy;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StartUrlRequiresActivate(const QString &url) {
|
|
|
|
return Core::App().locked()
|
|
|
|
? true
|
|
|
|
: !InternalPassportLink(url);
|
|
|
|
}
|
|
|
|
|
2018-11-26 15:55:02 +04:00
|
|
|
} // namespace Core
|