From e2747b6c760bd8304e71f59c93a3fe824ffb16d3 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 21 Dec 2023 22:44:59 +0300 Subject: [PATCH] Add td_api::getThemedChatEmojiStatuses. --- td/generate/scheme/td_api.tl | 6 +++- td/telegram/SpecialStickerSetType.cpp | 13 +++++-- td/telegram/SpecialStickerSetType.h | 2 ++ td/telegram/StickersManager.cpp | 52 +++++++++++++++++++++++++-- td/telegram/StickersManager.h | 4 +++ td/telegram/Td.cpp | 6 ++++ td/telegram/Td.h | 2 ++ td/telegram/UpdatesManager.cpp | 1 + td/telegram/cli.cpp | 2 ++ 9 files changed, 81 insertions(+), 7 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 7355dc401..8de3b3ab4 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -8259,7 +8259,7 @@ getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot; toggleBotIsAddedToAttachmentMenu bot_user_id:int53 is_added:Bool allow_write_access:Bool = Ok; -//@description Returns up to 8 emoji statuses, which must be shown right after the default Premium Badge in the emoji status list +//@description Returns up to 8 emoji statuses, which must be shown right after the default Premium Badge in the emoji status list for users getThemedEmojiStatuses = EmojiStatuses; //@description Returns recent emoji statuses @@ -8272,6 +8272,10 @@ getDefaultEmojiStatuses = EmojiStatuses; clearRecentEmojiStatuses = Ok; +//@description Returns up to 8 emoji statuses, which must be shown in the emoji status list for chats +getThemedChatEmojiStatuses = EmojiStatuses; + + //@description Downloads a file from the cloud. Download progress and completion of the download will be notified through updateFile updates //@file_id Identifier of the file to download //@priority Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile/addFileToDownloads was called will be downloaded first diff --git a/td/telegram/SpecialStickerSetType.cpp b/td/telegram/SpecialStickerSetType.cpp index 8455a4fad..af303501e 100644 --- a/td/telegram/SpecialStickerSetType.cpp +++ b/td/telegram/SpecialStickerSetType.cpp @@ -37,6 +37,10 @@ SpecialStickerSetType SpecialStickerSetType::default_statuses() { return SpecialStickerSetType("default_statuses_sticker_set"); } +SpecialStickerSetType SpecialStickerSetType::default_channel_statuses() { + return SpecialStickerSetType("default_channel_statuses_sticker_set"); +} + SpecialStickerSetType SpecialStickerSetType::default_topic_icons() { return SpecialStickerSetType("default_topic_icons_sticker_set"); } @@ -63,12 +67,12 @@ SpecialStickerSetType::SpecialStickerSetType( case telegram_api::inputStickerSetEmojiDefaultStatuses::ID: *this = default_statuses(); break; + case telegram_api::inputStickerSetEmojiChannelDefaultStatuses::ID: + *this = default_channel_statuses(); + break; case telegram_api::inputStickerSetEmojiDefaultTopicIcons::ID: *this = default_topic_icons(); break; - case telegram_api::inputStickerSetEmojiChannelDefaultStatuses::ID: - *this = default_statuses(); - break; default: UNREACHABLE(); break; @@ -99,6 +103,9 @@ telegram_api::object_ptr SpecialStickerSetType::g if (*this == default_statuses()) { return telegram_api::make_object(); } + if (*this == default_channel_statuses()) { + return telegram_api::make_object(); + } if (*this == default_topic_icons()) { return telegram_api::make_object(); } diff --git a/td/telegram/SpecialStickerSetType.h b/td/telegram/SpecialStickerSetType.h index df7c1f0c0..2f68bc271 100644 --- a/td/telegram/SpecialStickerSetType.h +++ b/td/telegram/SpecialStickerSetType.h @@ -34,6 +34,8 @@ class SpecialStickerSetType { static SpecialStickerSetType default_statuses(); + static SpecialStickerSetType default_channel_statuses(); + static SpecialStickerSetType default_topic_icons(); string get_dice_emoji() const; diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index ab61f77c3..540bf21a8 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1695,6 +1695,10 @@ void StickersManager::init() { auto &sticker_set = add_special_sticker_set(SpecialStickerSetType::default_statuses()); load_special_sticker_set_info_from_binlog(sticker_set); } + { + auto &sticker_set = add_special_sticker_set(SpecialStickerSetType::default_channel_statuses()); + load_special_sticker_set_info_from_binlog(sticker_set); + } { auto &sticker_set = add_special_sticker_set(SpecialStickerSetType::default_topic_icons()); load_special_sticker_set_info_from_binlog(sticker_set); @@ -1917,6 +1921,10 @@ void StickersManager::on_load_special_sticker_set(const SpecialStickerSetType &t set_promises(pending_get_default_statuses_queries_); return; } + if (type == SpecialStickerSetType::default_channel_statuses()) { + set_promises(pending_get_default_channel_statuses_queries_); + return; + } if (type == SpecialStickerSetType::default_topic_icons()) { set_promises(pending_get_default_topic_icons_queries_); return; @@ -3066,8 +3074,8 @@ StickerSetId StickersManager::get_sticker_set_id(const tl_object_ptr> &&promise) { + TRY_STATUS_PROMISE(promise, G()->close_status()); + + auto &special_sticker_set = add_special_sticker_set(SpecialStickerSetType::default_channel_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_channel_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_channel_emoji_statuses, true, std::move(promise)); + } + })); + load_special_sticker_set(special_sticker_set); + return; + } + + vector custom_emoji_ids; + for (auto sticker_id : sticker_set->sticker_ids_) { + auto custom_emoji_id = get_custom_emoji_id(sticker_id); + if (!custom_emoji_id.is_valid()) { + LOG(ERROR) << "Ignore wrong sticker " << sticker_id; + continue; + } + custom_emoji_ids.push_back(custom_emoji_id.get()); + if (custom_emoji_ids.size() >= 8) { + break; + } + } + promise.set_value(td_api::make_object(std::move(custom_emoji_ids))); +} + void StickersManager::get_default_topic_icons(bool is_recursive, Promise> &&promise) { TRY_STATUS_PROMISE(promise, G()->close_status()); diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index 9803610d6..1cc8e00b3 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -130,6 +130,9 @@ class StickersManager final : public Actor { bool is_default_emoji_status(CustomEmojiId custom_emoji_id); + void get_default_channel_emoji_statuses(bool is_recursive, + Promise> &&promise); + void get_default_topic_icons(bool is_recursive, Promise> &&promise); void get_custom_emoji_stickers(vector custom_emoji_ids, bool use_database, @@ -1060,6 +1063,7 @@ class StickersManager final : public Actor { vector> pending_get_premium_gift_option_sticker_queries_; vector> pending_get_generic_animations_queries_; vector> pending_get_default_statuses_queries_; + vector> pending_get_default_channel_statuses_queries_; vector> pending_get_default_topic_icons_queries_; double next_click_animated_emoji_message_time_ = 0; diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 2e161ed0b..b2174b7a4 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7456,6 +7456,12 @@ void Td::on_request(uint64 id, const td_api::getThemedEmojiStatuses &request) { stickers_manager_->get_default_emoji_statuses(false, std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getThemedChatEmojiStatuses &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + stickers_manager_->get_default_channel_emoji_statuses(false, std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getDefaultEmojiStatuses &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 75c22113f..15d3bff4d 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1247,6 +1247,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::getThemedEmojiStatuses &request); + void on_request(uint64 id, const td_api::getThemedChatEmojiStatuses &request); + void on_request(uint64 id, const td_api::getDefaultEmojiStatuses &request); void on_request(uint64 id, const td_api::getRecentEmojiStatuses &request); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index cf92a4941..2dddaf8bd 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -2273,6 +2273,7 @@ void UpdatesManager::try_reload_data() { td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::premium_gifts()); td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::generic_animations()); td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::default_statuses()); + td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::default_channel_statuses()); td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::default_topic_icons()); td_->stickers_manager_->get_default_custom_emoji_stickers(StickerListType::DialogPhoto, true, Auto()); td_->stickers_manager_->get_default_custom_emoji_stickers(StickerListType::UserProfilePhoto, true, Auto()); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index ee4a35677..741b94012 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -5587,6 +5587,8 @@ class CliClient final : public Actor { send_request(td_api::make_object()); } else if (op == "cres") { send_request(td_api::make_object()); + } else if (op == "gtces") { + send_request(td_api::make_object()); } else if (op == "ccun") { ChatId chat_id; string username;