From 2eba57276a110e331e335f7027f6649578b4c8e0 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 2 Sep 2022 15:02:37 +0300 Subject: [PATCH] Add td_api::getThemedPremiumStatuses. --- td/generate/scheme/td_api.tl | 7 ++++-- td/telegram/StickersManager.cpp | 39 +++++++++++++++++++++++++++++++++ td/telegram/StickersManager.h | 4 ++++ td/telegram/Td.cpp | 6 +++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 2 ++ 6 files changed, 58 insertions(+), 2 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index db7101ddb..085ba5990 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -5575,12 +5575,15 @@ getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot; toggleBotIsAddedToAttachmentMenu bot_user_id:int53 is_added:Bool = Ok; -//@description Returns default premium statuses -getDefaultPremiumStatuses = PremiumStatuses; +//@description Returns up to 8 themed premium statuses, which color must be changed to the color of the Telegram Premium badge +getThemedPremiumStatuses = PremiumStatuses; //@description Returns recent premium statuses getRecentPremiumStatuses = PremiumStatuses; +//@description Returns default premium statuses +getDefaultPremiumStatuses = PremiumStatuses; + //@description Clears recent premium statuses clearRecentPremiumStatuses = Ok; diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 4f9f1b756..dee278e02 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1667,6 +1667,7 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t return; } if (type == SpecialStickerSetType::default_statuses()) { + set_promises(pending_get_default_statuses_queries_); return; } @@ -5457,6 +5458,44 @@ void StickersManager::get_all_animated_emojis(bool is_recursive, promise.set_value(td_api::make_object(std::move(emojis))); } +void StickersManager::get_default_emoji_statuses(bool is_recursive, + Promise> &&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()); + } + + pending_get_default_statuses_queries_.push_back(PromiseCreator::lambda( + [actor_id = actor_id(this), promise = std::move(promise)](Result &&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> 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(custom_emoji_id)); + if (statuses.size() >= 8) { + break; + } + } + promise.set_value(td_api::make_object(std::move(statuses))); +} + void StickersManager::load_custom_emoji_sticker_from_database(int64 custom_emoji_id, Promise &&promise) { CHECK(custom_emoji_id != 0); auto &queries = custom_emoji_load_queries_[custom_emoji_id]; diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index 0e21a8faa..7b539d15b 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -103,6 +103,8 @@ class StickersManager final : public Actor { void get_all_animated_emojis(bool is_recursive, Promise> &&promise); + void get_default_emoji_statuses(bool is_recursive, Promise> &&promise); + void get_custom_emoji_stickers(vector &&document_ids, bool use_database, Promise> &&promise); @@ -967,6 +969,8 @@ class StickersManager final : public Actor { vector> pending_get_animated_emoji_queries_; vector> pending_get_premium_gift_option_sticker_queries_; + vector> pending_get_default_statuses_queries_; + double next_click_animated_emoji_message_time_ = 0; double next_update_animated_emoji_clicked_time_ = 0; vector pending_get_animated_emoji_click_stickers_; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index b924640bf..46543219e 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -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)); } +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) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index d629f5557..7eabb8a6b 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -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::getThemedPremiumStatuses &request); + void on_request(uint64 id, const td_api::getDefaultPremiumStatuses &request); void on_request(uint64 id, const td_api::getRecentPremiumStatuses &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 3038ad46f..ac5eb4629 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4481,6 +4481,8 @@ class CliClient final : public Actor { get_args(args, custom_emoji_id, until_date); send_request(td_api::make_object( td_api::make_object(custom_emoji_id), until_date)); + } else if (op == "gtps") { + send_request(td_api::make_object()); } else if (op == "gdps") { send_request(td_api::make_object()); } else if (op == "grps") {