From 18377ae3e7fc72b95259419e2bc08b0f4467f68a Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 23 Nov 2023 23:08:53 +0300 Subject: [PATCH] Add userFullInfo.set_chat_background. --- td/generate/scheme/td_api.tl | 7 ++++--- td/telegram/ContactsManager.cpp | 30 +++++++++++++++++++++++++++++- td/telegram/ContactsManager.h | 3 +++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 5f517586c..5e1474075 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -825,11 +825,12 @@ botInfo short_description:string description:string photo:photo animation:animat //@has_restricted_voice_and_video_note_messages True, if voice and video notes can't be sent or forwarded to the user //@has_pinned_stories True, if the user has pinned stories //@need_phone_number_privacy_exception True, if the current user needs to explicitly allow to share their phone number with the user when the method addContact is used +//@set_chat_background True, if the user set chat background for both chat users and it wasn't reverted yet //@bio A short user bio; may be null for bots //@premium_gift_options The list of available options for gifting Telegram Premium to the user //@group_in_common_count Number of group chats where both the other user and the current user are a member; 0 for the current user //@bot_info For bots, information about the bot; may be null if the user isn't a bot -userFullInfo personal_photo:chatPhoto photo:chatPhoto public_photo:chatPhoto block_list:BlockList can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool has_private_forwards:Bool has_restricted_voice_and_video_note_messages:Bool has_pinned_stories:Bool need_phone_number_privacy_exception:Bool bio:formattedText premium_gift_options:vector group_in_common_count:int32 bot_info:botInfo = UserFullInfo; +userFullInfo personal_photo:chatPhoto photo:chatPhoto public_photo:chatPhoto block_list:BlockList can_be_called:Bool supports_video_calls:Bool has_private_calls:Bool has_private_forwards:Bool has_restricted_voice_and_video_note_messages:Bool has_pinned_stories:Bool need_phone_number_privacy_exception:Bool set_chat_background:Bool bio:formattedText premium_gift_options:vector group_in_common_count:int32 bot_info:botInfo = UserFullInfo; //@description Represents a list of users @total_count Approximate total number of users found @user_ids A list of user identifiers users total_count:int32 user_ids:vector = Users; @@ -7752,8 +7753,8 @@ setChatPermissions chat_id:int53 permissions:chatPermissions = Ok; //@only_for_self Pass true to set background only for self; pass false to set background for both chat users. Background can be set for both users only by Telegram Premium users setChatBackground chat_id:int53 background:InputBackground type:BackgroundType dark_theme_dimming:int32 only_for_self:Bool = Ok; -//@description Restores background in a specific chat after it was changed by the other user. Can be called only from messageChatSetBackground messages with the currently set background that was set for both sides by the other user -//-Supported only in private and secret chats with non-deleted users +//@description Restores background in a specific chat after it was changed by the other user. Supported only in private and secret chats with non-deleted users. +//-Can be called only from messageChatSetBackground messages with the currently set background that was set for both sides by the other user if userFullInfo.set_chat_background //@chat_id Chat identifier revertChatBackground chat_id:int53 = Ok; diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index ceb098e9b..ad554e6ce 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -4625,6 +4625,7 @@ void ContactsManager::UserFull::store(StorerT &storer) const { STORE_FLAG(has_fallback_photo); STORE_FLAG(has_pinned_stories); STORE_FLAG(is_blocked_for_stories); + STORE_FLAG(wallpaper_overridden); END_STORE_FLAGS(); if (has_about) { store(about, storer); @@ -4709,6 +4710,7 @@ void ContactsManager::UserFull::parse(ParserT &parser) { PARSE_FLAG(has_fallback_photo); PARSE_FLAG(has_pinned_stories); PARSE_FLAG(is_blocked_for_stories); + PARSE_FLAG(wallpaper_overridden); END_PARSE_FLAGS(); if (has_about) { parse(about, parser); @@ -12967,6 +12969,7 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u on_update_user_full_common_chat_count(user_full, user_id, user->common_chats_count_); on_update_user_full_need_phone_number_privacy_exception(user_full, user_id, user->settings_->need_contacts_exception_); + on_update_user_full_wallpaper_overridden(user_full, user_id, user->wallpaper_overridden_); bool can_pin_messages = user->can_pin_message_; bool can_be_called = user->phone_calls_available_ && !user->phone_calls_private_; @@ -14357,6 +14360,30 @@ void ContactsManager::on_update_user_full_need_phone_number_privacy_exception( } } +void ContactsManager::on_update_user_wallpaper_overridden(UserId user_id, bool wallpaper_overridden) { + LOG(INFO) << "Receive " << wallpaper_overridden << " set chat background for " << user_id; + if (!user_id.is_valid()) { + LOG(ERROR) << "Receive invalid " << user_id; + return; + } + + UserFull *user_full = get_user_full_force(user_id); + if (user_full == nullptr) { + return; + } + on_update_user_full_wallpaper_overridden(user_full, user_id, wallpaper_overridden); + update_user_full(user_full, user_id, "on_update_user_wallpaper_overridden"); +} + +void ContactsManager::on_update_user_full_wallpaper_overridden(UserFull *user_full, UserId user_id, + bool wallpaper_overridden) const { + CHECK(user_full != nullptr); + if (user_full->wallpaper_overridden != wallpaper_overridden) { + user_full->wallpaper_overridden = wallpaper_overridden; + user_full->is_changed = true; + } +} + void ContactsManager::on_ignored_restriction_reasons_changed() { restricted_user_ids_.foreach([&](const UserId &user_id) { send_closure(G()->td(), &Td::send_update, get_update_user_object(user_id, get_user(user_id))); @@ -14651,6 +14678,7 @@ void ContactsManager::drop_user_full(UserId user_id) { user_full->supports_video_calls = false; user_full->has_private_calls = false; user_full->need_phone_number_privacy_exception = false; + user_full->wallpaper_overridden = false; user_full->about = string(); user_full->description = string(); user_full->description_photo = Photo(); @@ -19891,7 +19919,7 @@ tl_object_ptr ContactsManager::get_user_full_info_object(U get_chat_photo_object(td_->file_manager_.get(), user_full->fallback_photo), block_list_id.get_block_list_object(), user_full->can_be_called, user_full->supports_video_calls, user_full->has_private_calls, !user_full->private_forward_name.empty(), voice_messages_forbidden, user_full->has_pinned_stories, - user_full->need_phone_number_privacy_exception, std::move(bio_object), + user_full->need_phone_number_privacy_exception, user_full->wallpaper_overridden, std::move(bio_object), get_premium_payment_options_object(user_full->premium_gift_options), user_full->common_chat_count, std::move(bot_info)); } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 7f87c843c..a9729f908 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -213,6 +213,7 @@ class ContactsManager final : public Actor { void on_update_user_has_pinned_stories(UserId user_id, bool has_pinned_stories); void on_update_user_common_chat_count(UserId user_id, int32 common_chat_count); void on_update_user_need_phone_number_privacy_exception(UserId user_id, bool need_phone_number_privacy_exception); + void on_update_user_wallpaper_overridden(UserId user_id, bool wallpaper_overridden); void on_set_profile_photo(UserId user_id, tl_object_ptr &&photo, bool is_fallback, int64 old_photo_id, Promise &&promise); @@ -877,6 +878,7 @@ class ContactsManager final : public Actor { bool has_private_calls = false; bool can_pin_messages = true; bool need_phone_number_privacy_exception = false; + bool wallpaper_overridden = false; bool voice_messages_forbidden = false; bool has_pinned_stories = false; @@ -1493,6 +1495,7 @@ class ContactsManager final : public Actor { tl_object_ptr &&bot_menu_button); void on_update_user_full_need_phone_number_privacy_exception(UserFull *user_full, UserId user_id, bool need_phone_number_privacy_exception) const; + void on_update_user_full_wallpaper_overridden(UserFull *user_full, UserId user_id, bool wallpaper_overridden) const; UserPhotos *add_user_photos(UserId user_id); void send_get_user_photos_query(UserId user_id, const UserPhotos *user_photos);