Simplify EditDialogPhotoQuery,

GitOrigin-RevId: 2ea74ff1695764020835d30c5c73f8400d68da01
This commit is contained in:
levlam 2019-01-29 02:41:33 +03:00
parent 595eb119d7
commit 3494ae8b09
2 changed files with 11 additions and 21 deletions

View File

@ -574,12 +574,11 @@ class EditDialogPhotoQuery : public Td::ResultHandler {
explicit EditDialogPhotoQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(FileId file_id, bool was_uploaded, string file_reference, DialogId dialog_id,
tl_object_ptr<telegram_api::InputChatPhoto> &&input_chat_photo) {
void send(DialogId dialog_id, FileId file_id, tl_object_ptr<telegram_api::InputChatPhoto> &&input_chat_photo) {
CHECK(input_chat_photo != nullptr);
file_id_ = file_id;
was_uploaded_ = was_uploaded;
file_reference_ = std::move(file_reference);
was_uploaded_ = FileManager::extract_was_uploaded(input_chat_photo);
file_reference_ = FileManager::extract_file_reference(input_chat_photo);
dialog_id_ = dialog_id;
switch (dialog_id.get_type()) {
@ -6331,8 +6330,6 @@ void MessagesManager::on_upload_dialog_photo(FileId file_id, tl_object_ptr<teleg
tl_object_ptr<telegram_api::InputChatPhoto> input_chat_photo;
FileView file_view = td_->file_manager_->get_file_view(file_id);
bool was_uploaded = false;
string file_reference;
CHECK(!file_view.is_encrypted());
if (input_file == nullptr && file_view.has_remote_location()) {
if (file_view.remote_location().is_web()) {
@ -6341,15 +6338,12 @@ void MessagesManager::on_upload_dialog_photo(FileId file_id, tl_object_ptr<teleg
return;
}
auto input_photo = file_view.remote_location().as_input_photo();
file_reference = input_photo->file_reference_.as_slice().str();
input_chat_photo = make_tl_object<telegram_api::inputChatPhoto>(std::move(input_photo));
} else {
input_chat_photo = make_tl_object<telegram_api::inputChatUploadedPhoto>(std::move(input_file));
was_uploaded = true;
}
send_edit_dialog_photo_query(file_id, was_uploaded, file_reference, dialog_id, std::move(input_chat_photo),
std::move(promise));
send_edit_dialog_photo_query(dialog_id, file_id, std::move(input_chat_photo), std::move(promise));
}
void MessagesManager::on_upload_dialog_photo_error(FileId file_id, Status status) {
@ -20164,8 +20158,8 @@ void MessagesManager::set_dialog_photo(DialogId dialog_id, const tl_object_ptr<t
FileId file_id = r_file_id.ok();
if (!file_id.is_valid()) {
send_edit_dialog_photo_query(FileId(), false, string(), dialog_id,
make_tl_object<telegram_api::inputChatPhotoEmpty>(), std::move(promise));
send_edit_dialog_photo_query(dialog_id, FileId(), make_tl_object<telegram_api::inputChatPhotoEmpty>(),
std::move(promise));
return;
}
@ -20174,10 +20168,8 @@ void MessagesManager::set_dialog_photo(DialogId dialog_id, const tl_object_ptr<t
if (file_view.has_remote_location() && !file_view.remote_location().is_web()) {
// file has already been uploaded, just send change photo request
auto input_photo = file_view.remote_location().as_input_photo();
auto file_reference = input_photo->file_reference_.as_slice().str();
send_edit_dialog_photo_query(file_id, false, std::move(file_reference), dialog_id,
make_tl_object<telegram_api::inputChatPhoto>(std::move(input_photo)),
std::move(promise));
send_edit_dialog_photo_query(
dialog_id, file_id, make_tl_object<telegram_api::inputChatPhoto>(std::move(input_photo)), std::move(promise));
return;
}
@ -20185,13 +20177,11 @@ void MessagesManager::set_dialog_photo(DialogId dialog_id, const tl_object_ptr<t
upload_dialog_photo(dialog_id, td_->file_manager_->dup_file_id(file_id), std::move(promise));
}
void MessagesManager::send_edit_dialog_photo_query(FileId file_id, bool was_uploaded, string file_reference,
DialogId dialog_id,
void MessagesManager::send_edit_dialog_photo_query(DialogId dialog_id, FileId file_id,
tl_object_ptr<telegram_api::InputChatPhoto> &&input_chat_photo,
Promise<Unit> &&promise) {
// TODO invoke after
td_->create_handler<EditDialogPhotoQuery>(std::move(promise))
->send(file_id, was_uploaded, file_reference, dialog_id, std::move(input_chat_photo));
td_->create_handler<EditDialogPhotoQuery>(std::move(promise))->send(dialog_id, file_id, std::move(input_chat_photo));
}
void MessagesManager::upload_dialog_photo(DialogId dialog_id, FileId file_id, Promise<Unit> &&promise) {

View File

@ -1965,7 +1965,7 @@ class MessagesManager : public Actor {
void on_upload_dialog_photo(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file);
void on_upload_dialog_photo_error(FileId file_id, Status status);
void send_edit_dialog_photo_query(FileId file_id, bool was_uploaded, string file_reference, DialogId dialog_id,
void send_edit_dialog_photo_query(DialogId dialog_id, FileId file_id,
tl_object_ptr<telegram_api::InputChatPhoto> &&input_chat_photo,
Promise<Unit> &&promise);