Repair file_reference in editMessageMedia.
GitOrigin-RevId: 9826a975dda2838d12943efa03752a79ddee7765
This commit is contained in:
parent
c958bd5b7c
commit
c474ce5994
@ -2123,7 +2123,12 @@ tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *co
|
||||
}
|
||||
|
||||
tl_object_ptr<telegram_api::InputMedia> get_input_media(const MessageContent *content, Td *td, int32 ttl) {
|
||||
return get_input_media(content, td, nullptr, nullptr, ttl);
|
||||
auto input_media = get_input_media(content, td, nullptr, nullptr, ttl);
|
||||
auto file_reference = FileManager::extract_file_reference(input_media);
|
||||
if (file_reference == FullRemoteFileLocation::invalid_file_reference()) {
|
||||
return nullptr;
|
||||
}
|
||||
return input_media;
|
||||
}
|
||||
|
||||
void delete_message_content_thumbnail(MessageContent *content, Td *td) {
|
||||
|
@ -15362,11 +15362,13 @@ void MessagesManager::on_message_media_uploaded(DialogId dialog_id, Message *m,
|
||||
bool was_thumbnail_uploaded = FileManager::extract_was_thumbnail_uploaded(input_media);
|
||||
|
||||
LOG(INFO) << "Edit media from " << message_id << " in " << dialog_id;
|
||||
auto promise = PromiseCreator::lambda([actor_id = actor_id(this), dialog_id, message_id, file_id, thumbnail_file_id,
|
||||
generation = m->edit_generation, was_uploaded,
|
||||
was_thumbnail_uploaded](Result<Unit> result) {
|
||||
auto promise = PromiseCreator::lambda(
|
||||
[actor_id = actor_id(this), dialog_id, message_id, file_id, thumbnail_file_id, generation = m->edit_generation,
|
||||
was_uploaded, was_thumbnail_uploaded,
|
||||
file_reference = FileManager::extract_file_reference(input_media)](Result<Unit> result) mutable {
|
||||
send_closure(actor_id, &MessagesManager::on_message_media_edited, dialog_id, message_id, file_id,
|
||||
thumbnail_file_id, was_uploaded, was_thumbnail_uploaded, generation, std::move(result));
|
||||
thumbnail_file_id, was_uploaded, was_thumbnail_uploaded, std::move(file_reference), generation,
|
||||
std::move(result));
|
||||
});
|
||||
send_closure(td_->create_net_actor<EditMessageActor>(std::move(promise)), &EditMessageActor::send, 1 << 11,
|
||||
dialog_id, message_id, caption == nullptr ? "" : caption->text,
|
||||
@ -16296,7 +16298,7 @@ void MessagesManager::cancel_edit_message_media(DialogId dialog_id, Message *m)
|
||||
|
||||
void MessagesManager::on_message_media_edited(DialogId dialog_id, MessageId message_id, FileId file_id,
|
||||
FileId thumbnail_file_id, bool was_uploaded, bool was_thumbnail_uploaded,
|
||||
uint64 generation, Result<Unit> &&result) {
|
||||
string file_reference, uint64 generation, Result<Unit> &&result) {
|
||||
CHECK(message_id.is_server());
|
||||
auto m = get_message({dialog_id, message_id});
|
||||
if (m == nullptr || m->edit_generation != generation) {
|
||||
@ -16316,7 +16318,6 @@ void MessagesManager::on_message_media_edited(DialogId dialog_id, MessageId mess
|
||||
m->content->get_type() == MessageContentType::Photo;
|
||||
update_message_content(dialog_id, m, std::move(m->edited_content), need_send_update_message_content, true);
|
||||
} else {
|
||||
auto error_message = result.error().message();
|
||||
if (was_uploaded) {
|
||||
if (was_thumbnail_uploaded) {
|
||||
CHECK(thumbnail_file_id.is_valid());
|
||||
@ -16324,6 +16325,7 @@ void MessagesManager::on_message_media_edited(DialogId dialog_id, MessageId mess
|
||||
td_->file_manager_->delete_partial_remote_location(thumbnail_file_id);
|
||||
}
|
||||
CHECK(file_id.is_valid());
|
||||
auto error_message = result.error().message();
|
||||
if (begins_with(error_message, "FILE_PART_") && ends_with(error_message, "_MISSING")) {
|
||||
do_send_message(dialog_id, m, {to_integer<int32>(error_message.substr(10))});
|
||||
return;
|
||||
@ -16332,6 +16334,14 @@ void MessagesManager::on_message_media_edited(DialogId dialog_id, MessageId mess
|
||||
if (result.error().code() != 429 && result.error().code() < 500 && !G()->close_flag()) {
|
||||
td_->file_manager_->delete_partial_remote_location(file_id);
|
||||
}
|
||||
} else if (FileReferenceManager::is_file_reference_error(result.error())) {
|
||||
if (file_id.is_valid()) {
|
||||
td_->file_manager_->delete_file_reference(file_id, file_reference);
|
||||
do_send_message(dialog_id, m, {-1});
|
||||
return;
|
||||
} else {
|
||||
LOG(ERROR) << "Receive file reference error, but have no file_id";
|
||||
}
|
||||
}
|
||||
|
||||
cancel_upload_message_content_files(m->edited_content.get());
|
||||
|
@ -1269,7 +1269,7 @@ class MessagesManager : public Actor {
|
||||
void cancel_edit_message_media(DialogId dialog_id, Message *m);
|
||||
|
||||
void on_message_media_edited(DialogId dialog_id, MessageId message_id, FileId file_id, FileId thumbnail_file_id,
|
||||
bool was_uploaded, bool was_thumbnail_uploaded, uint64 generation,
|
||||
bool was_uploaded, bool was_thumbnail_uploaded, string file_reference, uint64 generation,
|
||||
Result<Unit> &&result);
|
||||
|
||||
MessageId get_persistent_message_id(const Dialog *d, MessageId message_id) const;
|
||||
|
@ -2104,11 +2104,14 @@ void FileManager::run_upload(FileNodePtr node, std::vector<int> bad_parts) {
|
||||
return;
|
||||
}
|
||||
|
||||
bad_parts.erase(std::remove_if(bad_parts.begin(), bad_parts.end(), [](auto part_id) { return part_id < 0; }),
|
||||
bad_parts.end());
|
||||
|
||||
QueryId id = queries_container_.create(Query{file_id, Query::Upload});
|
||||
node->upload_id_ = id;
|
||||
auto new_priority = narrow_cast<int8>(bad_parts.empty() ? -priority : priority);
|
||||
send_closure(file_load_manager_, &FileLoadManager::upload, id, node->local_, node->remote_,
|
||||
file_view.expected_size(true), node->encryption_key_,
|
||||
narrow_cast<int8>(bad_parts.empty() ? -priority : priority), std::move(bad_parts));
|
||||
file_view.expected_size(true), node->encryption_key_, new_priority, std::move(bad_parts));
|
||||
|
||||
LOG(INFO) << "File " << file_id << " upload request has sent to FileLoadManager";
|
||||
}
|
||||
@ -2471,6 +2474,30 @@ bool FileManager::extract_was_thumbnail_uploaded(const tl_object_ptr<telegram_ap
|
||||
return static_cast<const telegram_api::inputMediaUploadedDocument *>(input_media.get())->thumb_ != nullptr;
|
||||
}
|
||||
|
||||
string FileManager::extract_file_reference(const tl_object_ptr<telegram_api::InputMedia> &input_media) {
|
||||
if (input_media != nullptr) {
|
||||
switch (input_media->get_id()) {
|
||||
case telegram_api::inputMediaDocument::ID: {
|
||||
const auto *id = static_cast<const telegram_api::inputMediaDocument *>(input_media.get())->id_.get();
|
||||
CHECK(id != nullptr);
|
||||
if (id->get_id() == telegram_api::inputDocument::ID) {
|
||||
return static_cast<const telegram_api::inputDocument *>(id)->file_reference_.as_slice().str();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case telegram_api::inputMediaPhoto::ID: {
|
||||
const auto *id = static_cast<const telegram_api::inputMediaPhoto *>(input_media.get())->id_.get();
|
||||
CHECK(id != nullptr);
|
||||
if (id->get_id() == telegram_api::inputPhoto::ID) {
|
||||
return static_cast<const telegram_api::inputPhoto *>(id)->file_reference_.as_slice().str();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return string();
|
||||
}
|
||||
|
||||
FileId FileManager::next_file_id() {
|
||||
if (!empty_file_ids_.empty()) {
|
||||
auto res = empty_file_ids_.back();
|
||||
|
@ -394,6 +394,7 @@ class FileManager : public FileLoadManager::Callback {
|
||||
|
||||
static bool extract_was_uploaded(const tl_object_ptr<telegram_api::InputMedia> &input_media);
|
||||
static bool extract_was_thumbnail_uploaded(const tl_object_ptr<telegram_api::InputMedia> &input_media);
|
||||
static string extract_file_reference(const tl_object_ptr<telegram_api::InputMedia> &input_media);
|
||||
|
||||
template <class T>
|
||||
void store_file(FileId file_id, T &storer, int32 ttl = 5) const;
|
||||
|
Reference in New Issue
Block a user