diff --git a/td/telegram/ForumTopicManager.cpp b/td/telegram/ForumTopicManager.cpp index f9cf75995..23277f6f5 100644 --- a/td/telegram/ForumTopicManager.cpp +++ b/td/telegram/ForumTopicManager.cpp @@ -16,6 +16,7 @@ #include "td/telegram/ForumTopicIcon.h" #include "td/telegram/ForumTopicInfo.hpp" #include "td/telegram/Global.h" +#include "td/telegram/LinkManager.h" #include "td/telegram/logevent/LogEvent.h" #include "td/telegram/MessagesManager.h" #include "td/telegram/MessageThreadDb.h" @@ -724,7 +725,7 @@ void ForumTopicManager::get_forum_topic_link(DialogId dialog_id, MessageId top_t auto channel_id = dialog_id.get_channel_id(); SliceBuilder sb; - sb << td_->option_manager_->get_option_string("t_me_url", "https://t.me/"); + sb << LinkManager::get_t_me_url(); bool is_public = false; auto dialog_username = td_->contacts_manager_->get_channel_first_username(channel_id); diff --git a/td/telegram/LinkManager.cpp b/td/telegram/LinkManager.cpp index 465a03940..b5c5fce65 100644 --- a/td/telegram/LinkManager.cpp +++ b/td/telegram/LinkManager.cpp @@ -1694,7 +1694,7 @@ void LinkManager::get_link_login_url(const string &url, bool allow_write_access, Result LinkManager::get_background_url(const string &name, td_api::object_ptr background_type) { TRY_RESULT(type, BackgroundType::get_background_type(background_type.get())); - auto url = PSTRING() << G()->get_option_string("t_me_url", "https://t.me/") << "bg/"; + auto url = PSTRING() << get_t_me_url() << "bg/"; auto link = type.get_link(); if (type.has_file()) { url += name; @@ -1728,7 +1728,7 @@ string LinkManager::get_dialog_invite_link(Slice hash, bool is_internal) { if (is_internal) { return PSTRING() << "tg:join?invite=" << hash; } else { - return PSTRING() << G()->get_option_string("t_me_url", "https://t.me/") << '+' << hash; + return PSTRING() << get_t_me_url() << '+' << hash; } } @@ -1759,12 +1759,11 @@ string LinkManager::get_instant_view_link_rhash(Slice link) { } string LinkManager::get_instant_view_link(Slice url, Slice rhash) { - return PSTRING() << G()->get_option_string("t_me_url", "https://t.me/") << "iv?url=" << url_encode(url) - << "&rhash=" << url_encode(rhash); + return PSTRING() << get_t_me_url() << "iv?url=" << url_encode(url) << "&rhash=" << url_encode(rhash); } string LinkManager::get_public_chat_link(Slice username) { - return PSTRING() << G()->get_option_string("t_me_url", "https://t.me/") << url_encode(username); + return PSTRING() << get_t_me_url() << url_encode(username); } UserId LinkManager::get_link_user_id(Slice url) { @@ -1809,6 +1808,14 @@ UserId LinkManager::get_link_user_id(Slice url) { return UserId(); } +string LinkManager::get_t_me_url() { + if (Scheduler::context() != nullptr) { + return G()->get_option_string("t_me_url", "https://t.me/"); + } else { + return "https://t.me/"; + } +} + Result LinkManager::get_link_custom_emoji_id(Slice url) { string lower_cased_url = to_lower(url); url = lower_cased_url; diff --git a/td/telegram/LinkManager.h b/td/telegram/LinkManager.h index ee493f8d9..dd82a71b4 100644 --- a/td/telegram/LinkManager.h +++ b/td/telegram/LinkManager.h @@ -94,6 +94,8 @@ class LinkManager final : public Actor { static UserId get_link_user_id(Slice url); + static string get_t_me_url(); + static Result get_link_custom_emoji_id(Slice url); static Result get_message_link_info(Slice url); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 9d7085571..a265f5e78 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -19451,7 +19451,7 @@ Result> MessagesManager::get_message_link(FullMessageId } SliceBuilder sb; - sb << td_->option_manager_->get_option_string("t_me_url", "https://t.me/"); + sb << LinkManager::get_t_me_url(); if (in_message_thread && !is_forum) { // try to generate a comment link diff --git a/td/telegram/SponsoredMessageManager.cpp b/td/telegram/SponsoredMessageManager.cpp index 341227747..f12089ed8 100644 --- a/td/telegram/SponsoredMessageManager.cpp +++ b/td/telegram/SponsoredMessageManager.cpp @@ -177,9 +177,9 @@ td_api::object_ptr SponsoredMessageManager::get_sponso case DialogType::Channel: if (sponsored_message.server_message_id.is_valid()) { auto channel_id = sponsored_message.sponsor_dialog_id.get_channel_id(); - auto t_me = td_->option_manager_->get_option_string("t_me_url", "https://t.me/"); link = td_api::make_object( - PSTRING() << t_me << "c/" << channel_id.get() << '/' << sponsored_message.server_message_id.get()); + PSTRING() << LinkManager::get_t_me_url() << "c/" << channel_id.get() << '/' + << sponsored_message.server_message_id.get()); } break; case DialogType::None: { diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 349435129..5c5eff8e7 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -8,6 +8,7 @@ #include "td/telegram/ConfigManager.h" #include "td/telegram/Global.h" +#include "td/telegram/LinkManager.h" #include "td/telegram/logevent/LogEvent.h" #include "td/telegram/MessagesManager.h" #include "td/telegram/net/MtprotoHeader.h" @@ -233,7 +234,7 @@ void ConnectionCreator::get_proxy_link(int32 proxy_id, Promise promise) } auto &proxy = it->second; - string url = G()->get_option_string("t_me_url", "https://t.me/"); + string url = LinkManager::get_t_me_url(); bool is_socks = false; switch (proxy.type()) { case Proxy::Type::Socks5: