Support photo deletion in setUserPersonalProfilePhoto.

This commit is contained in:
levlam 2022-12-15 18:39:39 +03:00
parent 1ee924aeb2
commit ab349e1562
3 changed files with 44 additions and 1 deletions

View File

@ -7015,7 +7015,7 @@ changeImportedContacts contacts:vector<contact> = ImportedContacts;
//@description Clears all imported contacts, contact list remains unchanged //@description Clears all imported contacts, contact list remains unchanged
clearImportedContacts = Ok; clearImportedContacts = Ok;
//@description Changes a personal profile photo of a contact user @user_id User identifier @photo Profile photo to set; inputChatPhotoPrevious isn't supported in this function //@description Changes a personal profile photo of a contact user @user_id User identifier @photo Profile photo to set; pass null to delete the photo; inputChatPhotoPrevious isn't supported in this function
setUserPersonalProfilePhoto user_id:int53 photo:InputChatPhoto = Ok; setUserPersonalProfilePhoto user_id:int53 photo:InputChatPhoto = Ok;
//@description Suggests a personal profile photo to a user with common messages @user_id User identifier @photo Profile photo to suggest; inputChatPhotoPrevious isn't supported in this function //@description Suggests a personal profile photo to a user with common messages @user_id User identifier @photo Profile photo to suggest; inputChatPhotoPrevious isn't supported in this function

View File

@ -590,6 +590,41 @@ class UpdateProfilePhotoQuery final : public Td::ResultHandler {
} }
}; };
class DeleteContactProfilePhotoQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
UserId user_id_;
public:
explicit DeleteContactProfilePhotoQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(UserId user_id, tl_object_ptr<telegram_api::InputUser> &&input_user) {
CHECK(input_user != nullptr);
user_id_ = user_id;
int32 flags = 0;
flags |= telegram_api::photos_uploadContactProfilePhoto::SAVE_MASK;
send_query(G()->net_query_creator().create(
telegram_api::photos_uploadContactProfilePhoto(flags, false /*ignored*/, false /*ignored*/,
std::move(input_user), nullptr, nullptr, 0),
{{user_id}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::photos_uploadContactProfilePhoto>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
td_->contacts_manager_->on_set_profile_photo(user_id_, result_ptr.move_as_ok(), false, 0);
promise_.set_value(Unit());
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class DeleteProfilePhotoQuery final : public Td::ResultHandler { class DeleteProfilePhotoQuery final : public Td::ResultHandler {
Promise<Unit> promise_; Promise<Unit> promise_;
int64 profile_photo_id_; int64 profile_photo_id_;
@ -7008,6 +7043,10 @@ void ContactsManager::set_user_profile_photo(UserId user_id,
if (user_id == get_my_id()) { if (user_id == get_my_id()) {
return promise.set_error(Status::Error(400, "Can't set personal photo to self")); return promise.set_error(Status::Error(400, "Can't set personal photo to self"));
} }
if (input_photo == nullptr) {
td_->create_handler<DeleteContactProfilePhotoQuery>(std::move(promise))->send(user_id, r_input_user.move_as_ok());
return;
}
set_profile_photo_impl(user_id, input_photo, false, only_suggest, std::move(promise)); set_profile_photo_impl(user_id, input_photo, false, only_suggest, std::move(promise));
} }

View File

@ -4829,6 +4829,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::setUserPersonalProfilePhoto>( send_request(td_api::make_object<td_api::setUserPersonalProfilePhoto>(
user_id, td_api::make_object<td_api::inputChatPhotoAnimation>(as_input_file(animation), user_id, td_api::make_object<td_api::inputChatPhotoAnimation>(as_input_file(animation),
to_double(main_frame_timestamp)))); to_double(main_frame_timestamp))));
} else if (op == "suppe") {
UserId user_id;
get_args(args, user_id);
send_request(td_api::make_object<td_api::setUserPersonalProfilePhoto>(user_id, nullptr));
} else if (op == "suuppp") { } else if (op == "suuppp") {
UserId user_id; UserId user_id;
string photo; string photo;