Add and use is_same_dialog_photo.

This commit is contained in:
levlam 2022-04-28 21:02:44 +03:00
parent d106148618
commit f421cff7f3
3 changed files with 15 additions and 6 deletions

View File

@ -9796,9 +9796,7 @@ void ContactsManager::on_load_chat_full_from_database(ChatId chat_id, string val
} }
} }
if (td_->file_manager_->get_file_view(c->photo.small_file_id).get_unique_file_id() != if (!is_same_dialog_photo(td_->file_manager_.get(), DialogId(chat_id), chat_full->photo, c->photo)) {
td_->file_manager_->get_file_view(as_fake_dialog_photo(chat_full->photo, DialogId(chat_id)).small_file_id)
.get_unique_file_id()) {
chat_full->photo = Photo(); chat_full->photo = Photo();
if (c->photo.small_file_id.is_valid()) { if (c->photo.small_file_id.is_valid()) {
reload_chat_full(chat_id, Auto()); reload_chat_full(chat_id, Auto());
@ -9909,9 +9907,7 @@ void ContactsManager::on_load_channel_full_from_database(ChannelId channel_id, s
} }
} }
if (td_->file_manager_->get_file_view(c->photo.small_file_id).get_unique_file_id() != if (!is_same_dialog_photo(td_->file_manager_.get(), DialogId(channel_id), channel_full->photo, c->photo)) {
td_->file_manager_->get_file_view(as_fake_dialog_photo(channel_full->photo, DialogId(channel_id)).small_file_id)
.get_unique_file_id()) {
channel_full->photo = Photo(); channel_full->photo = Photo();
if (c->photo.small_file_id.is_valid()) { if (c->photo.small_file_id.is_valid()) {
channel_full->expires_at = 0.0; channel_full->expires_at = 0.0;

View File

@ -194,6 +194,16 @@ ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 u
return result; return result;
} }
bool is_same_dialog_photo(FileManager *file_manager, DialogId dialog_id, const Photo &photo,
const DialogPhoto &dialog_photo) {
auto get_unique_file_id = [file_manager](FileId file_id) {
return file_manager->get_file_view(file_id).get_unique_file_id();
};
auto fake_photo = as_fake_dialog_photo(photo, dialog_id);
return get_unique_file_id(fake_photo.small_file_id) == get_unique_file_id(dialog_photo.small_file_id) &&
get_unique_file_id(fake_photo.big_file_id) == get_unique_file_id(dialog_photo.big_file_id);
}
bool operator==(const DialogPhoto &lhs, const DialogPhoto &rhs) { bool operator==(const DialogPhoto &lhs, const DialogPhoto &rhs) {
return lhs.small_file_id == rhs.small_file_id && lhs.big_file_id == rhs.big_file_id && return lhs.small_file_id == rhs.small_file_id && lhs.big_file_id == rhs.big_file_id &&
lhs.minithumbnail == rhs.minithumbnail && lhs.has_animation == rhs.has_animation; lhs.minithumbnail == rhs.minithumbnail && lhs.has_animation == rhs.has_animation;

View File

@ -74,6 +74,9 @@ DialogPhoto as_dialog_photo(FileManager *file_manager, DialogId dialog_id, int64
ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash, const Photo &photo); ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash, const Photo &photo);
bool is_same_dialog_photo(FileManager *file_manager, DialogId dialog_id, const Photo &photo,
const DialogPhoto &dialog_photo);
vector<FileId> dialog_photo_get_file_ids(const DialogPhoto &dialog_photo); vector<FileId> dialog_photo_get_file_ids(const DialogPhoto &dialog_photo);
bool operator==(const DialogPhoto &lhs, const DialogPhoto &rhs); bool operator==(const DialogPhoto &lhs, const DialogPhoto &rhs);