From c30ccd1e0dfa16e70996892559a81f87bdd6cf25 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 8 Jun 2021 01:10:19 +0300 Subject: [PATCH] Support removing Fill backgrounds from default list. --- td/generate/scheme/td_api.tl | 2 +- td/telegram/BackgroundManager.cpp | 45 +++++++++++++++++++++++-------- td/telegram/BackgroundType.cpp | 4 +-- td/telegram/BackgroundType.h | 3 +++ td/telegram/GroupCallManager.cpp | 1 + 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 5edbdf8b9..53773f53f 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2164,7 +2164,7 @@ groupCallRecentSpeaker participant_id:MessageSender is_speaking:Bool = GroupCall //@recent_speakers Recently speaking users in the group call //@is_my_video_enabled True, if the current user's video is enabled //@is_my_video_paused True, if the current user's video is paused -//@can_start_video True, if video can be enabled by group call participants +//@can_start_video True, if video can be enabled by group call participants. This flag is generally useless after the user has already joined the group call //@mute_new_participants True, if only group call administrators can unmute new participants //@can_change_mute_new_participants True, if the current user can enable or disable mute_new_participants setting //@record_duration Duration of the ongoing group call recording, in seconds; 0 if none. An updateGroupCall update is not triggered when value of this field changes, but the same recording goes on diff --git a/td/telegram/BackgroundManager.cpp b/td/telegram/BackgroundManager.cpp index 86b622802..7352c4fc9 100644 --- a/td/telegram/BackgroundManager.cpp +++ b/td/telegram/BackgroundManager.cpp @@ -752,8 +752,13 @@ void BackgroundManager::remove_background(BackgroundId background_id, Promisetype.is_server()) { - return query_promise.set_value(Unit()); + if (!background->type.has_file()) { + if (background->is_default) { + return td_->create_handler(std::move(query_promise)) + ->send(telegram_api::make_object(background_id.get())); + } else { + return query_promise.set_value(Unit()); + } } td_->create_handler(std::move(query_promise)) @@ -906,18 +911,36 @@ BackgroundId BackgroundManager::on_get_background(BackgroundId expected_backgrou } auto is_default = (wallpaper->flags_ & telegram_api::wallPaperNoFile::DEFAULT_MASK) != 0; - auto is_dark = (wallpaper->flags_ & telegram_api::wallPaperNoFile::DARK_MASK) != 0; + if (!is_default) { + LOG(ERROR) << "Receive non-default wallPaperNoFile: " << to_string(wallpaper); + return BackgroundId(); + } - return add_fill_background(BackgroundFill(settings.get()), is_default, is_dark); + auto background_id = BackgroundId(wallpaper->id_); + if (!background_id.is_valid() || BackgroundFill::is_valid_id(wallpaper->id_)) { + LOG(ERROR) << "Receive " << to_string(wallpaper); + return BackgroundId(); + } + + Background background; + background.id = background_id; + background.is_creator = false; + background.is_default = true; + background.is_dark = (wallpaper->flags_ & telegram_api::wallPaperNoFile::DARK_MASK) != 0; + background.type = BackgroundType(BackgroundFill(settings.get())); + background.name = background.type.get_link(); + add_background(background); + + return background_id; } auto wallpaper = move_tl_object_as(wallpaper_ptr); - auto id = BackgroundId(wallpaper->id_); - if (!id.is_valid()) { + auto background_id = BackgroundId(wallpaper->id_); + if (!background_id.is_valid()) { LOG(ERROR) << "Receive " << to_string(wallpaper); return BackgroundId(); } - if (expected_background_id.is_valid() && id != expected_background_id) { + if (expected_background_id.is_valid() && background_id != expected_background_id) { LOG(ERROR) << "Expected " << expected_background_id << ", but receive " << to_string(wallpaper); } if (is_background_name_local(wallpaper->slug_) || BackgroundFill::is_valid_id(wallpaper->id_)) { @@ -945,7 +968,7 @@ BackgroundId BackgroundManager::on_get_background(BackgroundId expected_backgrou CHECK(document.type == Document::Type::General); // guaranteed by is_background parameter to on_get_document Background background; - background.id = id; + background.id = background_id; background.access_hash = wallpaper->access_hash_; background.is_creator = (flags & telegram_api::wallPaper::CREATOR_MASK) != 0; background.is_default = (flags & telegram_api::wallPaper::DEFAULT_MASK) != 0; @@ -957,17 +980,17 @@ BackgroundId BackgroundManager::on_get_background(BackgroundId expected_backgrou if (!expected_background_name.empty() && background.name != expected_background_name) { LOG(ERROR) << "Expected background " << expected_background_name << ", but receive " << background.name; - name_to_background_id_.emplace(expected_background_name, id); + name_to_background_id_.emplace(expected_background_name, background_id); } if (G()->parameters().use_file_db) { - LOG(INFO) << "Save " << id << " to database with name " << background.name; + LOG(INFO) << "Save " << background_id << " to database with name " << background.name; CHECK(!is_background_name_local(background.name)); G()->td_db()->get_sqlite_pmc()->set(get_background_name_database_key(background.name), log_event_store(background).as_slice().str(), Auto()); } - return id; + return background_id; } void BackgroundManager::on_get_backgrounds(Result> result) { diff --git a/td/telegram/BackgroundType.cpp b/td/telegram/BackgroundType.cpp index 06c3cd7ed..dd9173ba5 100644 --- a/td/telegram/BackgroundType.cpp +++ b/td/telegram/BackgroundType.cpp @@ -225,7 +225,7 @@ int64 BackgroundFill::get_id() const { result = result * mul + static_cast(bottom_color); result = result * mul + static_cast(third_color); result = result * mul + static_cast(fourth_color); - return 0x8000008000008 + static_cast(result % 0x8000008000008); + return static_cast(result % 0x8000008000008); } default: UNREACHABLE(); @@ -249,7 +249,7 @@ bool BackgroundFill::is_dark() const { } bool BackgroundFill::is_valid_id(int64 id) { - return 0 < id && id < 0x8000008000008 * 2; + return 0 < id && id < 0x8000008000008; } bool operator==(const BackgroundFill &lhs, const BackgroundFill &rhs) { diff --git a/td/telegram/BackgroundType.h b/td/telegram/BackgroundType.h index e9be88e36..c8072c9b5 100644 --- a/td/telegram/BackgroundType.h +++ b/td/telegram/BackgroundType.h @@ -78,6 +78,9 @@ struct BackgroundType { bool is_server() const { return type == Type::Wallpaper || type == Type::Pattern; } + bool has_file() const { + return type == Type::Wallpaper || type == Type::Pattern; + } void apply_parameters_from_link(Slice name); diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index 4f5f4188b..a2cea7e57 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -2478,6 +2478,7 @@ void GroupCallManager::join_group_call(GroupCallId group_call_id, DialogId as_di // it contains reasonable default "!call.mute_new_participants || call.can_be_managed" participant.server_is_muted_by_admin = !group_call->can_self_unmute && !can_manage_group_call(input_group_call_id); participant.server_is_muted_by_themselves = is_muted && !participant.server_is_muted_by_admin; + participant.can_enable_video = !participant.server_is_muted_by_admin && group_call->can_start_video; participant.is_just_joined = !is_rejoin; participant.is_fake = true; int diff = process_group_call_participant(input_group_call_id, std::move(participant));