Add internalLinkTypeBuyStars.purpose.
This commit is contained in:
parent
f6c181bea8
commit
fbdec88dd1
@ -6544,8 +6544,10 @@ internalLinkTypeBotStartInGroup bot_username:string start_parameter:string admin
|
||||
//@link_name Name of the link
|
||||
internalLinkTypeBusinessChat link_name:string = InternalLinkType;
|
||||
|
||||
//@description The link is a link to the Telegram Star purchase section of the application @star_count The number of Telegram Stars that must be purchased by the user
|
||||
internalLinkTypeBuyStars star_count:int53 = InternalLinkType;
|
||||
//@description The link is a link to the Telegram Star purchase section of the application
|
||||
//@star_count The number of Telegram Stars that must be owned by the user
|
||||
//@purpose Purpose of Telegram Star purchase. Arbitrary string specified by the server, for example, "subs" if the Telegram Stars are required to extend channel subscriptions
|
||||
internalLinkTypeBuyStars star_count:int53 purpose:string = InternalLinkType;
|
||||
|
||||
//@description The link is a link to the change phone number section of the application
|
||||
internalLinkTypeChangePhoneNumber = InternalLinkType;
|
||||
|
@ -399,14 +399,15 @@ class LinkManager::InternalLinkBusinessChat final : public InternalLink {
|
||||
|
||||
class LinkManager::InternalLinkBuyStars final : public InternalLink {
|
||||
int64 star_count_;
|
||||
string purpose_;
|
||||
|
||||
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
|
||||
return td_api::make_object<td_api::internalLinkTypeBuyStars>(star_count_);
|
||||
return td_api::make_object<td_api::internalLinkTypeBuyStars>(star_count_, purpose_);
|
||||
}
|
||||
|
||||
public:
|
||||
explicit InternalLinkBuyStars(int64 star_count)
|
||||
: star_count_(clamp(star_count, static_cast<int64>(1), static_cast<int64>(1000000000000))) {
|
||||
explicit InternalLinkBuyStars(int64 star_count, const string &purpose)
|
||||
: star_count_(clamp(star_count, static_cast<int64>(1), static_cast<int64>(1000000000000))), purpose_(purpose) {
|
||||
}
|
||||
};
|
||||
|
||||
@ -1559,9 +1560,10 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
|
||||
// msg_url?url=<url>&text=<text>
|
||||
return get_internal_link_message_draft(get_arg("url"), get_arg("text"));
|
||||
} else if (path.size() == 1 && path[0] == "stars_topup") {
|
||||
// stars_topup?amount=<star_count>
|
||||
if (has_arg("amount")) {
|
||||
return td::make_unique<InternalLinkBuyStars>(to_integer<int64>(url_query.get_arg("amount")));
|
||||
// stars_topup?balance=<star_count>&purpose=<purpose>
|
||||
if (has_arg("balance")) {
|
||||
return td::make_unique<InternalLinkBuyStars>(to_integer<int64>(url_query.get_arg("balance")),
|
||||
url_query.get_arg("purpose").str());
|
||||
}
|
||||
}
|
||||
if (!path.empty() && !path[0].empty()) {
|
||||
@ -2121,7 +2123,7 @@ Result<string> LinkManager::get_internal_link_impl(const td_api::InternalLinkTyp
|
||||
if (link->star_count_ <= 0) {
|
||||
return Status::Error(400, "Invalid Telegram Star number provided");
|
||||
}
|
||||
return PSTRING() << "tg://stars_topup?amount=" << link->star_count_;
|
||||
return PSTRING() << "tg://stars_topup?balance=" << link->star_count_ << "&purpose=" << url_encode(link->purpose_);
|
||||
}
|
||||
case td_api::internalLinkTypeChangePhoneNumber::ID:
|
||||
if (!is_internal) {
|
||||
|
@ -224,8 +224,8 @@ static auto business_chat(const td::string &link_name) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeBusinessChat>(link_name);
|
||||
}
|
||||
|
||||
static auto buy_stars(td::int64 star_count) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeBuyStars>(star_count);
|
||||
static auto buy_stars(td::int64 star_count, const td::string &purpose) {
|
||||
return td::td_api::make_object<td::td_api::internalLinkTypeBuyStars>(star_count, purpose);
|
||||
}
|
||||
|
||||
static auto change_phone_number() {
|
||||
@ -1332,10 +1332,10 @@ TEST(Link, parse_internal_link_part4) {
|
||||
parse_internal_link("tg://settings/privacy", privacy_and_security_settings());
|
||||
|
||||
parse_internal_link("tg://stars_topup", unknown_deep_link("tg://stars_topup"));
|
||||
parse_internal_link("tg://stars_topup?amount=", unknown_deep_link("tg://stars_topup?amount="));
|
||||
parse_internal_link("tg://stars_topup?amount=test", buy_stars(1));
|
||||
parse_internal_link("tg://stars_topup?amount=10", buy_stars(10));
|
||||
parse_internal_link("tg://stars_topup?amount=100000000000", buy_stars(100000000000));
|
||||
parse_internal_link("tg://stars_topup?balance=", unknown_deep_link("tg://stars_topup?balance="));
|
||||
parse_internal_link("tg://stars_topup?balance=test", buy_stars(1, ""));
|
||||
parse_internal_link("tg://stars_topup?balance=10&purpose=%30test", buy_stars(10, "0test"));
|
||||
parse_internal_link("tg://stars_topup?balance=100000000000&purpose=subs", buy_stars(100000000000, "subs"));
|
||||
|
||||
parse_internal_link("username.t.me////0/a//s/as?start=", bot_start("username", ""));
|
||||
parse_internal_link("username.t.me?start=as", bot_start("username", "as"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user