Add internalLinkTypeStickerSet.
This commit is contained in:
parent
fb2c664f03
commit
feb01a71bb
@ -3007,7 +3007,7 @@ internalLinkTypeAuthenticationCode code:string = InternalLinkType;
|
||||
internalLinkTypeBackground background_name:string = InternalLinkType;
|
||||
|
||||
//@description The link is a chat invite link. Call checkChatInviteLink to process the link
|
||||
internalLinkTypeChatInviteLink = InternalLinkType;
|
||||
internalLinkTypeChatInvite = InternalLinkType;
|
||||
|
||||
//@description The link is a link to a Telegram message. Call getMessageLinkInfo to process the link
|
||||
internalLinkTypeMessage = InternalLinkType;
|
||||
@ -3020,6 +3020,9 @@ internalLinkTypeMessageDraft text:formattedText contains_link:Bool = InternalLin
|
||||
//-"This code can be used to allow someone to log in to your Telegram account. To confirm Telegram login, please go to Settings > Devices > Scan QR and scan the code" needs to be shown
|
||||
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 an unknown tg: link. Call getDeepLinkInfo to process the link
|
||||
internalLinkTypeUnknownDeepLink = InternalLinkType;
|
||||
|
||||
|
@ -55,13 +55,13 @@ class LinkManager::InternalLinkBackground : public InternalLink {
|
||||
}
|
||||
};
|
||||
|
||||
class LinkManager::InternalLinkDialogInviteLink : public InternalLink {
|
||||
class LinkManager::InternalLinkDialogInvite : public InternalLink {
|
||||
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
||||
return td_api::make_object<td_api::internalLinkTypeChatInviteLink>();
|
||||
return td_api::make_object<td_api::internalLinkTypeChatInvite>();
|
||||
}
|
||||
|
||||
InternalLinkType get_type() const final {
|
||||
return InternalLinkType::DialogInviteLink;
|
||||
return InternalLinkType::DialogInvite;
|
||||
}
|
||||
};
|
||||
|
||||
@ -103,6 +103,22 @@ class LinkManager::InternalLinkQrCodeAuthentication : public InternalLink {
|
||||
}
|
||||
};
|
||||
|
||||
class LinkManager::InternalLinkStickerSet : public InternalLink {
|
||||
string sticker_set_name_;
|
||||
|
||||
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
||||
return td_api::make_object<td_api::internalLinkTypeStickerSet>(sticker_set_name_);
|
||||
}
|
||||
|
||||
InternalLinkType get_type() const final {
|
||||
return InternalLinkType::StickerSet;
|
||||
}
|
||||
|
||||
public:
|
||||
explicit InternalLinkStickerSet(string sticker_set_name) : sticker_set_name_(std::move(sticker_set_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>();
|
||||
@ -434,7 +450,12 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
|
||||
} else if (path.size() == 1 && path[0] == "join") {
|
||||
// join?invite=abcdef
|
||||
if (has_arg("invite")) {
|
||||
return td::make_unique<InternalLinkDialogInviteLink>();
|
||||
return td::make_unique<InternalLinkDialogInvite>();
|
||||
}
|
||||
} else if (path.size() == 1 && path[0] == "addstickers") {
|
||||
// addstickers?set=name
|
||||
if (has_arg("set")) {
|
||||
return td::make_unique<InternalLinkStickerSet>(get_arg("set"));
|
||||
}
|
||||
} else if (path.size() == 1 && path[0] == "privatepost") {
|
||||
// privatepost?channel=123456789&msg_id=12345
|
||||
@ -498,12 +519,17 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
|
||||
} else if (path[0] == "joinchat") {
|
||||
if (path.size() >= 2 && !path[1].empty()) {
|
||||
// /joinchat/<link>
|
||||
return td::make_unique<InternalLinkDialogInviteLink>();
|
||||
return td::make_unique<InternalLinkDialogInvite>();
|
||||
}
|
||||
} else if (path[0] == "addstickers") {
|
||||
if (path.size() >= 2 && !path[1].empty()) {
|
||||
// /addstickers/<name>
|
||||
return td::make_unique<InternalLinkStickerSet>(path[1]);
|
||||
}
|
||||
} else if (path[0][0] == ' ' || path[0][0] == '+') {
|
||||
if (path[0].size() >= 2) {
|
||||
// /+<link>
|
||||
return td::make_unique<InternalLinkDialogInviteLink>();
|
||||
return td::make_unique<InternalLinkDialogInvite>();
|
||||
}
|
||||
} else if (path[0] == "bg") {
|
||||
if (path.size() >= 2 && !path[1].empty()) {
|
||||
|
@ -37,10 +37,11 @@ class LinkManager : public Actor {
|
||||
enum class InternalLinkType : int32 {
|
||||
AuthenticationCode,
|
||||
Background,
|
||||
DialogInviteLink,
|
||||
DialogInvite,
|
||||
Message,
|
||||
MessageDraft,
|
||||
QrCodeAuthentication,
|
||||
StickerSet,
|
||||
UnknownDeepLink
|
||||
};
|
||||
|
||||
@ -61,14 +62,6 @@ class LinkManager : public Actor {
|
||||
// checks whether the link is a valid tg, ton or HTTP(S) URL and returns it in a canonical form
|
||||
static Result<string> check_link(Slice link);
|
||||
|
||||
struct LinkInfo {
|
||||
bool is_internal_ = false;
|
||||
bool is_tg_ = false;
|
||||
string query_;
|
||||
};
|
||||
// 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);
|
||||
|
||||
@ -92,12 +85,21 @@ class LinkManager : public Actor {
|
||||
|
||||
class InternalLinkAuthenticationCode;
|
||||
class InternalLinkBackground;
|
||||
class InternalLinkDialogInviteLink;
|
||||
class InternalLinkDialogInvite;
|
||||
class InternalLinkMessage;
|
||||
class InternalLinkMessageDraft;
|
||||
class InternalLinkQrCodeAuthentication;
|
||||
class InternalLinkStickerSet;
|
||||
class InternalLinkUnknownDeepLink;
|
||||
|
||||
struct LinkInfo {
|
||||
bool is_internal_ = false;
|
||||
bool is_tg_ = false;
|
||||
string query_;
|
||||
};
|
||||
// returns information about the link
|
||||
static LinkInfo get_link_info(Slice link);
|
||||
|
||||
static unique_ptr<InternalLink> parse_tg_link_query(Slice query);
|
||||
|
||||
static unique_ptr<InternalLink> parse_t_me_link_query(Slice query);
|
||||
|
@ -70,8 +70,8 @@ TEST(Link, parse_internal_link) {
|
||||
auto background = [](td::string background_name) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeBackground>(background_name);
|
||||
};
|
||||
auto chat_invite_link = [] {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeChatInviteLink>();
|
||||
auto chat_invite = [] {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeChatInvite>();
|
||||
};
|
||||
auto message = [] {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeMessage>();
|
||||
@ -84,6 +84,9 @@ TEST(Link, parse_internal_link) {
|
||||
auto qr_code_authentication = []() {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeQrCodeAuthentication>();
|
||||
};
|
||||
auto sticker_set = [](td::string sticker_set_name) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeStickerSet>(sticker_set_name);
|
||||
};
|
||||
auto unknown_deep_link = [] {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeUnknownDeepLink>();
|
||||
};
|
||||
@ -258,28 +261,45 @@ TEST(Link, parse_internal_link) {
|
||||
parse_internal_link("t.me/joinchat?/abcdef", nullptr);
|
||||
parse_internal_link("t.me/joinchat/?abcdef", nullptr);
|
||||
parse_internal_link("t.me/joinchat/#abcdef", nullptr);
|
||||
parse_internal_link("t.me/joinchat/abacaba", chat_invite_link());
|
||||
parse_internal_link("t.me/joinchat/aba%20aba", chat_invite_link());
|
||||
parse_internal_link("t.me/joinchat/123456a", chat_invite_link());
|
||||
parse_internal_link("t.me/joinchat/12345678901", chat_invite_link());
|
||||
parse_internal_link("t.me/joinchat/123456", chat_invite_link());
|
||||
parse_internal_link("t.me/joinchat/123456/123123/12/31/a/s//21w/?asdas#test", chat_invite_link());
|
||||
parse_internal_link("t.me/joinchat/abacaba", chat_invite());
|
||||
parse_internal_link("t.me/joinchat/aba%20aba", chat_invite());
|
||||
parse_internal_link("t.me/joinchat/123456a", chat_invite());
|
||||
parse_internal_link("t.me/joinchat/12345678901", chat_invite());
|
||||
parse_internal_link("t.me/joinchat/123456", chat_invite());
|
||||
parse_internal_link("t.me/joinchat/123456/123123/12/31/a/s//21w/?asdas#test", chat_invite());
|
||||
|
||||
parse_internal_link("t.me/+?invite=abcdef", nullptr);
|
||||
parse_internal_link("t.me/+a", chat_invite_link());
|
||||
parse_internal_link("t.me/+a", chat_invite());
|
||||
parse_internal_link("t.me/+", nullptr);
|
||||
parse_internal_link("t.me/+/abcdef", nullptr);
|
||||
parse_internal_link("t.me/ ?/abcdef", nullptr);
|
||||
parse_internal_link("t.me/+?abcdef", nullptr);
|
||||
parse_internal_link("t.me/+#abcdef", nullptr);
|
||||
parse_internal_link("t.me/ abacaba", chat_invite_link());
|
||||
parse_internal_link("t.me/+aba%20aba", chat_invite_link());
|
||||
parse_internal_link("t.me/+123456a", chat_invite_link());
|
||||
parse_internal_link("t.me/%2012345678901", chat_invite_link());
|
||||
parse_internal_link("t.me/+123456", chat_invite_link());
|
||||
parse_internal_link("t.me/ 123456/123123/12/31/a/s//21w/?asdas#test", chat_invite_link());
|
||||
parse_internal_link("t.me/ abacaba", chat_invite());
|
||||
parse_internal_link("t.me/+aba%20aba", chat_invite());
|
||||
parse_internal_link("t.me/+123456a", chat_invite());
|
||||
parse_internal_link("t.me/%2012345678901", chat_invite());
|
||||
parse_internal_link("t.me/+123456", chat_invite());
|
||||
parse_internal_link("t.me/ 123456/123123/12/31/a/s//21w/?asdas#test", chat_invite());
|
||||
parse_internal_link("t.me/ /123456/123123/12/31/a/s//21w/?asdas#test", nullptr);
|
||||
|
||||
parse_internal_link("tg:join?invite=abcdef", chat_invite_link());
|
||||
parse_internal_link("tg:join?invite=abcdef", chat_invite());
|
||||
parse_internal_link("tg:join?invite=", unknown_deep_link());
|
||||
|
||||
parse_internal_link("t.me/addstickers?set=abcdef", nullptr);
|
||||
parse_internal_link("t.me/addstickers", nullptr);
|
||||
parse_internal_link("t.me/addstickers/", nullptr);
|
||||
parse_internal_link("t.me/addstickers//abcdef", nullptr);
|
||||
parse_internal_link("t.me/addstickers?/abcdef", nullptr);
|
||||
parse_internal_link("t.me/addstickers/?abcdef", nullptr);
|
||||
parse_internal_link("t.me/addstickers/#abcdef", nullptr);
|
||||
parse_internal_link("t.me/addstickers/abacaba", sticker_set());
|
||||
parse_internal_link("t.me/addstickers/aba%20aba", sticker_set());
|
||||
parse_internal_link("t.me/addstickers/123456a", sticker_set());
|
||||
parse_internal_link("t.me/addstickers/12345678901", sticker_set());
|
||||
parse_internal_link("t.me/addstickers/123456", sticker_set());
|
||||
parse_internal_link("t.me/addstickers/123456/123123/12/31/a/s//21w/?asdas#test", sticker_set());
|
||||
|
||||
parse_internal_link("tg:addstickers?set=abcdef", sticker_set());
|
||||
parse_internal_link("tg://addstickers?set=", unknown_deep_link());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user