Allow to set non-local filled backgrounds.
This commit is contained in:
parent
d10cc1eb77
commit
5188a5b5e7
@ -5079,8 +5079,8 @@ getBackgroundUrl name:string type:BackgroundType = HttpUrl;
|
|||||||
searchBackground name:string = Background;
|
searchBackground name:string = Background;
|
||||||
|
|
||||||
//@description Changes the background selected by the user; adds background to the list of installed backgrounds
|
//@description Changes the background selected by the user; adds background to the list of installed backgrounds
|
||||||
//@background The input background to use, null for filled backgrounds
|
//@background The input background to use. Pass null to create a new filled backgrounds. Pass null to remove the current background
|
||||||
//@type Background type; null for default background. The method will return error 404 if type is null
|
//@type Background type. Pass null to use default type of the remote background. Pass null to remove the current background
|
||||||
//@for_dark_theme True, if the background is chosen for dark theme
|
//@for_dark_theme True, if the background is chosen for dark theme
|
||||||
setBackground background:InputBackground type:BackgroundType for_dark_theme:Bool = Background;
|
setBackground background:InputBackground type:BackgroundType for_dark_theme:Bool = Background;
|
||||||
|
|
||||||
|
@ -108,10 +108,9 @@ class InstallBackgroundQuery : public Td::ResultHandler {
|
|||||||
explicit InstallBackgroundQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
explicit InstallBackgroundQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void send(BackgroundId background_id, int64 access_hash, const BackgroundType &type) {
|
void send(telegram_api::object_ptr<telegram_api::InputWallPaper> input_wallpaper, const BackgroundType &type) {
|
||||||
send_query(G()->net_query_creator().create(telegram_api::account_installWallPaper(
|
send_query(G()->net_query_creator().create(
|
||||||
telegram_api::make_object<telegram_api::inputWallPaper>(background_id.get(), access_hash),
|
telegram_api::account_installWallPaper(std::move(input_wallpaper), get_input_wallpaper_settings(type))));
|
||||||
get_input_wallpaper_settings(type))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_result(uint64 id, BufferSlice packet) override {
|
void on_result(uint64 id, BufferSlice packet) override {
|
||||||
@ -531,34 +530,44 @@ BackgroundId BackgroundManager::add_fill_background(const BackgroundFill &fill,
|
|||||||
BackgroundId BackgroundManager::set_background(const td_api::InputBackground *input_background,
|
BackgroundId BackgroundManager::set_background(const td_api::InputBackground *input_background,
|
||||||
const td_api::BackgroundType *background_type, bool for_dark_theme,
|
const td_api::BackgroundType *background_type, bool for_dark_theme,
|
||||||
Promise<Unit> &&promise) {
|
Promise<Unit> &&promise) {
|
||||||
if (background_type == nullptr) {
|
BackgroundType type;
|
||||||
set_background_id(BackgroundId(), BackgroundType(), for_dark_theme);
|
if (background_type != nullptr) {
|
||||||
promise.set_value(Unit());
|
auto r_type = get_background_type(background_type);
|
||||||
return BackgroundId();
|
if (r_type.is_error()) {
|
||||||
|
promise.set_error(r_type.move_as_error());
|
||||||
|
return BackgroundId();
|
||||||
|
}
|
||||||
|
type = r_type.move_as_ok();
|
||||||
|
} else {
|
||||||
|
CHECK(!type.has_file());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto r_type = get_background_type(background_type);
|
if (input_background == nullptr) {
|
||||||
if (r_type.is_error()) {
|
if (background_type == nullptr) {
|
||||||
promise.set_error(r_type.move_as_error());
|
set_background_id(BackgroundId(), BackgroundType(), for_dark_theme);
|
||||||
return BackgroundId();
|
promise.set_value(Unit());
|
||||||
}
|
return BackgroundId();
|
||||||
|
}
|
||||||
|
if (type.has_file()) {
|
||||||
|
promise.set_error(Status::Error(400, "Input background must be non-empty for the background type"));
|
||||||
|
return BackgroundId();
|
||||||
|
}
|
||||||
|
|
||||||
auto type = r_type.move_as_ok();
|
CHECK(type.type == BackgroundType::Type::Fill);
|
||||||
if (type.type == BackgroundType::Type::Fill) {
|
|
||||||
auto background_id = add_fill_background(type.fill);
|
auto background_id = add_fill_background(type.fill);
|
||||||
set_background_id(background_id, type, for_dark_theme);
|
set_background_id(background_id, type, for_dark_theme);
|
||||||
promise.set_value(Unit());
|
promise.set_value(Unit());
|
||||||
return background_id;
|
return background_id;
|
||||||
}
|
}
|
||||||
CHECK(type.is_server());
|
|
||||||
|
|
||||||
if (input_background == nullptr) {
|
|
||||||
promise.set_error(Status::Error(400, "Input background must be non-empty"));
|
|
||||||
return BackgroundId();
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (input_background->get_id()) {
|
switch (input_background->get_id()) {
|
||||||
case td_api::inputBackgroundLocal::ID: {
|
case td_api::inputBackgroundLocal::ID: {
|
||||||
|
if (!type.has_file()) {
|
||||||
|
promise.set_error(Status::Error(400, "Can't specify local file for the background type"));
|
||||||
|
return BackgroundId();
|
||||||
|
}
|
||||||
|
CHECK(background_type != nullptr);
|
||||||
|
|
||||||
auto background_local = static_cast<const td_api::inputBackgroundLocal *>(input_background);
|
auto background_local = static_cast<const td_api::inputBackgroundLocal *>(input_background);
|
||||||
auto r_file_id = prepare_input_file(background_local->background_);
|
auto r_file_id = prepare_input_file(background_local->background_);
|
||||||
if (r_file_id.is_error()) {
|
if (r_file_id.is_error()) {
|
||||||
@ -578,7 +587,8 @@ BackgroundId BackgroundManager::set_background(const td_api::InputBackground *in
|
|||||||
}
|
}
|
||||||
case td_api::inputBackgroundRemote::ID: {
|
case td_api::inputBackgroundRemote::ID: {
|
||||||
auto background_remote = static_cast<const td_api::inputBackgroundRemote *>(input_background);
|
auto background_remote = static_cast<const td_api::inputBackgroundRemote *>(input_background);
|
||||||
return set_background(BackgroundId(background_remote->background_id_), type, for_dark_theme, std::move(promise));
|
return set_background(BackgroundId(background_remote->background_id_), std::move(type), for_dark_theme,
|
||||||
|
std::move(promise));
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
@ -586,14 +596,17 @@ BackgroundId BackgroundManager::set_background(const td_api::InputBackground *in
|
|||||||
return BackgroundId();
|
return BackgroundId();
|
||||||
}
|
}
|
||||||
|
|
||||||
BackgroundId BackgroundManager::set_background(BackgroundId background_id, const BackgroundType &type,
|
BackgroundId BackgroundManager::set_background(BackgroundId background_id, BackgroundType type, bool for_dark_theme,
|
||||||
bool for_dark_theme, Promise<Unit> &&promise) {
|
Promise<Unit> &&promise) {
|
||||||
LOG(INFO) << "Set " << background_id << " with " << type;
|
LOG(INFO) << "Set " << background_id << " with " << type;
|
||||||
const auto *background = get_background(background_id);
|
const auto *background = get_background(background_id);
|
||||||
if (background == nullptr) {
|
if (background == nullptr) {
|
||||||
promise.set_error(Status::Error(400, "Background to set not found"));
|
promise.set_error(Status::Error(400, "Background to set not found"));
|
||||||
return BackgroundId();
|
return BackgroundId();
|
||||||
}
|
}
|
||||||
|
if (!type.has_file()) {
|
||||||
|
type = background->type;
|
||||||
|
}
|
||||||
if (background->type.type != type.type) {
|
if (background->type.type != type.type) {
|
||||||
promise.set_error(Status::Error(400, "Background type mismatch"));
|
promise.set_error(Status::Error(400, "Background type mismatch"));
|
||||||
return BackgroundId();
|
return BackgroundId();
|
||||||
@ -604,13 +617,21 @@ BackgroundId BackgroundManager::set_background(BackgroundId background_id, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG(INFO) << "Install " << background_id << " with " << type;
|
LOG(INFO) << "Install " << background_id << " with " << type;
|
||||||
|
|
||||||
|
if (!type.has_file()) {
|
||||||
|
set_background_id(background_id, type, for_dark_theme);
|
||||||
|
promise.set_value(Unit());
|
||||||
|
return background_id;
|
||||||
|
}
|
||||||
|
|
||||||
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), background_id, type, for_dark_theme,
|
auto query_promise = PromiseCreator::lambda([actor_id = actor_id(this), background_id, type, for_dark_theme,
|
||||||
promise = std::move(promise)](Result<Unit> &&result) mutable {
|
promise = std::move(promise)](Result<Unit> &&result) mutable {
|
||||||
send_closure(actor_id, &BackgroundManager::on_installed_background, background_id, type, for_dark_theme,
|
send_closure(actor_id, &BackgroundManager::on_installed_background, background_id, type, for_dark_theme,
|
||||||
std::move(result), std::move(promise));
|
std::move(result), std::move(promise));
|
||||||
});
|
});
|
||||||
td_->create_handler<InstallBackgroundQuery>(std::move(query_promise))
|
td_->create_handler<InstallBackgroundQuery>(std::move(query_promise))
|
||||||
->send(background_id, background->access_hash, type);
|
->send(telegram_api::make_object<telegram_api::inputWallPaper>(background_id.get(), background->access_hash),
|
||||||
|
type);
|
||||||
return BackgroundId();
|
return BackgroundId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ class BackgroundManager : public Actor {
|
|||||||
|
|
||||||
Result<FileId> prepare_input_file(const tl_object_ptr<td_api::InputFile> &input_file);
|
Result<FileId> prepare_input_file(const tl_object_ptr<td_api::InputFile> &input_file);
|
||||||
|
|
||||||
BackgroundId set_background(BackgroundId background_id, const BackgroundType &type, bool for_dark_theme,
|
BackgroundId set_background(BackgroundId background_id, BackgroundType type, bool for_dark_theme,
|
||||||
Promise<Unit> &&promise);
|
Promise<Unit> &&promise);
|
||||||
|
|
||||||
void on_installed_background(BackgroundId background_id, BackgroundType type, bool for_dark_theme,
|
void on_installed_background(BackgroundId background_id, BackgroundType type, bool for_dark_theme,
|
||||||
|
@ -448,7 +448,7 @@ td_api::object_ptr<td_api::BackgroundType> get_background_type_object(const Back
|
|||||||
}
|
}
|
||||||
|
|
||||||
telegram_api::object_ptr<telegram_api::wallPaperSettings> get_input_wallpaper_settings(const BackgroundType &type) {
|
telegram_api::object_ptr<telegram_api::wallPaperSettings> get_input_wallpaper_settings(const BackgroundType &type) {
|
||||||
CHECK(type.is_server());
|
CHECK(type.has_file());
|
||||||
|
|
||||||
int32 flags = 0;
|
int32 flags = 0;
|
||||||
if (type.is_blurred) {
|
if (type.is_blurred) {
|
||||||
|
@ -2262,6 +2262,11 @@ class CliClient final : public Actor {
|
|||||||
} else if (op == "sbgfg" || op == "sbgfgd") {
|
} else if (op == "sbgfg" || op == "sbgfgd") {
|
||||||
auto background_type = get_freeform_gradient_background(to_integers<int32>(args));
|
auto background_type = get_freeform_gradient_background(to_integers<int32>(args));
|
||||||
send_request(td_api::make_object<td_api::setBackground>(nullptr, std::move(background_type), op == "sbgfgd"));
|
send_request(td_api::make_object<td_api::setBackground>(nullptr, std::move(background_type), op == "sbgfgd"));
|
||||||
|
} else if (op == "sbgfid" || op == "sbgfidd") {
|
||||||
|
int64 background_id;
|
||||||
|
get_args(args, background_id);
|
||||||
|
send_request(td_api::make_object<td_api::setBackground>(
|
||||||
|
td_api::make_object<td_api::inputBackgroundRemote>(background_id), nullptr, op == "sbgfidd"));
|
||||||
} else if (op == "sbgwid" || op == "sbgwidd") {
|
} else if (op == "sbgwid" || op == "sbgwidd") {
|
||||||
send_request(td_api::make_object<td_api::setBackground>(
|
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::inputBackgroundRemote>(to_integer<int64>(args)),
|
||||||
|
Loading…
Reference in New Issue
Block a user