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-05-25 01:39:29 +02:00
|
|
|
#include "td/telegram/DialogId.h"
|
|
|
|
#include "td/telegram/MessageId.h"
|
|
|
|
#include "td/telegram/td_api.h"
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
class LinkManager : public Actor {
|
|
|
|
public:
|
|
|
|
LinkManager(Td *td, ActorShared<> parent);
|
|
|
|
|
|
|
|
LinkManager(const LinkManager &) = delete;
|
|
|
|
LinkManager &operator=(const LinkManager &) = delete;
|
|
|
|
LinkManager(LinkManager &&) = delete;
|
|
|
|
LinkManager &operator=(LinkManager &&) = delete;
|
|
|
|
~LinkManager() override;
|
|
|
|
|
2021-05-25 18:30:23 +02:00
|
|
|
enum class InternalLinkType : int32 { Background, Message, MessageDraft, UnknownDeepLink };
|
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;
|
|
|
|
|
|
|
|
virtual InternalLinkType get_type() 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-05-25 16:06:27 +02:00
|
|
|
struct LinkInfo {
|
|
|
|
bool is_internal_ = false;
|
|
|
|
bool is_tg_ = false;
|
2021-05-26 15:44:49 +02:00
|
|
|
string query_;
|
2021-05-25 16:06:27 +02:00
|
|
|
};
|
|
|
|
// returns information about the link
|
|
|
|
static LinkInfo get_link_info(Slice link);
|
|
|
|
|
|
|
|
// checks whether the link is a supported tg or t.me URL and parses it
|
|
|
|
static unique_ptr<InternalLink> parse_internal_link(Slice link);
|
|
|
|
|
2021-05-25 01:39:29 +02:00
|
|
|
void get_login_url_info(DialogId dialog_id, MessageId message_id, int32 button_id,
|
|
|
|
Promise<td_api::object_ptr<td_api::LoginUrlInfo>> &&promise);
|
|
|
|
|
|
|
|
void get_login_url(DialogId dialog_id, MessageId message_id, int32 button_id, bool allow_write_access,
|
|
|
|
Promise<td_api::object_ptr<td_api::httpUrl>> &&promise);
|
|
|
|
|
|
|
|
void get_link_login_url_info(const string &url, Promise<td_api::object_ptr<td_api::LoginUrlInfo>> &&promise);
|
|
|
|
|
|
|
|
void get_link_login_url(const string &url, bool allow_write_access,
|
|
|
|
Promise<td_api::object_ptr<td_api::httpUrl>> &&promise);
|
|
|
|
|
2021-05-25 01:24:30 +02:00
|
|
|
private:
|
|
|
|
void tear_down() override;
|
|
|
|
|
2021-05-25 16:06:27 +02:00
|
|
|
class InternalLinkBackground;
|
|
|
|
class InternalLinkMessage;
|
2021-05-25 18:05:17 +02:00
|
|
|
class InternalLinkMessageDraft;
|
2021-05-25 18:30:23 +02:00
|
|
|
class InternalLinkUnknownDeepLink;
|
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-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_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|