Add getPremiumGiftOptionSticker.
This commit is contained in:
parent
2c7493978b
commit
d506c4732a
@ -6426,6 +6426,9 @@ getPremiumFeatures source:PremiumSource = PremiumFeatures;
|
||||
//@description Returns examples of premium stickers for demonstration purposes
|
||||
getPremiumStickers = Stickers;
|
||||
|
||||
//@description Returns a Premium gift option sticker by its position among Premium options @month_count Number of month the Telegram Premium subscription will be active
|
||||
getPremiumGiftOptionSticker month_count:int32 = Sticker;
|
||||
|
||||
//@description Informs TDLib that the user viewed detailed information about a Premium feature on the Premium features screen @feature The viewed premium feature
|
||||
viewPremiumFeature feature:PremiumFeature = Ok;
|
||||
|
||||
|
@ -1352,11 +1352,9 @@ void StickersManager::init() {
|
||||
auto &sticker_set = add_special_sticker_set(SpecialStickerSetType::animated_emoji_click());
|
||||
load_special_sticker_set_info_from_binlog(sticker_set);
|
||||
}
|
||||
if (!G()->is_test_dc()) {
|
||||
// add premium gifts sticker set
|
||||
auto &sticker_set = add_special_sticker_set(SpecialStickerSetType::premium_gifts());
|
||||
load_special_sticker_set_info_from_binlog(sticker_set);
|
||||
}
|
||||
// add premium gifts sticker set
|
||||
auto &sticker_set = add_special_sticker_set(SpecialStickerSetType::premium_gifts());
|
||||
load_special_sticker_set_info_from_binlog(sticker_set);
|
||||
|
||||
dice_emojis_str_ =
|
||||
G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01⚽\x01⚽️\x01🎰\x01🎳");
|
||||
@ -1570,6 +1568,7 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t
|
||||
return;
|
||||
}
|
||||
if (type == SpecialStickerSetType::premium_gifts()) {
|
||||
set_promises(pending_get_premium_gift_option_sticker_queries_);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2138,6 +2137,43 @@ tl_object_ptr<td_api::stickerSetInfo> StickersManager::get_sticker_set_info_obje
|
||||
std::move(stickers));
|
||||
}
|
||||
|
||||
FileId StickersManager::get_premium_gift_option_sticker_id(const StickerSet *sticker_set, int32 month_count) {
|
||||
if (sticker_set == nullptr || sticker_set->sticker_ids.empty() || month_count <= 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
int32 number = [month_count] {
|
||||
switch (month_count) {
|
||||
case 1:
|
||||
return 1;
|
||||
case 3:
|
||||
return 2;
|
||||
case 6:
|
||||
return 3;
|
||||
case 12:
|
||||
return 4;
|
||||
case 24:
|
||||
return 5;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}();
|
||||
|
||||
for (auto sticker_id : sticker_set->sticker_ids) {
|
||||
auto it = sticker_set->sticker_emojis_map_.find(sticker_id);
|
||||
if (it != sticker_set->sticker_emojis_map_.end()) {
|
||||
for (auto &emoji : it->second) {
|
||||
if (get_emoji_number(emoji) == number) {
|
||||
return sticker_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// there is no match; return the first sticker
|
||||
return sticker_set->sticker_ids[0];
|
||||
}
|
||||
|
||||
const StickersManager::StickerSet *StickersManager::get_animated_emoji_sticker_set() {
|
||||
if (td_->auth_manager_->is_bot() || disable_animated_emojis_) {
|
||||
return nullptr;
|
||||
@ -4819,6 +4855,33 @@ void StickersManager::get_all_animated_emojis(bool is_recursive,
|
||||
promise.set_value(td_api::make_object<td_api::emojis>(std::move(emojis)));
|
||||
}
|
||||
|
||||
void StickersManager::get_premium_gift_option_sticker(int32 month_count, bool is_recursive,
|
||||
Promise<td_api::object_ptr<td_api::sticker>> &&promise) {
|
||||
TRY_STATUS_PROMISE(promise, G()->close_status());
|
||||
|
||||
auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::premium_gifts());
|
||||
auto sticker_set = get_sticker_set(special_sticker_set.id_);
|
||||
if (sticker_set == nullptr || !sticker_set->was_loaded) {
|
||||
if (is_recursive) {
|
||||
return promise.set_value(nullptr);
|
||||
}
|
||||
|
||||
pending_get_premium_gift_option_sticker_queries_.push_back(PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), month_count, promise = std::move(promise)](Result<Unit> &&result) mutable {
|
||||
if (result.is_error()) {
|
||||
promise.set_error(result.move_as_error());
|
||||
} else {
|
||||
send_closure(actor_id, &StickersManager::get_premium_gift_option_sticker, month_count, true,
|
||||
std::move(promise));
|
||||
}
|
||||
}));
|
||||
load_special_sticker_set(special_sticker_set);
|
||||
return;
|
||||
}
|
||||
|
||||
promise.set_value(get_sticker_object(get_premium_gift_option_sticker_id(sticker_set, month_count)));
|
||||
}
|
||||
|
||||
void StickersManager::get_animated_emoji_click_sticker(const string &message_text, FullMessageId full_message_id,
|
||||
Promise<td_api::object_ptr<td_api::sticker>> &&promise) {
|
||||
if (disable_animated_emojis_ || td_->auth_manager_->is_bot()) {
|
||||
|
@ -91,6 +91,9 @@ class StickersManager final : public Actor {
|
||||
|
||||
void get_all_animated_emojis(bool is_recursive, Promise<td_api::object_ptr<td_api::emojis>> &&promise);
|
||||
|
||||
void get_premium_gift_option_sticker(int32 month_count, bool is_recursive,
|
||||
Promise<td_api::object_ptr<td_api::sticker>> &&promise);
|
||||
|
||||
void get_animated_emoji_click_sticker(const string &message_text, FullMessageId full_message_id,
|
||||
Promise<td_api::object_ptr<td_api::sticker>> &&promise);
|
||||
|
||||
@ -684,6 +687,8 @@ class StickersManager final : public Actor {
|
||||
|
||||
bool update_sticker_set_cache(const StickerSet *sticker_set, Promise<Unit> &promise);
|
||||
|
||||
static FileId get_premium_gift_option_sticker_id(const StickerSet *sticker_set, int32 position);
|
||||
|
||||
const StickerSet *get_animated_emoji_sticker_set();
|
||||
|
||||
static std::pair<FileId, int> get_animated_emoji_sticker(const StickerSet *sticker_set, const string &emoji);
|
||||
@ -880,6 +885,7 @@ class StickersManager final : public Actor {
|
||||
FlatHashMap<int64, unique_ptr<PendingSetStickerSetThumbnail>> pending_set_sticker_set_thumbnails_;
|
||||
|
||||
vector<Promise<Unit>> pending_get_animated_emoji_queries_;
|
||||
vector<Promise<Unit>> pending_get_premium_gift_option_sticker_queries_;
|
||||
|
||||
double next_click_animated_emoji_message_time_ = 0;
|
||||
double next_update_animated_emoji_clicked_time_ = 0;
|
||||
|
@ -7893,6 +7893,12 @@ void Td::on_request(uint64 id, const td_api::getPremiumStickers &request) {
|
||||
CREATE_REQUEST(SearchStickersRequest, "⭐️⭐️", 100);
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::getPremiumGiftOptionSticker &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
stickers_manager_->get_premium_gift_option_sticker(request.month_count_, false, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::viewPremiumFeature &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
|
@ -1299,6 +1299,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, const td_api::getPremiumStickers &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::getPremiumGiftOptionSticker &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::viewPremiumFeature &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::clickPremiumSubscriptionButton &request);
|
||||
|
@ -2790,6 +2790,8 @@ class CliClient final : public Actor {
|
||||
send_request(td_api::make_object<td_api::getAnimatedEmoji>(args));
|
||||
} else if (op == "gesu") {
|
||||
send_request(td_api::make_object<td_api::getEmojiSuggestionsUrl>(args));
|
||||
} else if (op == "gpgos") {
|
||||
send_request(td_api::make_object<td_api::getPremiumGiftOptionSticker>(to_integer<int32>(args)));
|
||||
} else if (op == "gsan") {
|
||||
send_request(td_api::make_object<td_api::getSavedAnimations>());
|
||||
} else if (op == "asan") {
|
||||
|
Loading…
Reference in New Issue
Block a user