Add td_api::internalLinkTypePremiumGift.

This commit is contained in:
levlam 2023-12-26 21:01:33 +03:00
parent 65903180a4
commit 4a45265926
4 changed files with 34 additions and 0 deletions

View File

@ -5569,6 +5569,9 @@ internalLinkTypePhoneNumberConfirmation hash:string phone_number:string = Intern
//@description The link is a link to the Premium features screen of the application from which the user can subscribe to Telegram Premium. Call getPremiumFeatures with the given referrer to process the link @referrer Referrer specified in the link
internalLinkTypePremiumFeatures referrer:string = InternalLinkType;
//@description The link is a link to the screen for gifting Telegram Premium subscriptions to friends @referrer Referrer specified in the link
internalLinkTypePremiumGift referrer:string = InternalLinkType;
//@description The link is a link with a Telegram Premium gift code. Call checkPremiumGiftCode with the given code to process the link. If the code is valid and the user wants to apply it, then call applyPremiumGiftCode
//@code The Telegram Premium gift code
internalLinkTypePremiumGiftCode code:string = InternalLinkType;

View File

@ -561,6 +561,18 @@ class LinkManager::InternalLinkPremiumFeatures final : public InternalLink {
}
};
class LinkManager::InternalLinkPremiumGift final : public InternalLink {
string referrer_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
return td_api::make_object<td_api::internalLinkTypePremiumGift>(referrer_);
}
public:
explicit InternalLinkPremiumGift(string referrer) : referrer_(std::move(referrer)) {
}
};
class LinkManager::InternalLinkPremiumGiftCode final : public InternalLink {
string code_;
@ -1344,6 +1356,9 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
} else if (path.size() == 1 && path[0] == "premium_offer") {
// premium_offer?ref=<referrer>
return td::make_unique<InternalLinkPremiumFeatures>(get_arg("ref"));
} else if (path.size() == 1 && path[0] == "premium_multigift") {
// premium_multigift?ref=<referrer>
return td::make_unique<InternalLinkPremiumGift>(get_arg("ref"));
} else if (!path.empty() && path[0] == "settings") {
if (path.size() == 2 && path[1] == "auto_delete") {
// settings/auto_delete
@ -2180,6 +2195,13 @@ Result<string> LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp
}
return PSTRING() << "tg://premium_offer?ref=" << url_encode(link->referrer_);
}
case td_api::internalLinkTypePremiumGift::ID: {
auto link = static_cast<const td_api::internalLinkTypePremiumGift *>(type_ptr);
if (!is_internal) {
return Status::Error("HTTP link is unavailable for the link type");
}
return PSTRING() << "tg://premium_multigift?ref=" << url_encode(link->referrer_);
}
case td_api::internalLinkTypePremiumGiftCode::ID: {
auto link = static_cast<const td_api::internalLinkTypePremiumGiftCode *>(type_ptr);
if (is_internal) {

View File

@ -141,6 +141,7 @@ class LinkManager final : public Actor {
class InternalLinkMessageDraft;
class InternalLinkPassportDataRequest;
class InternalLinkPremiumFeatures;
class InternalLinkPremiumGift;
class InternalLinkPremiumGiftCode;
class InternalLinkPrivacyAndSecuritySettings;
class InternalLinkProxy;

View File

@ -291,6 +291,10 @@ static auto premium_features(const td::string &referrer) {
return td::td_api::make_object<td::td_api::internalLinkTypePremiumFeatures>(referrer);
}
static auto premium_gift(const td::string &referrer) {
return td::td_api::make_object<td::td_api::internalLinkTypePremiumGift>(referrer);
}
static auto premium_gift_code(const td::string &code) {
return td::td_api::make_object<td::td_api::internalLinkTypePremiumGiftCode>(code);
}
@ -1237,6 +1241,10 @@ TEST(Link, parse_internal_link_part4) {
parse_internal_link("tg:premium_offer?ref=abc%30ef", premium_features("abc0ef"));
parse_internal_link("tg://premium_offer?ref=", premium_features(""));
parse_internal_link("tg:premium_multigift?ref=abcdef", premium_gift("abcdef"));
parse_internal_link("tg:premium_multigift?ref=abc%30ef", premium_gift("abc0ef"));
parse_internal_link("tg://premium_multigift?ref=", premium_gift(""));
parse_internal_link("tg://settings", settings());
parse_internal_link("tg://setting", unknown_deep_link("tg://setting"));
parse_internal_link("tg://settings?asdsa?D?SADasD?asD", settings());