Add inputBackgroundPrevious.

This commit is contained in:
levlam 2023-04-12 00:02:42 +03:00
parent b130306ce7
commit 5df2f3c141
4 changed files with 36 additions and 9 deletions

View File

@ -4098,6 +4098,9 @@ inputBackgroundLocal background:InputFile = InputBackground;
//@description A background from the server @background_id The background identifier
inputBackgroundRemote background_id:int64 = InputBackground;
//@description A background previously set in the chat; for chat backgrounds only @message_id Identifier of the message with the background
inputBackgroundPrevious message_id:int53 = InputBackground;
//@description Describes theme settings
//@accent_color Theme accent color in ARGB format

View File

@ -107,7 +107,7 @@ class SetChatWallPaperQuery final : public Td::ResultHandler {
}
void send(DialogId dialog_id, telegram_api::object_ptr<telegram_api::InputWallPaper> input_wallpaper,
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings) {
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings, MessageId old_message_id) {
int32 flags = 0;
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) {
@ -119,8 +119,12 @@ class SetChatWallPaperQuery final : public Td::ResultHandler {
if (settings != nullptr) {
flags |= telegram_api::messages_setChatWallPaper::SETTINGS_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::messages_setChatWallPaper(
flags, std::move(input_peer), std::move(input_wallpaper), std::move(settings), 0)));
if (old_message_id.is_valid()) {
flags |= telegram_api::messages_setChatWallPaper::ID_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::messages_setChatWallPaper(flags, std::move(input_peer), std::move(input_wallpaper),
std::move(settings), old_message_id.get_server_message_id().get())));
}
void on_result(BufferSlice packet) final {
@ -692,6 +696,8 @@ void BackgroundManager::set_background(const td_api::InputBackground *input_back
return set_background(BackgroundId(background_remote->background_id_), std::move(type), for_dark_theme,
std::move(promise));
}
case td_api::inputBackgroundPrevious::ID:
return promise.set_error(Status::Error(400, "Can't use a previous background"));
default:
UNREACHABLE();
}
@ -733,11 +739,11 @@ void BackgroundManager::set_dialog_background(DialogId dialog_id, const td_api::
return promise.set_error(Status::Error(400, "Input background must be non-empty for the background type"));
}
if (background_type == nullptr) {
return send_set_dialog_background_query(dialog_id, nullptr, nullptr, std::move(promise));
return send_set_dialog_background_query(dialog_id, nullptr, nullptr, MessageId(), std::move(promise));
} else {
return send_set_dialog_background_query(dialog_id,
telegram_api::make_object<telegram_api::inputWallPaperNoFile>(0),
type.get_input_wallpaper_settings(), std::move(promise));
type.get_input_wallpaper_settings(), MessageId(), std::move(promise));
}
}
@ -775,6 +781,16 @@ void BackgroundManager::set_dialog_background(DialogId dialog_id, const td_api::
return do_set_dialog_background(dialog_id, BackgroundId(background_remote->background_id_), std::move(type),
std::move(promise));
}
case td_api::inputBackgroundPrevious::ID: {
auto background_previous = static_cast<const td_api::inputBackgroundPrevious *>(input_background);
MessageId message_id(background_previous->message_id_);
if (!message_id.is_valid() || !message_id.is_server()) {
return promise.set_error(Status::Error(400, "Invalid message identifier specified"));
}
return send_set_dialog_background_query(
dialog_id, nullptr, background_type == nullptr ? nullptr : type.get_input_wallpaper_settings(), message_id,
std::move(promise));
}
default:
UNREACHABLE();
}
@ -795,14 +811,15 @@ void BackgroundManager::do_set_dialog_background(DialogId dialog_id, BackgroundI
send_set_dialog_background_query(
dialog_id, telegram_api::make_object<telegram_api::inputWallPaper>(background_id.get(), background->access_hash),
type.get_input_wallpaper_settings(), std::move(promise));
type.get_input_wallpaper_settings(), MessageId(), std::move(promise));
}
void BackgroundManager::send_set_dialog_background_query(
DialogId dialog_id, telegram_api::object_ptr<telegram_api::InputWallPaper> input_wallpaper,
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings, Promise<Unit> &&promise) {
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings, MessageId old_message_id,
Promise<Unit> &&promise) {
td_->create_handler<SetChatWallPaperQuery>(std::move(promise))
->send(dialog_id, std::move(input_wallpaper), std::move(settings));
->send(dialog_id, std::move(input_wallpaper), std::move(settings), old_message_id);
}
void BackgroundManager::set_background(BackgroundId background_id, BackgroundType type, bool for_dark_theme,

View File

@ -145,7 +145,7 @@ class BackgroundManager final : public Actor {
void send_set_dialog_background_query(DialogId dialog_id,
telegram_api::object_ptr<telegram_api::InputWallPaper> input_wallpaper,
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings,
Promise<Unit> &&promise);
MessageId old_message_id, Promise<Unit> &&promise);
void set_background(BackgroundId background_id, BackgroundType type, bool for_dark_theme,
Promise<td_api::object_ptr<td_api::background>> &&promise);

View File

@ -965,6 +965,8 @@ class CliClient final : public Actor {
string background_file;
// or
int64 background_id = 0;
// or
int64 message_id = 0;
operator td_api::object_ptr<td_api::InputBackground>() const {
if (!background_file.empty()) {
@ -973,6 +975,9 @@ class CliClient final : public Actor {
if (background_id != 0) {
return td_api::make_object<td_api::inputBackgroundRemote>(background_id);
}
if (message_id != 0) {
return td_api::make_object<td_api::inputBackgroundPrevious>(message_id);
}
return nullptr;
}
};
@ -984,6 +989,8 @@ class CliClient final : public Actor {
}
if (to_integer_safe<int64>(args).is_ok()) {
arg.background_id = to_integer<int64>(args);
} else if (args.back() == 's' && to_integer_safe<int32>(args.substr(0, args.size() - 1)).is_ok()) {
arg.message_id = as_message_id(args);
} else {
arg.background_file = std::move(args);
}