diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 43323b3a5..c2f1246ab 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -11323,7 +11323,7 @@ void ContactsManager::do_update_user_photo(User *u, UserId user_id, void ContactsManager::do_update_user_photo(User *u, UserId user_id, ProfilePhoto &&new_photo, bool invalidate_photo_cache, const char *source) { u->is_photo_inited = true; - if (new_photo != u->photo) { + if (need_update_profile_photo(u->photo, new_photo)) { LOG_IF(ERROR, u->access_hash == -1 && new_photo.small_file_id.is_valid()) << "Update profile photo of " << user_id << " without access hash from " << source; u->photo = new_photo; @@ -13458,7 +13458,7 @@ void ContactsManager::on_update_chat_photo(Chat *c, DialogPhoto &&photo) { photo.minithumbnail.clear(); } - if (photo != c->photo) { + if (need_update_dialog_photo(c->photo, photo)) { c->photo = std::move(photo); c->is_photo_changed = true; c->need_save_to_database = true; @@ -13587,7 +13587,7 @@ void ContactsManager::on_update_channel_photo(Channel *c, DialogPhoto &&photo) { photo.minithumbnail.clear(); } - if (photo != c->photo) { + if (need_update_dialog_photo(c->photo, photo)) { c->photo = std::move(photo); c->is_photo_changed = true; c->need_save_to_database = true; diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index f91d3c8a4..f0d733eec 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -67,18 +67,8 @@ tl_object_ptr get_profile_photo_object(FileManager *file_m profile_photo.has_animation); } -bool operator==(const ProfilePhoto &lhs, const ProfilePhoto &rhs) { - bool location_differs = lhs.small_file_id != rhs.small_file_id || lhs.big_file_id != rhs.big_file_id; - bool id_differs = lhs.id != rhs.id; - - if (location_differs) { - return false; - } - return lhs.has_animation == rhs.has_animation && lhs.minithumbnail == rhs.minithumbnail && !id_differs; -} - -bool operator!=(const ProfilePhoto &lhs, const ProfilePhoto &rhs) { - return !(lhs == rhs); +bool need_update_profile_photo(const ProfilePhoto &from, const ProfilePhoto &to) { + return from.id != to.id || need_update_dialog_photo(from, to); } StringBuilder &operator<<(StringBuilder &string_builder, const ProfilePhoto &profile_photo) { @@ -204,13 +194,10 @@ bool is_same_dialog_photo(FileManager *file_manager, DialogId dialog_id, const P 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) { - 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; -} - -bool operator!=(const DialogPhoto &lhs, const DialogPhoto &rhs) { - return !(lhs == rhs); +bool need_update_dialog_photo(const DialogPhoto &from, const DialogPhoto &to) { + return from.small_file_id != to.small_file_id || from.big_file_id != to.big_file_id || + from.has_animation != to.has_animation || + need_update_dialog_photo_minithumbnail(from.minithumbnail, to.minithumbnail); } StringBuilder &operator<<(StringBuilder &string_builder, const DialogPhoto &dialog_photo) { diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index a6345e9b9..577ad4e47 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -57,8 +57,7 @@ ProfilePhoto get_profile_photo(FileManager *file_manager, UserId user_id, int64 tl_object_ptr get_profile_photo_object(FileManager *file_manager, const ProfilePhoto &profile_photo); -bool operator==(const ProfilePhoto &lhs, const ProfilePhoto &rhs); -bool operator!=(const ProfilePhoto &lhs, const ProfilePhoto &rhs); +bool need_update_profile_photo(const ProfilePhoto &from, const ProfilePhoto &to); StringBuilder &operator<<(StringBuilder &string_builder, const ProfilePhoto &profile_photo); @@ -79,8 +78,7 @@ bool is_same_dialog_photo(FileManager *file_manager, DialogId dialog_id, const P vector 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); +bool need_update_dialog_photo(const DialogPhoto &from, const DialogPhoto &to); StringBuilder &operator<<(StringBuilder &string_builder, const DialogPhoto &dialog_photo); diff --git a/td/telegram/PhotoSize.cpp b/td/telegram/PhotoSize.cpp index db1688c72..4772c4d39 100644 --- a/td/telegram/PhotoSize.cpp +++ b/td/telegram/PhotoSize.cpp @@ -57,6 +57,27 @@ StringBuilder &operator<<(StringBuilder &string_builder, const Dimensions &dimen return string_builder << "(" << dimensions.width << ", " << dimensions.height << ")"; } +static int32 get_minithumbnail_size(const string &packed) { + if (packed.size() < 3) { + return 0; + } + if (packed[0] == '\x01') { + return max(static_cast(packed[1]), static_cast(packed[2])); + } + return 0; +} + +bool need_update_dialog_photo_minithumbnail(const string &from, const string &to) { + if (from == to) { + return false; + } + + auto from_size = get_minithumbnail_size(from); + auto to_size = get_minithumbnail_size(to); + // dialog photo minithumbnail is expected to be 8x8 + return to_size != 0 && (to_size <= 8 || from_size > 8); +} + td_api::object_ptr get_minithumbnail_object(const string &packed) { if (packed.size() < 3) { return nullptr; diff --git a/td/telegram/PhotoSize.h b/td/telegram/PhotoSize.h index d73903b43..2510983ca 100644 --- a/td/telegram/PhotoSize.h +++ b/td/telegram/PhotoSize.h @@ -48,6 +48,8 @@ bool operator!=(const Dimensions &lhs, const Dimensions &rhs); StringBuilder &operator<<(StringBuilder &string_builder, const Dimensions &dimensions); +bool need_update_dialog_photo_minithumbnail(const string &from, const string &to); + td_api::object_ptr get_minithumbnail_object(const string &packed); FileId register_photo_size(FileManager *file_manager, const PhotoSizeSource &source, int64 id, int64 access_hash,