Add internalLinkTypeTheme.
This commit is contained in:
parent
8d8a5d0b30
commit
ee8e0ec2ad
@ -3030,6 +3030,9 @@ internalLinkTypeQrCodeAuthentication = InternalLinkType;
|
||||
//@description The link is a link to a sticker set. Call searchStickerSet with the given sticker set name to process the link and show the sticker set @sticker_set_name Name of the sticker set
|
||||
internalLinkTypeStickerSet sticker_set_name:string = InternalLinkType;
|
||||
|
||||
//@description The link is a link to a theme. TDLib has no theme support yet @theme_name Name of the theme
|
||||
internalLinkTypeTheme theme_name:string = InternalLinkType;
|
||||
|
||||
//@description The link is an unknown tg: link. Call getDeepLinkInfo to process the link
|
||||
internalLinkTypeUnknownDeepLink = InternalLinkType;
|
||||
|
||||
|
@ -153,6 +153,22 @@ class LinkManager::InternalLinkStickerSet : public InternalLink {
|
||||
}
|
||||
};
|
||||
|
||||
class LinkManager::InternalLinkTheme : public InternalLink {
|
||||
string theme_name_;
|
||||
|
||||
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
||||
return td_api::make_object<td_api::internalLinkTypeBackground>(theme_name_);
|
||||
}
|
||||
|
||||
InternalLinkType get_type() const final {
|
||||
return InternalLinkType::Theme;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit InternalLinkTheme(string theme_name) : theme_name_(std::move(theme_name)) {
|
||||
}
|
||||
};
|
||||
|
||||
class LinkManager::InternalLinkUnknownDeepLink : public InternalLink {
|
||||
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
||||
return td_api::make_object<td_api::internalLinkTypeUnknownDeepLink>();
|
||||
@ -499,6 +515,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
|
||||
if (has_arg("lang")) {
|
||||
return td::make_unique<InternalLinkLanguage>(get_arg("lang"));
|
||||
}
|
||||
} else if (path.size() == 1 && path[0] == "addtheme") {
|
||||
// addtheme?slug=name
|
||||
if (has_arg("slug")) {
|
||||
return td::make_unique<InternalLinkTheme>(get_arg("slug"));
|
||||
}
|
||||
} else if (path.size() == 1 && path[0] == "confirmphone") {
|
||||
if (has_arg("hash") && has_arg("phone")) {
|
||||
// confirmphone?phone=<phone>&hash=<hash>
|
||||
@ -582,6 +603,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
|
||||
// /setlanguage/<name>
|
||||
return td::make_unique<InternalLinkLanguage>(path[1]);
|
||||
}
|
||||
} else if (path[0] == "addtheme") {
|
||||
if (path.size() >= 2 && !path[1].empty()) {
|
||||
// /addtheme/<name>
|
||||
return td::make_unique<InternalLinkTheme>(path[1]);
|
||||
}
|
||||
} else if (path[0] == "confirmphone") {
|
||||
if (has_arg("hash") && has_arg("phone")) {
|
||||
// /confirmphone?phone=<phone>&hash=<hash>
|
||||
|
@ -44,6 +44,7 @@ class LinkManager : public Actor {
|
||||
MessageDraft,
|
||||
QrCodeAuthentication,
|
||||
StickerSet,
|
||||
Theme,
|
||||
UnknownDeepLink
|
||||
};
|
||||
|
||||
@ -94,6 +95,7 @@ class LinkManager : public Actor {
|
||||
class InternalLinkMessageDraft;
|
||||
class InternalLinkQrCodeAuthentication;
|
||||
class InternalLinkStickerSet;
|
||||
class InternalLinkTheme;
|
||||
class InternalLinkUnknownDeepLink;
|
||||
|
||||
struct LinkInfo {
|
||||
|
@ -93,6 +93,9 @@ TEST(Link, parse_internal_link) {
|
||||
auto sticker_set = [](td::string sticker_set_name) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeStickerSet>(sticker_set_name);
|
||||
};
|
||||
auto theme = [](td::string theme_name) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeTheme>(theme_name);
|
||||
};
|
||||
auto unknown_deep_link = [] {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeUnknownDeepLink>();
|
||||
};
|
||||
@ -341,4 +344,22 @@ TEST(Link, parse_internal_link) {
|
||||
parse_internal_link("tg:setlanguage?lang=abcdef", language_pack("abcdef"));
|
||||
parse_internal_link("tg:setlanguage?lang=abc%30ef", language_pack("abc0ef"));
|
||||
parse_internal_link("tg://setlanguage?lang=", unknown_deep_link());
|
||||
|
||||
parse_internal_link("t.me/addtheme?slug=abcdef", nullptr);
|
||||
parse_internal_link("t.me/addtheme", nullptr);
|
||||
parse_internal_link("t.me/addtheme/", nullptr);
|
||||
parse_internal_link("t.me/addtheme//abcdef", nullptr);
|
||||
parse_internal_link("t.me/addtheme?/abcdef", nullptr);
|
||||
parse_internal_link("t.me/addtheme/?abcdef", nullptr);
|
||||
parse_internal_link("t.me/addtheme/#abcdef", nullptr);
|
||||
parse_internal_link("t.me/addtheme/abacaba", theme("abacaba"));
|
||||
parse_internal_link("t.me/addtheme/aba%20aba", theme("aba aba"));
|
||||
parse_internal_link("t.me/addtheme/123456a", theme("123456a"));
|
||||
parse_internal_link("t.me/addtheme/12345678901", theme("12345678901"));
|
||||
parse_internal_link("t.me/addtheme/123456", theme("123456"));
|
||||
parse_internal_link("t.me/addtheme/123456/123123/12/31/a/s//21w/?asdas#test", theme("123456"));
|
||||
|
||||
parse_internal_link("tg:addtheme?slug=abcdef", theme("abcdef"));
|
||||
parse_internal_link("tg:addtheme?slug=abc%30ef", theme("abc0ef"));
|
||||
parse_internal_link("tg://addtheme?slug=", unknown_deep_link());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user