Change file_id type in as_profile_photo.

GitOrigin-RevId: fe45d895b4781c942512d5c838d99449431440d3
This commit is contained in:
levlam 2020-07-20 17:46:54 +03:00
parent a01ad861bd
commit 405934676e
6 changed files with 39 additions and 12 deletions

View File

@ -8559,7 +8559,7 @@ void ContactsManager::on_load_chat_full_from_database(ChatId chat_id, string val
Chat *c = get_chat(chat_id);
CHECK(c != nullptr);
if (td_->file_manager_->get_file_view(c->photo.small_file_id).get_unique_file_id() !=
td_->file_manager_->get_file_view(as_dialog_photo(chat_full->photo).small_file_id).get_unique_file_id()) {
td_->file_manager_->get_file_view(as_fake_dialog_photo(chat_full->photo).small_file_id).get_unique_file_id()) {
chat_full->photo = Photo();
if (c->photo.small_file_id.is_valid()) {
reload_chat_full(chat_id, Auto());
@ -8646,7 +8646,7 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s
Channel *c = get_channel(channel_id);
CHECK(c != nullptr);
if (td_->file_manager_->get_file_view(c->photo.small_file_id).get_unique_file_id() !=
td_->file_manager_->get_file_view(as_dialog_photo(channel_full->photo).small_file_id).get_unique_file_id()) {
td_->file_manager_->get_file_view(as_fake_dialog_photo(channel_full->photo).small_file_id).get_unique_file_id()) {
channel_full->photo = Photo();
if (c->photo.small_file_id.is_valid()) {
channel_full->expires_at = 0.0;
@ -10081,7 +10081,9 @@ bool ContactsManager::delete_profile_photo_from_cache(UserId user_id, int64 prof
bool need_reget_user = false;
if (it != user_photos_.end() && it->second.count != -1 && it->second.offset == 0 && !it->second.photos.empty()) {
// found exact new photo
do_update_user_photo(u, user_id, as_profile_photo(it->second.photos[0]), "delete_profile_photo_from_cache");
do_update_user_photo(u, user_id,
as_profile_photo(td_->file_manager_.get(), user_id, u->access_hash, it->second.photos[0]),
"delete_profile_photo_from_cache");
} else {
do_update_user_photo(u, user_id, ProfilePhoto(), "delete_profile_photo_from_cache 2");
need_reget_user = it == user_photos_.end() || it->second.count != 0;
@ -14176,7 +14178,7 @@ tl_object_ptr<td_api::chatInviteLinkInfo> ContactsManager::get_chat_invite_link_
}
} else {
title = invite_link_info->title;
invite_link_photo = as_dialog_photo(invite_link_info->photo);
invite_link_photo = as_fake_dialog_photo(invite_link_info->photo);
photo = &invite_link_photo;
participant_count = invite_link_info->participant_count;
member_user_ids = get_user_ids_object(invite_link_info->participant_user_ids, "get_chat_invite_link_info_object");

View File

@ -271,7 +271,7 @@ vector<FileId> dialog_photo_get_file_ids(const DialogPhoto &dialog_photo) {
return result;
}
DialogPhoto as_dialog_photo(const Photo &photo) {
DialogPhoto as_fake_dialog_photo(const Photo &photo) {
DialogPhoto result;
if (!photo.is_empty()) {
for (auto &size : photo.photos) {
@ -290,10 +290,28 @@ DialogPhoto as_dialog_photo(const Photo &photo) {
return result;
}
ProfilePhoto as_profile_photo(const Photo &photo) {
ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash, const Photo &photo) {
ProfilePhoto result;
static_cast<DialogPhoto &>(result) = as_dialog_photo(photo);
static_cast<DialogPhoto &>(result) = as_fake_dialog_photo(photo);
if (!result.small_file_id.is_valid()) {
return result;
}
auto reregister_photo = [&](bool is_big, FileId file_id) {
auto file_view = file_manager->get_file_view(file_id);
CHECK(file_view.has_remote_location());
auto remote = file_view.remote_location();
CHECK(remote.is_photo());
CHECK(!remote.is_web());
remote.set_source({DialogId(user_id), user_access_hash, is_big});
return file_manager->register_remote(std::move(remote), FileLocationSource::FromServer, DialogId(),
file_view.size(), file_view.expected_size(), file_view.remote_name());
};
result.id = photo.id.get();
result.small_file_id = reregister_photo(false, result.small_file_id);
result.big_file_id = reregister_photo(true, result.big_file_id);
return result;
}

View File

@ -94,9 +94,9 @@ DialogPhoto get_dialog_photo(FileManager *file_manager, DialogId dialog_id, int6
tl_object_ptr<td_api::chatPhotoInfo> get_chat_photo_info_object(FileManager *file_manager,
const DialogPhoto *dialog_photo);
DialogPhoto as_dialog_photo(const Photo &photo);
DialogPhoto as_fake_dialog_photo(const Photo &photo);
ProfilePhoto as_profile_photo(const Photo &photo);
ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash, const Photo &photo);
vector<FileId> dialog_photo_get_file_ids(const DialogPhoto &dialog_photo);

View File

@ -332,6 +332,12 @@ class FullRemoteFileLocation {
}
}
void set_source(PhotoSizeSource source) {
CHECK(is_photo());
file_type_ = source.get_file_type();
photo().source_ = std::move(source);
}
bool delete_file_reference(Slice bad_file_reference) {
if (file_reference_ != FileReferenceView::invalid_file_reference() && file_reference_ == bad_file_reference) {
file_reference_ = FileReferenceView::invalid_file_reference().str();

View File

@ -1096,13 +1096,13 @@ Result<FileId> FileManager::register_local(FullLocalFileLocation location, Dialo
}
FileId FileManager::register_remote(const FullRemoteFileLocation &location, FileLocationSource file_location_source,
DialogId owner_dialog_id, int64 size, int64 expected_size, string name) {
DialogId owner_dialog_id, int64 size, int64 expected_size, string remote_name) {
FileData data;
data.remote_ = RemoteFileLocation(location);
data.owner_dialog_id_ = owner_dialog_id;
data.size_ = size;
data.expected_size_ = expected_size;
data.remote_name_ = std::move(name);
data.remote_name_ = std::move(remote_name);
auto file_id = register_file(std::move(data), file_location_source, "register_remote", false).move_as_ok();
auto url = location.get_url();

View File

@ -419,7 +419,8 @@ class FileManager : public FileLoadManager::Callback {
bool get_by_hash = false, bool force = false,
bool skip_file_size_checks = false) TD_WARN_UNUSED_RESULT;
FileId register_remote(const FullRemoteFileLocation &location, FileLocationSource file_location_source,
DialogId owner_dialog_id, int64 size, int64 expected_size, string name) TD_WARN_UNUSED_RESULT;
DialogId owner_dialog_id, int64 size, int64 expected_size,
string remote_name) TD_WARN_UNUSED_RESULT;
Result<FileId> register_generate(FileType file_type, FileLocationSource file_location_source, string original_path,
string conversion, DialogId owner_dialog_id,
int64 expected_size) TD_WARN_UNUSED_RESULT;