From 8fae960e43d1de2f37cdbc6c7b04d230c49c6efe Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 3 Jun 2022 17:31:48 +0300 Subject: [PATCH] Support premium stickers in secret chats. --- td/telegram/ContactsManager.cpp | 5 +++++ td/telegram/ContactsManager.h | 2 ++ td/telegram/MessageContent.cpp | 6 +++--- td/telegram/MessageContent.h | 2 +- td/telegram/MessagesManager.cpp | 3 ++- td/telegram/StickersManager.cpp | 2 +- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 039d3c0f1..09344f28c 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -14312,6 +14312,11 @@ bool ContactsManager::have_min_user(UserId user_id) const { return users_.count(user_id) > 0; } +bool ContactsManager::is_user_premium(UserId user_id) const { + auto u = get_user(user_id); + return u != nullptr && u->is_premium; +} + bool ContactsManager::is_user_deleted(UserId user_id) const { auto u = get_user(user_id); return u == nullptr || u->is_deleted; diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index fe881ba48..746f50e19 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -452,6 +452,8 @@ class ContactsManager final : public Actor { bool is_user_contact(UserId user_id, bool is_mutual = false) const; + bool is_user_premium(UserId user_id) const; + bool is_user_deleted(UserId user_id) const; bool is_user_support(UserId user_id) const; diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index b71ab0da3..908c694ea 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4033,7 +4033,7 @@ unique_ptr get_secret_message_content( Td *td, string message_text, unique_ptr file, tl_object_ptr &&media, vector> &&secret_entities, DialogId owner_dialog_id, - MultiPromiseActor &load_data_multipromise) { + MultiPromiseActor &load_data_multipromise, bool is_premium) { int32 constructor_id = media == nullptr ? secret_api::decryptedMessageMediaEmpty::ID : media->get_id(); auto caption = [&] { switch (constructor_id) { @@ -4194,8 +4194,8 @@ unique_ptr get_secret_message_content( auto external_document = move_tl_object_as(media); auto document = secret_to_telegram_document(*external_document); return get_document_message_content(td, std::move(document), owner_dialog_id, - FormattedText{std::move(message_text), std::move(entities)}, false, false, - &load_data_multipromise); + FormattedText{std::move(message_text), std::move(entities)}, false, + is_premium, &load_data_multipromise); } default: break; diff --git a/td/telegram/MessageContent.h b/td/telegram/MessageContent.h index 943c65385..9a65153ea 100644 --- a/td/telegram/MessageContent.h +++ b/td/telegram/MessageContent.h @@ -184,7 +184,7 @@ unique_ptr get_secret_message_content( Td *td, string message_text, unique_ptr file, tl_object_ptr &&media, vector> &&secret_entities, DialogId owner_dialog_id, - MultiPromiseActor &load_data_multipromise); + MultiPromiseActor &load_data_multipromise, bool is_premium); unique_ptr get_message_content(Td *td, FormattedText message_text, tl_object_ptr &&media, diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 41d119273..03bcd0461 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -13926,7 +13926,8 @@ void MessagesManager::on_get_secret_message(SecretChatId secret_chat_id, UserId message_info.flags = flags; message_info.content = get_secret_message_content( td_, std::move(message->message_), std::move(file), std::move(message->media_), std::move(message->entities_), - message_info.dialog_id, pending_secret_message->load_data_multipromise); + message_info.dialog_id, pending_secret_message->load_data_multipromise, + td_->contacts_manager_->is_user_premium(user_id)); add_secret_message(std::move(pending_secret_message), std::move(lock_promise)); } diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 05634cd1d..af53143b8 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -2691,7 +2691,7 @@ void StickersManager::create_sticker(FileId file_id, FileId premium_animation_fi } } s->format = format; - on_get_sticker(std::move(s), sticker != nullptr); + on_get_sticker(std::move(s), sticker != nullptr && load_data_multipromise_ptr == nullptr); } bool StickersManager::has_input_media(FileId sticker_file_id, bool is_secret) const {