2021-05-25 01:24:30 +02:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
|
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2021-06-03 22:37:56 +02:00
|
|
|
#include "td/telegram/FullMessageId.h"
|
2021-05-27 19:47:04 +02:00
|
|
|
#include "td/telegram/MessageLinkInfo.h"
|
2021-05-25 01:39:29 +02:00
|
|
|
#include "td/telegram/td_api.h"
|
2021-11-24 10:53:38 +01:00
|
|
|
#include "td/telegram/UserId.h"
|
2021-05-25 01:39:29 +02:00
|
|
|
|
2021-05-25 01:24:30 +02:00
|
|
|
#include "td/actor/actor.h"
|
2021-05-25 01:39:29 +02:00
|
|
|
#include "td/actor/PromiseFuture.h"
|
2021-05-25 01:24:30 +02:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2021-05-25 01:53:25 +02:00
|
|
|
#include "td/utils/Slice.h"
|
|
|
|
#include "td/utils/Status.h"
|
2021-05-25 01:24:30 +02:00
|
|
|
|
2021-05-25 16:06:27 +02:00
|
|
|
#include <utility>
|
|
|
|
|
2021-05-25 01:24:30 +02:00
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class Td;
|
|
|
|
|
2021-07-04 04:58:54 +02:00
|
|
|
class LinkManager final : public Actor {
|
2021-05-25 01:24:30 +02:00
|
|
|
public:
|
|
|
|
LinkManager(Td *td, ActorShared<> parent);
|
|
|
|
|
|
|
|
LinkManager(const LinkManager &) = delete;
|
|
|
|
LinkManager &operator=(const LinkManager &) = delete;
|
|
|
|
LinkManager(LinkManager &&) = delete;
|
|
|
|
LinkManager &operator=(LinkManager &&) = delete;
|
2021-07-03 22:51:36 +02:00
|
|
|
~LinkManager() final;
|
2021-05-25 01:24:30 +02:00
|
|
|
|
2021-05-25 16:06:27 +02:00
|
|
|
class InternalLink {
|
|
|
|
public:
|
|
|
|
InternalLink() = default;
|
|
|
|
InternalLink(const InternalLink &) = delete;
|
|
|
|
InternalLink &operator=(const InternalLink &) = delete;
|
|
|
|
InternalLink(InternalLink &&) = delete;
|
|
|
|
InternalLink &operator=(InternalLink &&) = delete;
|
|
|
|
virtual ~InternalLink() = default;
|
|
|
|
|
|
|
|
virtual td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// checks whether the link is a valid tg, ton or HTTP(S) URL and returns it in a canonical form
|
2021-05-25 01:53:25 +02:00
|
|
|
static Result<string> check_link(Slice link);
|
|
|
|
|
2021-06-01 04:41:32 +02:00
|
|
|
// checks whether the link is a supported tg or t.me link and parses it
|
2021-05-25 16:06:27 +02:00
|
|
|
static unique_ptr<InternalLink> parse_internal_link(Slice link);
|
|
|
|
|
2021-06-03 22:19:35 +02:00
|
|
|
void update_autologin_domains(string autologin_token, vector<string> autologin_domains,
|
|
|
|
vector<string> url_auth_domains);
|
|
|
|
|
2021-08-08 10:26:51 +02:00
|
|
|
void get_deep_link_info(Slice link, Promise<td_api::object_ptr<td_api::deepLinkInfo>> &&promise);
|
|
|
|
|
2021-06-03 22:19:35 +02:00
|
|
|
void get_external_link_info(string &&link, Promise<td_api::object_ptr<td_api::LoginUrlInfo>> &&promise);
|
|
|
|
|
2021-09-03 11:27:59 +02:00
|
|
|
void get_login_url_info(FullMessageId full_message_id, int64 button_id,
|
2021-05-25 01:39:29 +02:00
|
|
|
Promise<td_api::object_ptr<td_api::LoginUrlInfo>> &&promise);
|
|
|
|
|
2021-09-03 11:27:59 +02:00
|
|
|
void get_login_url(FullMessageId full_message_id, int64 button_id, bool allow_write_access,
|
2021-05-25 01:39:29 +02:00
|
|
|
Promise<td_api::object_ptr<td_api::httpUrl>> &&promise);
|
|
|
|
|
|
|
|
void get_link_login_url(const string &url, bool allow_write_access,
|
|
|
|
Promise<td_api::object_ptr<td_api::httpUrl>> &&promise);
|
|
|
|
|
2021-05-27 19:31:06 +02:00
|
|
|
static string get_dialog_invite_link_hash(Slice invite_link);
|
|
|
|
|
2021-11-24 10:53:38 +01:00
|
|
|
static UserId get_link_user_id(Slice url);
|
|
|
|
|
2021-05-27 19:47:04 +02:00
|
|
|
static Result<MessageLinkInfo> get_message_link_info(Slice url);
|
|
|
|
|
2021-05-25 01:24:30 +02:00
|
|
|
private:
|
2021-06-03 22:19:35 +02:00
|
|
|
void start_up() final;
|
|
|
|
|
|
|
|
void tear_down() final;
|
2021-05-25 01:24:30 +02:00
|
|
|
|
2021-06-01 02:55:08 +02:00
|
|
|
class InternalLinkActiveSessions;
|
2021-05-27 00:02:12 +02:00
|
|
|
class InternalLinkAuthenticationCode;
|
2021-05-25 16:06:27 +02:00
|
|
|
class InternalLinkBackground;
|
2021-05-30 02:25:45 +02:00
|
|
|
class InternalLinkBotStart;
|
|
|
|
class InternalLinkBotStartInGroup;
|
2021-06-01 02:55:08 +02:00
|
|
|
class InternalLinkChangePhoneNumber;
|
2021-05-28 17:17:14 +02:00
|
|
|
class InternalLinkConfirmPhone;
|
2021-05-28 16:27:30 +02:00
|
|
|
class InternalLinkDialogInvite;
|
2021-06-01 02:55:08 +02:00
|
|
|
class InternalLinkFilterSettings;
|
2021-05-30 02:46:06 +02:00
|
|
|
class InternalLinkGame;
|
2021-05-28 18:26:09 +02:00
|
|
|
class InternalLinkLanguage;
|
2021-05-25 16:06:27 +02:00
|
|
|
class InternalLinkMessage;
|
2021-05-25 18:05:17 +02:00
|
|
|
class InternalLinkMessageDraft;
|
2021-05-31 20:41:40 +02:00
|
|
|
class InternalLinkPassportDataRequest;
|
2021-05-29 02:51:31 +02:00
|
|
|
class InternalLinkProxy;
|
2021-05-31 03:15:33 +02:00
|
|
|
class InternalLinkPublicDialog;
|
2021-05-27 00:25:11 +02:00
|
|
|
class InternalLinkQrCodeAuthentication;
|
2021-06-01 02:55:08 +02:00
|
|
|
class InternalLinkSettings;
|
2021-05-28 16:27:30 +02:00
|
|
|
class InternalLinkStickerSet;
|
2021-05-28 18:50:54 +02:00
|
|
|
class InternalLinkTheme;
|
2021-06-01 02:55:08 +02:00
|
|
|
class InternalLinkThemeSettings;
|
2021-05-25 18:30:23 +02:00
|
|
|
class InternalLinkUnknownDeepLink;
|
2021-10-28 20:46:34 +02:00
|
|
|
class InternalLinkUnsupportedProxy;
|
2021-05-30 01:05:23 +02:00
|
|
|
class InternalLinkVoiceChat;
|
2021-05-25 16:06:27 +02:00
|
|
|
|
2021-05-28 16:27:30 +02:00
|
|
|
struct LinkInfo {
|
|
|
|
bool is_internal_ = false;
|
|
|
|
bool is_tg_ = false;
|
|
|
|
string query_;
|
|
|
|
};
|
|
|
|
// returns information about the link
|
|
|
|
static LinkInfo get_link_info(Slice link);
|
|
|
|
|
2021-05-25 16:06:27 +02:00
|
|
|
static unique_ptr<InternalLink> parse_tg_link_query(Slice query);
|
|
|
|
|
|
|
|
static unique_ptr<InternalLink> parse_t_me_link_query(Slice query);
|
|
|
|
|
2021-08-20 19:56:07 +02:00
|
|
|
static unique_ptr<InternalLink> get_internal_link_passport(Slice query,
|
|
|
|
const vector<std::pair<string, string>> &args);
|
2021-05-31 20:41:40 +02:00
|
|
|
|
2021-05-25 18:05:17 +02:00
|
|
|
static unique_ptr<InternalLink> get_internal_link_message_draft(Slice url, Slice text);
|
|
|
|
|
2021-05-25 01:24:30 +02:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
2021-06-03 22:19:35 +02:00
|
|
|
|
|
|
|
string autologin_token_;
|
|
|
|
vector<string> autologin_domains_;
|
|
|
|
double autologin_update_time_ = 0.0;
|
|
|
|
vector<string> url_auth_domains_;
|
2021-05-25 01:24:30 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|