Add td_api::revertChatBackground.

This commit is contained in:
levlam 2023-11-10 14:53:16 +03:00
parent aa7a0a6ee3
commit 1c8205d6de
6 changed files with 57 additions and 4 deletions

View File

@ -7709,6 +7709,11 @@ setChatPermissions chat_id:int53 permissions:chatPermissions = Ok;
//@only_for_self Pass true to set background only for self; pass false to set background for both chat users. Background can be set for both users only by Telegram Premium users
setChatBackground chat_id:int53 background:InputBackground type:BackgroundType dark_theme_dimming:int32 only_for_self:Bool = Ok;
//@description Restores background in a specific chat after it was changed by the other user. Can be called only from messageChatSetBackground messages with the currently set background that was set for both sides by the other user
//-Supported only in private and secret chats with non-deleted users
//@chat_id Chat identifier
revertChatBackground chat_id:int53 = Ok;
//@description Changes the chat theme. Supported only in private and secret chats @chat_id Chat identifier @theme_name Name of the new chat theme; pass an empty string to return the default theme
setChatTheme chat_id:int53 theme_name:string = Ok;

View File

@ -111,10 +111,10 @@ 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, MessageId old_message_id,
bool for_both) {
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings, MessageId old_message_id, bool for_both,
bool revert) {
dialog_id_ = dialog_id;
is_remove_ = input_wallpaper == nullptr && settings == nullptr;
is_remove_ = input_wallpaper == nullptr && settings == nullptr && !revert;
if (is_remove_) {
td_->messages_manager_->on_update_dialog_background(dialog_id_, nullptr);
}
@ -136,6 +136,9 @@ class SetChatWallPaperQuery final : public Td::ResultHandler {
if (for_both) {
flags |= telegram_api::messages_setChatWallPaper::FOR_BOTH_MASK;
}
if (revert) {
flags |= telegram_api::messages_setChatWallPaper::REVERT_MASK;
}
send_query(G()->net_query_creator().create(telegram_api::messages_setChatWallPaper(
flags, false /*ignored*/, false /*ignored*/, std::move(input_peer), std::move(input_wallpaper),
std::move(settings), old_message_id.get_server_message_id().get())));
@ -817,6 +820,37 @@ void BackgroundManager::set_dialog_background(DialogId dialog_id, const td_api::
}
}
void BackgroundManager::revert_dialog_background(DialogId dialog_id, Promise<Unit> &&promise) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "set_dialog_background")) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Write)) {
return promise.set_error(Status::Error(400, "Can't access the chat"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
break;
case DialogType::Chat:
case DialogType::Channel:
return promise.set_error(Status::Error(400, "Can't change background in the chat"));
case DialogType::SecretChat: {
auto user_id = td_->contacts_manager_->get_secret_chat_user_id(dialog_id.get_secret_chat_id());
if (!user_id.is_valid()) {
return promise.set_error(Status::Error(400, "Can't access the user"));
}
dialog_id = DialogId(user_id);
break;
}
case DialogType::None:
default:
UNREACHABLE();
}
td_->create_handler<SetChatWallPaperQuery>(std::move(promise))
->send(dialog_id, nullptr, nullptr, MessageId(), false, true);
}
void BackgroundManager::do_set_dialog_background(DialogId dialog_id, BackgroundId background_id, BackgroundType type,
bool for_both, Promise<Unit> &&promise) {
TRY_STATUS_PROMISE(promise, G()->close_status());
@ -840,7 +874,7 @@ void BackgroundManager::send_set_dialog_background_query(
telegram_api::object_ptr<telegram_api::wallPaperSettings> settings, MessageId old_message_id, bool for_both,
Promise<Unit> &&promise) {
td_->create_handler<SetChatWallPaperQuery>(std::move(promise))
->send(dialog_id, std::move(input_wallpaper), std::move(settings), old_message_id, for_both);
->send(dialog_id, std::move(input_wallpaper), std::move(settings), old_message_id, for_both, false);
}
void BackgroundManager::set_background(BackgroundId background_id, BackgroundType type, bool for_dark_theme,

View File

@ -52,6 +52,8 @@ class BackgroundManager final : public Actor {
const td_api::BackgroundType *background_type, int32 dark_theme_dimming, bool for_both,
Promise<Unit> &&promise);
void revert_dialog_background(DialogId dialog_id, Promise<Unit> &&promise);
td_api::object_ptr<td_api::background> get_background_object(BackgroundId background_id, bool for_dark_theme,
const BackgroundType *type) const;

View File

@ -6499,6 +6499,12 @@ void Td::on_request(uint64 id, td_api::setChatBackground &request) {
request.dark_theme_dimming_, !request.only_for_self_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::revertChatBackground &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
background_manager_->revert_dialog_background(DialogId(request.chat_id_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::setChatTheme &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.theme_name_);

View File

@ -1006,6 +1006,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::setChatBackground &request);
void on_request(uint64 id, const td_api::revertChatBackground &request);
void on_request(uint64 id, td_api::setChatTheme &request);
void on_request(uint64 id, td_api::setChatDraftMessage &request);

View File

@ -3109,6 +3109,10 @@ class CliClient final : public Actor {
get_args(args, chat_id, input_background, background_type, dark_theme_dimming);
send_request(td_api::make_object<td_api::setChatBackground>(chat_id, input_background, background_type,
dark_theme_dimming, op == "scbgs"));
} else if (op == "rcb") {
ChatId chat_id;
get_args(args, chat_id);
send_request(td_api::make_object<td_api::revertChatBackground>(chat_id));
} else if (op == "gcos") {
send_request(td_api::make_object<td_api::getCountries>());
} else if (op == "gcoc") {