Add td_api::getThemedPremiumStatuses.

This commit is contained in:
levlam 2022-09-02 15:02:37 +03:00
parent 899ceecab1
commit 2eba57276a
6 changed files with 58 additions and 2 deletions

View File

@ -5575,12 +5575,15 @@ getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot;
toggleBotIsAddedToAttachmentMenu bot_user_id:int53 is_added:Bool = Ok; toggleBotIsAddedToAttachmentMenu bot_user_id:int53 is_added:Bool = Ok;
//@description Returns default premium statuses //@description Returns up to 8 themed premium statuses, which color must be changed to the color of the Telegram Premium badge
getDefaultPremiumStatuses = PremiumStatuses; getThemedPremiumStatuses = PremiumStatuses;
//@description Returns recent premium statuses //@description Returns recent premium statuses
getRecentPremiumStatuses = PremiumStatuses; getRecentPremiumStatuses = PremiumStatuses;
//@description Returns default premium statuses
getDefaultPremiumStatuses = PremiumStatuses;
//@description Clears recent premium statuses //@description Clears recent premium statuses
clearRecentPremiumStatuses = Ok; clearRecentPremiumStatuses = Ok;

View File

@ -1667,6 +1667,7 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t
return; return;
} }
if (type == SpecialStickerSetType::default_statuses()) { if (type == SpecialStickerSetType::default_statuses()) {
set_promises(pending_get_default_statuses_queries_);
return; return;
} }
@ -5457,6 +5458,44 @@ void StickersManager::get_all_animated_emojis(bool is_recursive,
promise.set_value(td_api::make_object<td_api::emojis>(std::move(emojis))); promise.set_value(td_api::make_object<td_api::emojis>(std::move(emojis)));
} }
void StickersManager::get_default_emoji_statuses(bool is_recursive,
Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::default_statuses());
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(td_api::make_object<td_api::premiumStatuses>());
}
pending_get_default_statuses_queries_.push_back(PromiseCreator::lambda(
[actor_id = actor_id(this), 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_default_emoji_statuses, true, std::move(promise));
}
}));
load_special_sticker_set(special_sticker_set);
return;
}
vector<td_api::object_ptr<td_api::premiumStatus>> statuses;
for (auto sticker_id : sticker_set->sticker_ids_) {
auto custom_emoji_id = get_custom_emoji_id(sticker_id);
if (custom_emoji_id == 0) {
LOG(ERROR) << "Ignore wrong sticker " << sticker_id;
continue;
}
statuses.emplace_back(td_api::make_object<td_api::premiumStatus>(custom_emoji_id));
if (statuses.size() >= 8) {
break;
}
}
promise.set_value(td_api::make_object<td_api::premiumStatuses>(std::move(statuses)));
}
void StickersManager::load_custom_emoji_sticker_from_database(int64 custom_emoji_id, Promise<Unit> &&promise) { void StickersManager::load_custom_emoji_sticker_from_database(int64 custom_emoji_id, Promise<Unit> &&promise) {
CHECK(custom_emoji_id != 0); CHECK(custom_emoji_id != 0);
auto &queries = custom_emoji_load_queries_[custom_emoji_id]; auto &queries = custom_emoji_load_queries_[custom_emoji_id];

View File

@ -103,6 +103,8 @@ class StickersManager final : public Actor {
void get_all_animated_emojis(bool is_recursive, Promise<td_api::object_ptr<td_api::emojis>> &&promise); void get_all_animated_emojis(bool is_recursive, Promise<td_api::object_ptr<td_api::emojis>> &&promise);
void get_default_emoji_statuses(bool is_recursive, Promise<td_api::object_ptr<td_api::premiumStatuses>> &&promise);
void get_custom_emoji_stickers(vector<int64> &&document_ids, bool use_database, void get_custom_emoji_stickers(vector<int64> &&document_ids, bool use_database,
Promise<td_api::object_ptr<td_api::stickers>> &&promise); Promise<td_api::object_ptr<td_api::stickers>> &&promise);
@ -967,6 +969,8 @@ class StickersManager final : public Actor {
vector<Promise<Unit>> pending_get_animated_emoji_queries_; vector<Promise<Unit>> pending_get_animated_emoji_queries_;
vector<Promise<Unit>> pending_get_premium_gift_option_sticker_queries_; vector<Promise<Unit>> pending_get_premium_gift_option_sticker_queries_;
vector<Promise<Unit>> pending_get_default_statuses_queries_;
double next_click_animated_emoji_message_time_ = 0; double next_click_animated_emoji_message_time_ = 0;
double next_update_animated_emoji_clicked_time_ = 0; double next_update_animated_emoji_clicked_time_ = 0;
vector<PendingGetAnimatedEmojiClickSticker> pending_get_animated_emoji_click_stickers_; vector<PendingGetAnimatedEmojiClickSticker> pending_get_animated_emoji_click_stickers_;

View File

@ -6733,6 +6733,12 @@ void Td::on_request(uint64 id, const td_api::setPremiumStatus &request) {
contacts_manager_->set_emoji_status(EmojiStatus(request.premium_status_, request.duration_), std::move(promise)); contacts_manager_->set_emoji_status(EmojiStatus(request.premium_status_, request.duration_), std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::getThemedPremiumStatuses &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
stickers_manager_->get_default_emoji_statuses(false, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getDefaultPremiumStatuses &request) { void Td::on_request(uint64 id, const td_api::getDefaultPremiumStatuses &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_REQUEST_PROMISE(); CREATE_REQUEST_PROMISE();

View File

@ -1014,6 +1014,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::setPremiumStatus &request); void on_request(uint64 id, const td_api::setPremiumStatus &request);
void on_request(uint64 id, const td_api::getThemedPremiumStatuses &request);
void on_request(uint64 id, const td_api::getDefaultPremiumStatuses &request); void on_request(uint64 id, const td_api::getDefaultPremiumStatuses &request);
void on_request(uint64 id, const td_api::getRecentPremiumStatuses &request); void on_request(uint64 id, const td_api::getRecentPremiumStatuses &request);

View File

@ -4481,6 +4481,8 @@ class CliClient final : public Actor {
get_args(args, custom_emoji_id, until_date); get_args(args, custom_emoji_id, until_date);
send_request(td_api::make_object<td_api::setPremiumStatus>( send_request(td_api::make_object<td_api::setPremiumStatus>(
td_api::make_object<td_api::premiumStatus>(custom_emoji_id), until_date)); td_api::make_object<td_api::premiumStatus>(custom_emoji_id), until_date));
} else if (op == "gtps") {
send_request(td_api::make_object<td_api::getThemedPremiumStatuses>());
} else if (op == "gdps") { } else if (op == "gdps") {
send_request(td_api::make_object<td_api::getDefaultPremiumStatuses>()); send_request(td_api::make_object<td_api::getDefaultPremiumStatuses>());
} else if (op == "grps") { } else if (op == "grps") {