Add support for separate background for dark theme.

GitOrigin-RevId: e5315453db1a7388f240dbefd4eeac6d8c9929c8
This commit is contained in:
levlam 2019-06-18 01:39:57 +03:00
parent 5273b48afe
commit c874b1d4b1
7 changed files with 182 additions and 137 deletions

View File

@ -480,9 +480,9 @@ Changes in 1.1.0:
* Added parameter `as_album` to method `getPublicMessageLink` to enable getting public links for media albums.
* Added field `html` to class `publicMessageLink`, containing HTML-code for message/message album embedding.
* Added parameter `only_if_pending` to method `cancelDownloadFile` to allow keeping already started downloads.
* Methods `createPrivateChat`, `createBasciGroupChat`, `createSupergroupChat` and `createSecretChat`
can now be called without a prior call to `getUser`/`getBasicGroup`/`getSupergorup`/`getSecretChat`.
* Added parameter `force` to methods `createPrivateChat`, `createBasciGroupChat` and `createSupergroupChat` to allow
* Methods `createPrivateChat`, `createBasicGroupChat`, `createSupergroupChat` and `createSecretChat`
can now be called without a prior call to `getUser`/`getBasicGroup`/`getSupergroup`/`getSecretChat`.
* Added parameter `force` to methods `createPrivateChat`, `createBasicGroupChat` and `createSupergroupChat` to allow
creating a chat without network requests.
* Numerous optimizations and bug fixes.

View File

@ -1966,7 +1966,7 @@ backgroundTypeSolid color:int32 = BackgroundType;
//@description Describes a chat background
//@id Unique background identifier
//@is_default True, if this is one of default backgrounds
//@is_dark True, if this background is dark and is recommended to be used with dark theme
//@is_dark True, if the background is dark and is recommended to be used with dark theme
//@name Unique background name
//@document Document with the background; may be null. Null only for solid backgrounds
//@type Type of the background
@ -2701,8 +2701,8 @@ updateFavoriteStickers sticker_ids:vector<int32> = Update;
//@description The list of saved animations was updated @animation_ids The new list of file identifiers of saved animations
updateSavedAnimations animation_ids:vector<int32> = Update;
//@description The selected background has changed @background The new selected background; may be null
updateSelectedBackground background:background = Update;
//@description The selected background has changed @for_dark_theme True, if background for dark theme has changed @background The new selected background; may be null
updateSelectedBackground for_dark_theme:Bool background:background = Update;
//@description Some language pack strings have been updated @localization_target Localization target to which the language pack belongs @language_pack_id Identifier of the updated language pack @strings List of changed language pack strings
updateLanguagePackStrings localization_target:string language_pack_id:string strings:vector<languagePackString> = Update;
@ -3651,8 +3651,8 @@ deleteSavedCredentials = Ok;
getSupportUser = User;
//@description Returns backgrounds installed by the user
getBackgrounds = Backgrounds;
//@description Returns backgrounds installed by the user @for_dark_theme True, if the backgrounds needs to be ordered for dark theme
getBackgrounds for_dark_theme:Bool = Backgrounds;
//@description Constructs a persistent HTTP URL for a background @name Background name @type Background type
getBackgroundUrl name:string type:BackgroundType = HttpUrl;
@ -3661,8 +3661,8 @@ getBackgroundUrl name:string type:BackgroundType = HttpUrl;
searchBackground name:string = Background;
//@description Changes selected by the user background; adds background to the list of installed backgrounds
//@background The input background to use, null for solid backgrounds @type Background type
setBackground background:InputBackground type:BackgroundType = Background;
//@background The input background to use, null for solid backgrounds @type Background type @for_dark_theme True, if the background is chosen for dark theme
setBackground background:InputBackground type:BackgroundType for_dark_theme:Bool = Background;
//@description Removes background from the list of installed backgrounds @background_id The background indentifier
removeBackground background_id:int64 = Ok;

Binary file not shown.

View File

@ -125,15 +125,18 @@ class UploadBackgroundQuery : public Td::ResultHandler {
Promise<Unit> promise_;
FileId file_id_;
BackgroundType type_;
bool for_dark_theme_;
public:
explicit UploadBackgroundQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(FileId file_id, tl_object_ptr<telegram_api::InputFile> &&input_file, const BackgroundType &type) {
void send(FileId file_id, tl_object_ptr<telegram_api::InputFile> &&input_file, const BackgroundType &type,
bool for_dark_theme) {
CHECK(input_file != nullptr);
file_id_ = file_id;
type_ = type;
for_dark_theme_ = for_dark_theme;
string mime_type = type.type == BackgroundType::Type::Pattern ? "image/png" : "image/jpeg";
send_query(G()->net_query_creator().create(create_storer(
telegram_api::account_uploadWallPaper(std::move(input_file), mime_type, get_input_wallpaper_settings(type)))));
@ -145,7 +148,8 @@ class UploadBackgroundQuery : public Td::ResultHandler {
return on_error(id, result_ptr.move_as_error());
}
td->background_manager_->on_uploaded_background_file(file_id_, type_, result_ptr.move_as_ok(), std::move(promise_));
td->background_manager_->on_uploaded_background_file(file_id_, type_, for_dark_theme_, result_ptr.move_as_ok(),
std::move(promise_));
}
void on_error(uint64 id, Status status) override {
@ -305,19 +309,21 @@ class BackgroundManager::BackgroundLogEvent {
};
void BackgroundManager::start_up() {
// G()->td_db()->get_binlog_pmc()->erase(get_background_database_key());
auto logevent_string = G()->td_db()->get_binlog_pmc()->get(get_background_database_key());
for (int i = 0; i < 2; i++) {
bool for_dark_theme = static_cast<bool>(i);
// G()->td_db()->get_binlog_pmc()->erase(get_background_database_key(for_dark_theme));
auto logevent_string = G()->td_db()->get_binlog_pmc()->get(get_background_database_key(for_dark_theme));
if (!logevent_string.empty()) {
BackgroundLogEvent logevent;
log_event_parse(logevent, logevent_string).ensure();
CHECK(logevent.background_id_.is_valid());
set_background_id_ = logevent.background_id_;
set_background_type_ = logevent.set_type_;
set_background_id_[for_dark_theme] = logevent.background_id_;
set_background_type_[for_dark_theme] = logevent.set_type_;
auto *background = add_background(set_background_id_);
auto *background = add_background(set_background_id_[for_dark_theme]);
CHECK(!background->id.is_valid());
background->id = set_background_id_;
background->id = set_background_id_[for_dark_theme];
background->access_hash = logevent.access_hash_;
background->is_creator = logevent.is_creator_;
background->is_default = logevent.is_default_;
@ -337,7 +343,8 @@ void BackgroundManager::start_up() {
}
}
send_update_selected_background();
send_update_selected_background(for_dark_theme);
}
}
void BackgroundManager::tear_down() {
@ -443,12 +450,14 @@ BackgroundId BackgroundManager::search_background(const string &name, Promise<Un
return BackgroundId();
}
td_api::object_ptr<td_api::updateSelectedBackground> BackgroundManager::get_update_selected_background_object() const {
return td_api::make_object<td_api::updateSelectedBackground>(get_background_object(set_background_id_));
td_api::object_ptr<td_api::updateSelectedBackground> BackgroundManager::get_update_selected_background_object(
bool for_dark_theme) const {
return td_api::make_object<td_api::updateSelectedBackground>(
for_dark_theme, get_background_object(set_background_id_[for_dark_theme], for_dark_theme));
}
void BackgroundManager::send_update_selected_background() const {
send_closure(G()->td(), &Td::send_update, get_update_selected_background_object());
void BackgroundManager::send_update_selected_background(bool for_dark_theme) const {
send_closure(G()->td(), &Td::send_update, get_update_selected_background_object(for_dark_theme));
}
Result<FileId> BackgroundManager::prepare_input_file(const tl_object_ptr<td_api::InputFile> &input_file) {
@ -487,7 +496,8 @@ BackgroundId BackgroundManager::add_solid_background(int32 color) {
}
BackgroundId BackgroundManager::set_background(const td_api::InputBackground *input_background,
const td_api::BackgroundType *background_type, Promise<Unit> &&promise) {
const td_api::BackgroundType *background_type, bool for_dark_theme,
Promise<Unit> &&promise) {
auto r_type = get_background_type(background_type);
if (r_type.is_error()) {
promise.set_error(r_type.move_as_error());
@ -497,8 +507,8 @@ BackgroundId BackgroundManager::set_background(const td_api::InputBackground *in
auto type = r_type.move_as_ok();
if (type.type == BackgroundType::Type::Solid) {
auto background_id = add_solid_background(type.color);
if (set_background_id_ != background_id) {
set_background_id(background_id, type);
if (set_background_id_[for_dark_theme] != background_id) {
set_background_id(background_id, type, for_dark_theme);
}
promise.set_value(Unit());
return background_id;
@ -522,15 +532,15 @@ BackgroundId BackgroundManager::set_background(const td_api::InputBackground *in
auto it = file_id_to_background_id_.find(file_id);
if (it != file_id_to_background_id_.end()) {
return set_background(it->second, type, std::move(promise));
return set_background(it->second, type, for_dark_theme, std::move(promise));
}
upload_background_file(file_id, type, std::move(promise));
upload_background_file(file_id, type, for_dark_theme, std::move(promise));
break;
}
case td_api::inputBackgroundRemote::ID: {
auto background_remote = static_cast<const td_api::inputBackgroundRemote *>(input_background);
return set_background(BackgroundId(background_remote->background_id_), type, std::move(promise));
return set_background(BackgroundId(background_remote->background_id_), type, for_dark_theme, std::move(promise));
}
default:
UNREACHABLE();
@ -539,7 +549,7 @@ BackgroundId BackgroundManager::set_background(const td_api::InputBackground *in
}
BackgroundId BackgroundManager::set_background(BackgroundId background_id, const BackgroundType &type,
Promise<Unit> &&promise) {
bool for_dark_theme, Promise<Unit> &&promise) {
auto *background = get_background(background_id);
if (background == nullptr) {
promise.set_error(Status::Error(400, "Background to set not found"));
@ -549,24 +559,24 @@ BackgroundId BackgroundManager::set_background(BackgroundId background_id, const
promise.set_error(Status::Error(400, "Background type mismatch"));
return BackgroundId();
}
if (set_background_id_ == background_id) {
if (set_background_id_[for_dark_theme] == background_id) {
promise.set_value(Unit());
return background_id;
}
LOG(INFO) << "Install " << background_id << " with " << type;
auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), background_id, type, promise = std::move(promise)](Result<Unit> &&result) mutable {
send_closure(actor_id, &BackgroundManager::on_installed_background, background_id, type, std::move(result),
std::move(promise));
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), background_id, type, for_dark_theme,
promise = std::move(promise)](Result<Unit> &&result) mutable {
send_closure(actor_id, &BackgroundManager::on_installed_background, background_id, type, for_dark_theme,
std::move(result), std::move(promise));
});
td_->create_handler<InstallBackgroundQuery>(std::move(query_promise))
->send(background_id, background->access_hash, type);
return BackgroundId();
}
void BackgroundManager::on_installed_background(BackgroundId background_id, BackgroundType type, Result<Unit> &&result,
Promise<Unit> &&promise) {
void BackgroundManager::on_installed_background(BackgroundId background_id, BackgroundType type, bool for_dark_theme,
Result<Unit> &&result, Promise<Unit> &&promise) {
if (result.is_error()) {
return promise.set_error(result.move_as_error());
}
@ -575,44 +585,46 @@ void BackgroundManager::on_installed_background(BackgroundId background_id, Back
if (it == installed_background_ids_.end()) {
installed_background_ids_.insert(installed_background_ids_.begin(), background_id);
}
set_background_id(background_id, type);
set_background_id(background_id, type, for_dark_theme);
promise.set_value(Unit());
}
string BackgroundManager::get_background_database_key() {
return "bg";
string BackgroundManager::get_background_database_key(bool for_dark_theme) {
return for_dark_theme ? "bgd" : "bg";
}
void BackgroundManager::save_background_id() const {
string key = get_background_database_key();
if (set_background_id_.is_valid()) {
const Background *background = get_background(set_background_id_);
void BackgroundManager::save_background_id(bool for_dark_theme) const {
string key = get_background_database_key(for_dark_theme);
auto background_id = set_background_id_[for_dark_theme];
if (background_id.is_valid()) {
const Background *background = get_background(background_id);
CHECK(background != nullptr);
BackgroundLogEvent logevent{set_background_id_, background->access_hash, background->name,
BackgroundLogEvent logevent{background_id, background->access_hash, background->name,
background->file_id, background->is_creator, background->is_default,
background->is_dark, background->type, set_background_type_};
background->is_dark, background->type, set_background_type_[for_dark_theme]};
G()->td_db()->get_binlog_pmc()->set(key, log_event_store(logevent).as_slice().str());
} else {
G()->td_db()->get_binlog_pmc()->erase(key);
}
}
void BackgroundManager::set_background_id(BackgroundId background_id, const BackgroundType &type) {
if (background_id == set_background_id_ && set_background_type_ == type) {
void BackgroundManager::set_background_id(BackgroundId background_id, const BackgroundType &type, bool for_dark_theme) {
if (background_id == set_background_id_[for_dark_theme] && set_background_type_[for_dark_theme] == type) {
return;
}
set_background_id_ = background_id;
set_background_type_ = type;
set_background_id_[for_dark_theme] = background_id;
set_background_type_[for_dark_theme] = type;
save_background_id();
send_update_selected_background();
save_background_id(for_dark_theme);
send_update_selected_background(for_dark_theme);
}
void BackgroundManager::upload_background_file(FileId file_id, const BackgroundType &type, Promise<Unit> &&promise) {
void BackgroundManager::upload_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme,
Promise<Unit> &&promise) {
auto upload_file_id = td_->file_manager_->dup_file_id(file_id);
being_uploaded_files_[upload_file_id] = {type, std::move(promise)};
being_uploaded_files_[upload_file_id] = {type, for_dark_theme, std::move(promise)};
LOG(INFO) << "Ask to upload background file " << upload_file_id;
td_->file_manager_->upload(upload_file_id, upload_background_file_callback_, 1, 0);
}
@ -624,11 +636,12 @@ void BackgroundManager::on_upload_background_file(FileId file_id, tl_object_ptr<
CHECK(it != being_uploaded_files_.end());
auto type = it->second.type;
auto for_dark_theme = it->second.for_dark_theme;
auto promise = std::move(it->second.promise);
being_uploaded_files_.erase(it);
do_upload_background_file(file_id, type, std::move(input_file), std::move(promise));
do_upload_background_file(file_id, type, for_dark_theme, std::move(input_file), std::move(promise));
}
void BackgroundManager::on_upload_background_file_error(FileId file_id, Status status) {
@ -651,7 +664,7 @@ void BackgroundManager::on_upload_background_file_error(FileId file_id, Status s
status.message())); // TODO CHECK that status has always a code
}
void BackgroundManager::do_upload_background_file(FileId file_id, const BackgroundType &type,
void BackgroundManager::do_upload_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme,
tl_object_ptr<telegram_api::InputFile> &&input_file,
Promise<Unit> &&promise) {
if (input_file == nullptr) {
@ -659,16 +672,17 @@ void BackgroundManager::do_upload_background_file(FileId file_id, const Backgrou
file_id = file_view.file_id();
auto it = file_id_to_background_id_.find(file_id);
if (it != file_id_to_background_id_.end()) {
set_background(it->second, type, std::move(promise));
set_background(it->second, type, for_dark_theme, std::move(promise));
return;
}
return promise.set_error(Status::Error(500, "Failed to reupload background"));
}
td_->create_handler<UploadBackgroundQuery>(std::move(promise))->send(file_id, std::move(input_file), type);
td_->create_handler<UploadBackgroundQuery>(std::move(promise))
->send(file_id, std::move(input_file), type, for_dark_theme);
}
void BackgroundManager::on_uploaded_background_file(FileId file_id, const BackgroundType &type,
void BackgroundManager::on_uploaded_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme,
telegram_api::object_ptr<telegram_api::wallPaper> wallpaper,
Promise<Unit> &&promise) {
CHECK(wallpaper != nullptr);
@ -682,7 +696,7 @@ void BackgroundManager::on_uploaded_background_file(FileId file_id, const Backgr
auto background = get_background(background_id);
CHECK(background != nullptr);
LOG_STATUS(td_->file_manager_->merge(background->file_id, file_id));
set_background_id(background_id, type);
set_background_id(background_id, type, for_dark_theme);
promise.set_value(Unit());
}
@ -715,8 +729,11 @@ void BackgroundManager::on_removed_background(BackgroundId background_id, Result
if (it != installed_background_ids_.end()) {
installed_background_ids_.erase(it);
}
if (background_id == set_background_id_) {
set_background_id(BackgroundId(), BackgroundType());
if (background_id == set_background_id_[0]) {
set_background_id(BackgroundId(), BackgroundType(), false);
}
if (background_id == set_background_id_[1]) {
set_background_id(BackgroundId(), BackgroundType(), true);
}
promise.set_value(Unit());
}
@ -735,7 +752,8 @@ void BackgroundManager::on_reset_background(Result<Unit> &&result, Promise<Unit>
return promise.set_error(result.move_as_error());
}
installed_background_ids_.clear();
set_background_id(BackgroundId(), BackgroundType());
set_background_id(BackgroundId(), BackgroundType(), false);
set_background_id(BackgroundId(), BackgroundType(), true);
promise.set_value(Unit());
}
@ -878,33 +896,50 @@ void BackgroundManager::on_get_backgrounds(Result<telegram_api::object_ptr<teleg
}
}
td_api::object_ptr<td_api::background> BackgroundManager::get_background_object(BackgroundId background_id) const {
td_api::object_ptr<td_api::background> BackgroundManager::get_background_object(BackgroundId background_id,
bool for_dark_theme) const {
auto background = get_background(background_id);
if (background == nullptr) {
return nullptr;
}
auto type = &background->type;
if (background_id == set_background_id_) {
type = &set_background_type_;
// first check another set_background_id to get correct type if both backgrounds are the same
if (background_id == set_background_id_[1 - static_cast<int>(for_dark_theme)]) {
type = &set_background_type_[1 - static_cast<int>(for_dark_theme)];
}
if (background_id == set_background_id_[for_dark_theme]) {
type = &set_background_type_[for_dark_theme];
}
return td_api::make_object<td_api::background>(
background->id.get(), background->is_default, background->is_dark, background->name,
td_->documents_manager_->get_document_object(background->file_id), get_background_type_object(*type));
}
td_api::object_ptr<td_api::backgrounds> BackgroundManager::get_backgrounds_object() const {
auto background_ids = installed_background_ids_;
if (set_background_id_.is_valid()) {
auto it = std::find(background_ids.begin(), background_ids.end(), set_background_id_);
if (it != background_ids.end()) {
// move set background to the first place
std::rotate(background_ids.begin(), it, it + 1);
} else {
background_ids.insert(background_ids.begin(), set_background_id_);
td_api::object_ptr<td_api::backgrounds> BackgroundManager::get_backgrounds_object(bool for_dark_theme) const {
auto backgrounds = transform(installed_background_ids_, [this, for_dark_theme](BackgroundId background_id) {
return get_background_object(background_id, for_dark_theme);
});
auto background_id = set_background_id_[for_dark_theme];
if (background_id.is_valid() && std::find(installed_background_ids_.begin(), installed_background_ids_.end(),
background_id) == installed_background_ids_.end()) {
backgrounds.push_back(get_background_object(background_id, for_dark_theme));
}
std::stable_sort(backgrounds.begin(), backgrounds.end(),
[background_id, for_dark_theme](const td_api::object_ptr<td_api::background> &lhs,
const td_api::object_ptr<td_api::background> &rhs) {
auto get_order = [background_id,
for_dark_theme](const td_api::object_ptr<td_api::background> &background) {
if (background->id_ == background_id.get()) {
return 0;
}
return td_api::make_object<td_api::backgrounds>(
transform(background_ids, [this](BackgroundId background_id) { return get_background_object(background_id); }));
if (background->is_dark_ == for_dark_theme) {
return 1;
}
return 2;
};
return get_order(lhs) < get_order(rhs);
});
return td_api::make_object<td_api::backgrounds>(std::move(backgrounds));
}
FileSourceId BackgroundManager::get_background_file_source_id(BackgroundId background_id, int64 access_hash) {
@ -932,7 +967,8 @@ void BackgroundManager::get_current_state(vector<td_api::object_ptr<td_api::Upda
return;
}
updates.push_back(get_update_selected_background_object());
updates.push_back(get_update_selected_background_object(false));
updates.push_back(get_update_selected_background_object(true));
}
} // namespace td

View File

@ -42,22 +42,23 @@ class BackgroundManager : public Actor {
BackgroundId search_background(const string &name, Promise<Unit> &&promise);
BackgroundId set_background(const td_api::InputBackground *input_background,
const td_api::BackgroundType *background_type, Promise<Unit> &&promise);
const td_api::BackgroundType *background_type, bool for_dark_theme,
Promise<Unit> &&promise);
void remove_background(BackgroundId background_id, Promise<Unit> &&promise);
void reset_backgrounds(Promise<Unit> &&promise);
td_api::object_ptr<td_api::background> get_background_object(BackgroundId background_id) const;
td_api::object_ptr<td_api::background> get_background_object(BackgroundId background_id, bool for_dark_theme) const;
td_api::object_ptr<td_api::backgrounds> get_backgrounds_object() const;
td_api::object_ptr<td_api::backgrounds> get_backgrounds_object(bool for_dark_theme) const;
BackgroundId on_get_background(BackgroundId expected_background_id,
telegram_api::object_ptr<telegram_api::wallPaper> wallpaper);
FileSourceId get_background_file_source_id(BackgroundId background_id, int64 access_hash);
void on_uploaded_background_file(FileId file_id, const BackgroundType &type,
void on_uploaded_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme,
telegram_api::object_ptr<telegram_api::wallPaper> wallpaper,
Promise<Unit> &&promise);
@ -84,17 +85,17 @@ class BackgroundManager : public Actor {
void tear_down() override;
static string get_background_database_key();
static string get_background_database_key(bool for_dark_theme);
void save_background_id() const;
void save_background_id(bool for_dark_theme) const;
void reload_background_from_server(BackgroundId background_id,
telegram_api::object_ptr<telegram_api::InputWallPaper> &&input_wallpaper,
Promise<Unit> &&promise) const;
td_api::object_ptr<td_api::updateSelectedBackground> get_update_selected_background_object() const;
td_api::object_ptr<td_api::updateSelectedBackground> get_update_selected_background_object(bool for_dark_theme) const;
void send_update_selected_background() const;
void send_update_selected_background(bool for_dark_theme) const;
BackgroundId add_solid_background(int32 color);
@ -108,24 +109,25 @@ class BackgroundManager : public Actor {
Result<FileId> prepare_input_file(const tl_object_ptr<td_api::InputFile> &input_file);
BackgroundId set_background(BackgroundId background_id, const BackgroundType &type, Promise<Unit> &&promise);
void on_installed_background(BackgroundId background_id, BackgroundType type, Result<Unit> &&result,
BackgroundId set_background(BackgroundId background_id, const BackgroundType &type, bool for_dark_theme,
Promise<Unit> &&promise);
void set_background_id(BackgroundId background_id, const BackgroundType &type);
void on_installed_background(BackgroundId background_id, BackgroundType type, bool for_dark_theme,
Result<Unit> &&result, Promise<Unit> &&promise);
void set_background_id(BackgroundId background_id, const BackgroundType &type, bool for_dark_theme);
void on_removed_background(BackgroundId background_id, Result<Unit> &&result, Promise<Unit> &&promise);
void on_reset_background(Result<Unit> &&result, Promise<Unit> &&promise);
void upload_background_file(FileId file_id, const BackgroundType &type, Promise<Unit> &&promise);
void upload_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme, Promise<Unit> &&promise);
void on_upload_background_file(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file);
void on_upload_background_file_error(FileId file_id, Status status);
void do_upload_background_file(FileId file_id, const BackgroundType &type,
void do_upload_background_file(FileId file_id, const BackgroundType &type, bool for_dark_theme,
tl_object_ptr<telegram_api::InputFile> &&input_file, Promise<Unit> &&promise);
std::unordered_map<BackgroundId, Background, BackgroundIdHash> backgrounds_;
@ -137,8 +139,8 @@ class BackgroundManager : public Actor {
std::unordered_map<FileId, BackgroundId, FileIdHash> file_id_to_background_id_;
BackgroundId set_background_id_;
BackgroundType set_background_type_;
BackgroundId set_background_id_[2];
BackgroundType set_background_type_[2];
vector<BackgroundId> installed_background_ids_;
@ -148,6 +150,7 @@ class BackgroundManager : public Actor {
struct UploadedFileInfo {
BackgroundType type;
bool for_dark_theme;
Promise<Unit> promise;
};
std::unordered_map<FileId, UploadedFileInfo, FileIdHash> being_uploaded_files_;

View File

@ -2929,16 +2929,19 @@ class GetSupportUserRequest : public RequestActor<> {
};
class GetBackgroundsRequest : public RequestOnceActor {
bool for_dark_theme_;
void do_run(Promise<Unit> &&promise) override {
td->background_manager_->get_backgrounds(std::move(promise));
}
void do_send_result() override {
send_result(td->background_manager_->get_backgrounds_object());
send_result(td->background_manager_->get_backgrounds_object(for_dark_theme_));
}
public:
GetBackgroundsRequest(ActorShared<Td> td, uint64 request_id) : RequestOnceActor(std::move(td), request_id) {
GetBackgroundsRequest(ActorShared<Td> td, uint64 request_id, bool for_dark_theme)
: RequestOnceActor(std::move(td), request_id), for_dark_theme_(for_dark_theme) {
}
};
@ -2952,7 +2955,7 @@ class SearchBackgroundRequest : public RequestActor<> {
}
void do_send_result() override {
send_result(td->background_manager_->get_background_object(background_id_));
send_result(td->background_manager_->get_background_object(background_id_, false));
}
public:
@ -2964,25 +2967,27 @@ class SearchBackgroundRequest : public RequestActor<> {
class SetBackgroundRequest : public RequestActor<> {
td_api::object_ptr<td_api::InputBackground> input_background_;
td_api::object_ptr<td_api::BackgroundType> background_type_;
bool for_dark_theme_ = false;
BackgroundId background_id_;
void do_run(Promise<Unit> &&promise) override {
background_id_ =
td->background_manager_->set_background(input_background_.get(), background_type_.get(), std::move(promise));
background_id_ = td->background_manager_->set_background(input_background_.get(), background_type_.get(),
for_dark_theme_, std::move(promise));
}
void do_send_result() override {
send_result(td->background_manager_->get_background_object(background_id_));
send_result(td->background_manager_->get_background_object(background_id_, for_dark_theme_));
}
public:
SetBackgroundRequest(ActorShared<Td> td, uint64 request_id,
td_api::object_ptr<td_api::InputBackground> &&input_background,
td_api::object_ptr<td_api::BackgroundType> background_type)
td_api::object_ptr<td_api::BackgroundType> background_type, bool for_dark_theme)
: RequestActor(std::move(td), request_id)
, input_background_(std::move(input_background))
, background_type_(std::move(background_type)) {
, background_type_(std::move(background_type))
, for_dark_theme_(for_dark_theme) {
}
};
@ -7081,7 +7086,7 @@ void Td::on_request(uint64 id, const td_api::getSupportUser &request) {
void Td::on_request(uint64 id, const td_api::getBackgrounds &request) {
CHECK_IS_USER();
CREATE_NO_ARGS_REQUEST(GetBackgroundsRequest);
CREATE_REQUEST(GetBackgroundsRequest, request.for_dark_theme_);
}
void Td::on_request(uint64 id, td_api::getBackgroundUrl &request) {
@ -7103,7 +7108,8 @@ void Td::on_request(uint64 id, td_api::searchBackground &request) {
void Td::on_request(uint64 id, td_api::setBackground &request) {
CHECK_IS_USER();
CREATE_REQUEST(SetBackgroundRequest, std::move(request.background_), std::move(request.type_));
CREATE_REQUEST(SetBackgroundRequest, std::move(request.background_), std::move(request.type_),
request.for_dark_theme_);
}
void Td::on_request(uint64 id, const td_api::removeBackground &request) {

View File

@ -1975,7 +1975,7 @@ class CliClient final : public Actor {
} else if (op == "daw") {
send_request(td_api::make_object<td_api::disconnectAllWebsites>());
} else if (op == "gbgs") {
send_request(td_api::make_object<td_api::getBackgrounds>());
send_request(td_api::make_object<td_api::getBackgrounds>(as_bool(args)));
} else if (op == "gbgu") {
send_get_background_url(td_api::make_object<td_api::backgroundTypeWallpaper>(false, false));
send_get_background_url(td_api::make_object<td_api::backgroundTypeWallpaper>(false, true));
@ -1993,25 +1993,25 @@ class CliClient final : public Actor {
send_get_background_url(td_api::make_object<td_api::backgroundTypeSolid>(0x1000000));
} else if (op == "sbg") {
send_request(td_api::make_object<td_api::searchBackground>(args));
} else if (op == "sbgw") {
} else if (op == "sbgw" || op == "sbgwd") {
send_request(td_api::make_object<td_api::setBackground>(
td_api::make_object<td_api::inputBackgroundLocal>(as_input_file(args)),
td_api::make_object<td_api::backgroundTypeWallpaper>(true, true)));
} else if (op == "sbgp") {
td_api::make_object<td_api::backgroundTypeWallpaper>(true, true), op == "sbgwd"));
} else if (op == "sbgp" || op == "sbgpd") {
send_request(td_api::make_object<td_api::setBackground>(
td_api::make_object<td_api::inputBackgroundLocal>(as_input_file(args)),
td_api::make_object<td_api::backgroundTypePattern>(true, 0xabcdef, 49)));
} else if (op == "sbgs") {
td_api::make_object<td_api::backgroundTypePattern>(true, 0xabcdef, 49), op == "sbgpd"));
} else if (op == "sbgs" || op == "sbgsd") {
send_request(td_api::make_object<td_api::setBackground>(
nullptr, td_api::make_object<td_api::backgroundTypeSolid>(to_integer<int32>(args))));
} else if (op == "sbgwid") {
nullptr, td_api::make_object<td_api::backgroundTypeSolid>(to_integer<int32>(args)), op == "sbgsd"));
} else if (op == "sbgwid" || op == "sbgwidd") {
send_request(td_api::make_object<td_api::setBackground>(
td_api::make_object<td_api::inputBackgroundRemote>(to_integer<int64>(args)),
td_api::make_object<td_api::backgroundTypeWallpaper>(true, true)));
} else if (op == "sbgpid") {
td_api::make_object<td_api::backgroundTypeWallpaper>(true, true), op == "sbgwidd"));
} else if (op == "sbgpid" || op == "sbgpidd") {
send_request(td_api::make_object<td_api::setBackground>(
td_api::make_object<td_api::inputBackgroundRemote>(to_integer<int64>(args)),
td_api::make_object<td_api::backgroundTypePattern>(true, 0xabcdef, 49)));
td_api::make_object<td_api::backgroundTypePattern>(true, 0xabcdef, 49), op == "sbgpidd"));
} else if (op == "rbg") {
send_request(td_api::make_object<td_api::removeBackground>(to_integer<int64>(args)));
} else if (op == "rbgs") {