2019-09-16 11:14:06 +00: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
|
|
|
|
*/
|
2019-09-19 09:34:37 +00:00
|
|
|
#include "core/ui_integration.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
|
2022-06-23 13:52:15 +00:00
|
|
|
#include "api/api_text_entities.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "core/local_url_handlers.h"
|
|
|
|
#include "core/file_utilities.h"
|
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/sandbox.h"
|
|
|
|
#include "core/click_handler_types.h"
|
2022-06-23 13:52:15 +00:00
|
|
|
#include "data/stickers/data_custom_emoji.h"
|
|
|
|
#include "data/data_session.h"
|
2022-11-07 10:31:46 +00:00
|
|
|
#include "ui/text/text_custom_emoji.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "ui/basic_click_handlers.h"
|
|
|
|
#include "ui/emoji_config.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "platform/platform_specific.h"
|
2021-03-11 16:21:25 +00:00
|
|
|
#include "boxes/url_auth_box.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "main/main_account.h"
|
|
|
|
#include "main/main_session.h"
|
2021-02-15 12:18:54 +00:00
|
|
|
#include "main/main_app_config.h"
|
2022-11-30 13:28:09 +00:00
|
|
|
#include "window/window_controller.h"
|
2019-09-16 11:14:06 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
|
|
namespace Core {
|
2021-02-15 12:18:54 +00:00
|
|
|
namespace {
|
|
|
|
|
2021-03-11 16:21:25 +00:00
|
|
|
const auto kGoodPrefix = u"https://"_q;
|
|
|
|
const auto kBadPrefix = u"http://"_q;
|
|
|
|
|
|
|
|
[[nodiscard]] QUrl UrlForAutoLogin(const QString &url) {
|
|
|
|
return (url.startsWith(kGoodPrefix, Qt::CaseInsensitive)
|
|
|
|
|| url.startsWith(kBadPrefix, Qt::CaseInsensitive))
|
|
|
|
? QUrl(url)
|
|
|
|
: QUrl();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] QString DomainForAutoLogin(const QUrl &url) {
|
|
|
|
return url.isValid() ? url.host().toLower() : QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] QString UrlWithAutoLoginToken(
|
|
|
|
const QString &url,
|
|
|
|
QUrl parsed,
|
|
|
|
const QString &domain) {
|
2021-02-15 12:18:54 +00:00
|
|
|
const auto &config = Core::App().activeAccount().appConfig();
|
|
|
|
const auto token = config.get<QString>("autologin_token", {});
|
|
|
|
const auto domains = config.get<std::vector<QString>>(
|
|
|
|
"autologin_domains",
|
|
|
|
{});
|
2021-03-11 16:21:25 +00:00
|
|
|
if (token.isEmpty()
|
|
|
|
|| domain.isEmpty()
|
|
|
|
|| !ranges::contains(domains, domain)) {
|
2021-02-15 12:18:54 +00:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
const auto added = "autologin_token=" + token;
|
|
|
|
parsed.setQuery(parsed.hasQuery()
|
|
|
|
? (parsed.query() + '&' + added)
|
|
|
|
: added);
|
2021-03-11 16:21:25 +00:00
|
|
|
if (url.startsWith(kBadPrefix, Qt::CaseInsensitive)) {
|
|
|
|
parsed.setScheme("https");
|
|
|
|
}
|
2021-02-15 12:18:54 +00:00
|
|
|
return QString::fromUtf8(parsed.toEncoded());
|
|
|
|
}
|
|
|
|
|
2021-03-11 16:21:25 +00:00
|
|
|
[[nodiscard]] bool BotAutoLogin(
|
|
|
|
const QString &url,
|
|
|
|
const QString &domain,
|
|
|
|
QVariant context) {
|
|
|
|
auto &account = Core::App().activeAccount();
|
|
|
|
const auto &config = account.appConfig();
|
|
|
|
const auto domains = config.get<std::vector<QString>>(
|
|
|
|
"url_auth_domains",
|
|
|
|
{});
|
|
|
|
if (!account.sessionExists()
|
|
|
|
|| domain.isEmpty()
|
|
|
|
|| !ranges::contains(domains, domain)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto good = url.startsWith(kBadPrefix, Qt::CaseInsensitive)
|
|
|
|
? (kGoodPrefix + url.mid(kBadPrefix.size()))
|
|
|
|
: url;
|
|
|
|
UrlAuthBox::Activate(&account.session(), good, context);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-11 19:01:07 +00:00
|
|
|
[[nodiscard]] QString OpenGLCheckFilePath() {
|
|
|
|
return cWorkingDir() + "tdata/opengl_crash_check";
|
|
|
|
}
|
|
|
|
|
2021-07-01 07:47:29 +00:00
|
|
|
[[nodiscard]] QString ANGLEBackendFilePath() {
|
|
|
|
return cWorkingDir() + "tdata/angle_backend";
|
|
|
|
}
|
|
|
|
|
2021-02-15 12:18:54 +00:00
|
|
|
} // namespace
|
2019-09-16 11:14:06 +00:00
|
|
|
|
|
|
|
void UiIntegration::postponeCall(FnMut<void()> &&callable) {
|
|
|
|
Sandbox::Instance().postponeCall(std::move(callable));
|
|
|
|
}
|
|
|
|
|
|
|
|
void UiIntegration::registerLeaveSubscription(not_null<QWidget*> widget) {
|
|
|
|
Core::App().registerLeaveSubscription(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UiIntegration::unregisterLeaveSubscription(not_null<QWidget*> widget) {
|
|
|
|
Core::App().unregisterLeaveSubscription(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::emojiCacheFolder() {
|
|
|
|
return cWorkingDir() + "tdata/emoji";
|
|
|
|
}
|
|
|
|
|
2021-07-01 07:47:29 +00:00
|
|
|
QString UiIntegration::openglCheckFilePath() {
|
|
|
|
return OpenGLCheckFilePath();
|
2021-06-11 19:01:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-01 07:47:29 +00:00
|
|
|
QString UiIntegration::angleBackendFilePath() {
|
|
|
|
return ANGLEBackendFilePath();
|
2021-06-11 19:01:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
void UiIntegration::textActionsUpdated() {
|
2022-11-30 13:28:09 +00:00
|
|
|
if (const auto window = Core::App().primaryWindow()) {
|
|
|
|
window->widget()->updateGlobalMenu();
|
2019-09-16 11:14:06 +00:00
|
|
|
}
|
|
|
|
}
|
2019-10-02 08:09:45 +00:00
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
void UiIntegration::activationFromTopPanel() {
|
|
|
|
Platform::IgnoreApplicationActivationRightNow();
|
|
|
|
}
|
|
|
|
|
2021-04-27 08:46:51 +00:00
|
|
|
bool UiIntegration::screenIsLocked() {
|
2021-05-27 14:47:51 +00:00
|
|
|
return Core::App().screenIsLocked();
|
2021-04-27 08:46:51 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
std::shared_ptr<ClickHandler> UiIntegration::createLinkHandler(
|
2020-06-16 15:10:39 +00:00
|
|
|
const EntityLinkData &data,
|
|
|
|
const std::any &context) {
|
2020-11-10 16:38:21 +00:00
|
|
|
const auto my = std::any_cast<MarkedTextContext>(&context);
|
2020-06-16 15:10:39 +00:00
|
|
|
switch (data.type) {
|
2020-04-23 13:56:50 +00:00
|
|
|
case EntityType::Url:
|
2020-06-16 15:10:39 +00:00
|
|
|
return (!data.data.isEmpty()
|
|
|
|
&& UrlClickHandler::IsSuspicious(data.data))
|
|
|
|
? std::make_shared<HiddenUrlClickHandler>(data.data)
|
|
|
|
: Integration::createLinkHandler(data, context);
|
2020-04-23 13:56:50 +00:00
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
case EntityType::CustomUrl:
|
2020-06-16 15:10:39 +00:00
|
|
|
return !data.data.isEmpty()
|
|
|
|
? std::make_shared<HiddenUrlClickHandler>(data.data)
|
|
|
|
: Integration::createLinkHandler(data, context);
|
2019-09-16 11:14:06 +00:00
|
|
|
|
|
|
|
case EntityType::BotCommand:
|
2020-06-16 15:10:39 +00:00
|
|
|
return std::make_shared<BotCommandClickHandler>(data.data);
|
2019-09-16 11:14:06 +00:00
|
|
|
|
|
|
|
case EntityType::Hashtag:
|
2020-11-10 16:38:21 +00:00
|
|
|
using HashtagMentionType = MarkedTextContext::HashtagMentionType;
|
2020-06-16 15:10:39 +00:00
|
|
|
if (my && my->type == HashtagMentionType::Twitter) {
|
2019-09-16 11:14:06 +00:00
|
|
|
return std::make_shared<UrlClickHandler>(
|
2022-11-29 21:46:36 +00:00
|
|
|
(u"https://twitter.com/hashtag/"_q
|
2020-06-16 15:10:39 +00:00
|
|
|
+ data.data.mid(1)
|
2022-11-29 21:46:36 +00:00
|
|
|
+ u"?src=hash"_q),
|
2019-09-16 11:14:06 +00:00
|
|
|
true);
|
2020-06-16 15:10:39 +00:00
|
|
|
} else if (my && my->type == HashtagMentionType::Instagram) {
|
2019-09-16 11:14:06 +00:00
|
|
|
return std::make_shared<UrlClickHandler>(
|
2022-11-29 21:46:36 +00:00
|
|
|
(u"https://instagram.com/explore/tags/"_q
|
2020-06-16 15:10:39 +00:00
|
|
|
+ data.data.mid(1)
|
2019-09-16 11:14:06 +00:00
|
|
|
+ '/'),
|
|
|
|
true);
|
|
|
|
}
|
2020-06-16 15:10:39 +00:00
|
|
|
return std::make_shared<HashtagClickHandler>(data.data);
|
2019-09-16 11:14:06 +00:00
|
|
|
|
|
|
|
case EntityType::Cashtag:
|
2020-06-16 15:10:39 +00:00
|
|
|
return std::make_shared<CashtagClickHandler>(data.data);
|
2019-09-16 11:14:06 +00:00
|
|
|
|
|
|
|
case EntityType::Mention:
|
2020-11-10 16:38:21 +00:00
|
|
|
using HashtagMentionType = MarkedTextContext::HashtagMentionType;
|
2020-06-16 15:10:39 +00:00
|
|
|
if (my && my->type == HashtagMentionType::Twitter) {
|
2019-09-16 11:14:06 +00:00
|
|
|
return std::make_shared<UrlClickHandler>(
|
2022-11-29 21:46:36 +00:00
|
|
|
u"https://twitter.com/"_q + data.data.mid(1),
|
2019-09-16 11:14:06 +00:00
|
|
|
true);
|
2020-06-16 15:10:39 +00:00
|
|
|
} else if (my && my->type == HashtagMentionType::Instagram) {
|
2019-09-16 11:14:06 +00:00
|
|
|
return std::make_shared<UrlClickHandler>(
|
2022-11-29 21:46:36 +00:00
|
|
|
u"https://instagram.com/"_q + data.data.mid(1) + '/',
|
2019-09-16 11:14:06 +00:00
|
|
|
true);
|
|
|
|
}
|
2020-06-16 15:10:39 +00:00
|
|
|
return std::make_shared<MentionClickHandler>(data.data);
|
2019-09-16 11:14:06 +00:00
|
|
|
|
|
|
|
case EntityType::MentionName: {
|
2020-06-16 15:10:39 +00:00
|
|
|
auto fields = TextUtilities::MentionNameDataToFields(data.data);
|
2020-06-09 09:36:40 +00:00
|
|
|
if (!my || !my->session) {
|
|
|
|
LOG(("Mention name without a session: %1").arg(data.data));
|
|
|
|
} else if (fields.userId) {
|
2019-09-16 11:14:06 +00:00
|
|
|
return std::make_shared<MentionNameClickHandler>(
|
2020-06-09 09:36:40 +00:00
|
|
|
my->session,
|
2020-06-16 15:10:39 +00:00
|
|
|
data.text,
|
2019-09-16 11:14:06 +00:00
|
|
|
fields.userId,
|
|
|
|
fields.accessHash);
|
|
|
|
} else {
|
2020-06-16 15:10:39 +00:00
|
|
|
LOG(("Bad mention name: %1").arg(data.data));
|
2019-09-16 11:14:06 +00:00
|
|
|
}
|
|
|
|
} break;
|
2022-01-08 04:41:44 +00:00
|
|
|
|
|
|
|
case EntityType::Code:
|
|
|
|
return std::make_shared<MonospaceClickHandler>(data.text, data.type);
|
|
|
|
case EntityType::Pre:
|
|
|
|
return std::make_shared<MonospaceClickHandler>(data.text, data.type);
|
2019-09-16 11:14:06 +00:00
|
|
|
}
|
2020-06-16 15:10:39 +00:00
|
|
|
return Integration::createLinkHandler(data, context);
|
2019-09-16 11:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool UiIntegration::handleUrlClick(
|
|
|
|
const QString &url,
|
|
|
|
const QVariant &context) {
|
2019-10-02 08:09:45 +00:00
|
|
|
const auto local = Core::TryConvertUrlToLocal(url);
|
2019-09-16 11:14:06 +00:00
|
|
|
if (Core::InternalPassportLink(local)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UrlClickHandler::IsEmail(url)) {
|
|
|
|
File::OpenEmailLink(url);
|
|
|
|
return true;
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (local.startsWith(u"tg://"_q, Qt::CaseInsensitive)) {
|
2019-10-02 08:09:45 +00:00
|
|
|
Core::App().openLocalUrl(local, context);
|
2019-09-16 11:14:06 +00:00
|
|
|
return true;
|
2022-11-26 21:20:17 +00:00
|
|
|
} else if (local.startsWith(u"internal:"_q, Qt::CaseInsensitive)) {
|
2019-12-25 15:20:02 +00:00
|
|
|
Core::App().openInternalUrl(local, context);
|
|
|
|
return true;
|
2019-09-16 11:14:06 +00:00
|
|
|
}
|
2020-04-28 08:26:12 +00:00
|
|
|
|
2021-03-11 16:21:25 +00:00
|
|
|
auto parsed = UrlForAutoLogin(url);
|
|
|
|
const auto domain = DomainForAutoLogin(parsed);
|
|
|
|
const auto skip = context.value<ClickHandlerContext>().skipBotAutoLogin;
|
|
|
|
if (skip || !BotAutoLogin(url, domain, context)) {
|
|
|
|
File::OpenUrl(UrlWithAutoLoginToken(url, std::move(parsed), domain));
|
|
|
|
}
|
2020-04-28 08:26:12 +00:00
|
|
|
return true;
|
2022-06-23 11:36:06 +00:00
|
|
|
}
|
2019-09-16 11:14:06 +00:00
|
|
|
|
2022-06-23 11:36:06 +00:00
|
|
|
std::unique_ptr<Ui::Text::CustomEmoji> UiIntegration::createCustomEmoji(
|
|
|
|
const QString &data,
|
|
|
|
const std::any &context) {
|
|
|
|
const auto my = std::any_cast<MarkedTextContext>(&context);
|
2022-06-23 13:52:15 +00:00
|
|
|
if (!my || !my->session) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-11-07 10:31:46 +00:00
|
|
|
auto result = my->session->data().customEmojiManager().create(
|
2022-06-24 06:49:11 +00:00
|
|
|
data,
|
|
|
|
my->customEmojiRepaint);
|
2022-11-07 10:31:46 +00:00
|
|
|
if (my->customEmojiLoopLimit > 0) {
|
|
|
|
return std::make_unique<Ui::Text::LimitedLoopsEmoji>(
|
|
|
|
std::move(result),
|
|
|
|
my->customEmojiLoopLimit);
|
|
|
|
}
|
|
|
|
return result;
|
2019-09-16 11:14:06 +00:00
|
|
|
}
|
|
|
|
|
2022-09-16 20:23:27 +00:00
|
|
|
Fn<void()> UiIntegration::createSpoilerRepaint(const std::any &context) {
|
|
|
|
const auto my = std::any_cast<MarkedTextContext>(&context);
|
|
|
|
return my ? my->customEmojiRepaint : nullptr;
|
|
|
|
}
|
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
rpl::producer<> UiIntegration::forcePopupMenuHideRequests() {
|
2020-06-24 07:56:16 +00:00
|
|
|
return Core::App().passcodeLockChanges() | rpl::to_empty;
|
2019-09-16 11:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Ui::Emoji::One *UiIntegration::defaultEmojiVariant(
|
|
|
|
const Ui::Emoji::One *emoji) {
|
|
|
|
if (!emoji || !emoji->hasVariants()) {
|
|
|
|
return emoji;
|
|
|
|
}
|
|
|
|
const auto nonColored = emoji->nonColoredId();
|
2021-04-25 08:12:32 +00:00
|
|
|
const auto &variants = Core::App().settings().emojiVariants();
|
|
|
|
const auto i = variants.find(nonColored);
|
|
|
|
const auto result = (i != end(variants))
|
|
|
|
? emoji->variant(i->second)
|
2019-09-16 11:14:06 +00:00
|
|
|
: emoji;
|
2022-07-14 11:20:56 +00:00
|
|
|
Core::App().settings().incrementRecentEmoji({ result });
|
2019-09-16 11:14:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseContextCopyText() {
|
|
|
|
return tr::lng_context_copy_text(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseContextCopyEmail() {
|
|
|
|
return tr::lng_context_copy_email(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseContextCopyLink() {
|
|
|
|
return tr::lng_context_copy_link(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseContextCopySelected() {
|
|
|
|
return tr::lng_context_copy_selected(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseFormattingTitle() {
|
|
|
|
return tr::lng_menu_formatting(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseFormattingLinkCreate() {
|
|
|
|
return tr::lng_menu_formatting_link_create(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseFormattingLinkEdit() {
|
|
|
|
return tr::lng_menu_formatting_link_edit(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseFormattingClear() {
|
|
|
|
return tr::lng_menu_formatting_clear(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseFormattingBold() {
|
|
|
|
return tr::lng_menu_formatting_bold(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseFormattingItalic() {
|
|
|
|
return tr::lng_menu_formatting_italic(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseFormattingUnderline() {
|
|
|
|
return tr::lng_menu_formatting_underline(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseFormattingStrikeOut() {
|
|
|
|
return tr::lng_menu_formatting_strike_out(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseFormattingMonospace() {
|
|
|
|
return tr::lng_menu_formatting_monospace(tr::now);
|
|
|
|
}
|
|
|
|
|
2021-12-19 14:07:57 +00:00
|
|
|
QString UiIntegration::phraseFormattingSpoiler() {
|
|
|
|
return tr::lng_menu_formatting_spoiler(tr::now);
|
|
|
|
}
|
|
|
|
|
2022-04-29 16:20:15 +00:00
|
|
|
QString UiIntegration::phraseButtonOk() {
|
|
|
|
return tr::lng_box_ok(tr::now);
|
|
|
|
}
|
|
|
|
|
2022-07-07 04:39:33 +00:00
|
|
|
QString UiIntegration::phraseButtonClose() {
|
|
|
|
return tr::lng_close(tr::now);
|
|
|
|
}
|
|
|
|
|
2022-04-29 16:20:15 +00:00
|
|
|
QString UiIntegration::phraseButtonCancel() {
|
|
|
|
return tr::lng_cancel(tr::now);
|
|
|
|
}
|
|
|
|
|
2022-07-07 04:39:33 +00:00
|
|
|
QString UiIntegration::phrasePanelCloseWarning() {
|
|
|
|
return tr::lng_bot_close_warning_title(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phrasePanelCloseUnsaved() {
|
|
|
|
return tr::lng_bot_close_warning(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phrasePanelCloseAnyway() {
|
|
|
|
return tr::lng_bot_close_warning_sure(tr::now);
|
|
|
|
}
|
|
|
|
|
2022-07-25 15:48:26 +00:00
|
|
|
#if 0 // disabled for now
|
2022-07-15 12:09:55 +00:00
|
|
|
QString UiIntegration::phraseBotSharePhone() {
|
|
|
|
return tr::lng_bot_share_phone(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseBotSharePhoneTitle() {
|
|
|
|
return tr::lng_settings_phone_label(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString UiIntegration::phraseBotSharePhoneConfirm() {
|
|
|
|
return tr::lng_bot_share_phone_confirm(tr::now);
|
|
|
|
}
|
2022-07-25 15:48:26 +00:00
|
|
|
#endif
|
2022-07-15 12:09:55 +00:00
|
|
|
|
2021-06-14 07:22:39 +00:00
|
|
|
bool OpenGLLastCheckFailed() {
|
|
|
|
return QFile::exists(OpenGLCheckFilePath());
|
|
|
|
}
|
|
|
|
|
2019-09-16 11:14:06 +00:00
|
|
|
} // namespace Core
|