Support removing Fill backgrounds from default list.

This commit is contained in:
levlam 2021-06-08 01:10:19 +03:00
parent 36bcbcb418
commit c30ccd1e0d
5 changed files with 41 additions and 14 deletions

View File

@ -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

View File

@ -752,8 +752,13 @@ void BackgroundManager::remove_background(BackgroundId background_id, Promise<Un
std::move(promise));
});
if (!background->type.is_server()) {
return query_promise.set_value(Unit());
if (!background->type.has_file()) {
if (background->is_default) {
return td_->create_handler<UnsaveBackgroundQuery>(std::move(query_promise))
->send(telegram_api::make_object<telegram_api::inputWallPaperNoFile>(background_id.get()));
} else {
return query_promise.set_value(Unit());
}
}
td_->create_handler<UnsaveBackgroundQuery>(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<telegram_api::wallPaper>(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<telegram_api::object_ptr<telegram_api::account_WallPapers>> result) {

View File

@ -225,7 +225,7 @@ int64 BackgroundFill::get_id() const {
result = result * mul + static_cast<uint64>(bottom_color);
result = result * mul + static_cast<uint64>(third_color);
result = result * mul + static_cast<uint64>(fourth_color);
return 0x8000008000008 + static_cast<int64>(result % 0x8000008000008);
return static_cast<int64>(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) {

View File

@ -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);

View File

@ -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));