From c8cfee8d7bcb131048dec0c36155816be976c5ab Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 16 Feb 2019 05:29:28 +0300 Subject: [PATCH] Better deduplicating saved animations and recent/featured stickers. GitOrigin-RevId: 2bc58b3fabbf1cb01727e584036846e6acde0cc6 --- td/telegram/AnimationsManager.cpp | 12 +++++++++--- td/telegram/StickersManager.cpp | 16 ++++++++++++---- td/telegram/files/FileManager.cpp | 15 ++++++++++++--- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index fff5b730..dd18e523 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -664,7 +664,13 @@ bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise(saved_animation_ids_.size()) == saved_animations_limit_) { saved_animation_ids_.back() = animation_id; @@ -707,7 +713,7 @@ bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise &sticker_ids = recent_sticker_ids_[is_attached]; - if (!sticker_ids.empty() && sticker_ids[0] == sticker_id) { + if (!sticker_ids.empty() && is_equal(sticker_ids[0])) { if (sticker_ids[0].get_remote() == 0 && sticker_id.get_remote() != 0) { sticker_ids[0] = sticker_id; save_recent_stickers_to_database(is_attached); @@ -3953,7 +3957,7 @@ bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_i need_update_recent_stickers_[is_attached] = true; - auto it = std::find(sticker_ids.begin(), sticker_ids.end(), sticker_id); + auto it = std::find_if(sticker_ids.begin(), sticker_ids.end(), is_equal); if (it == sticker_ids.end()) { if (static_cast(sticker_ids.size()) == recent_stickers_limit_) { sticker_ids.back() = sticker_id; @@ -4311,7 +4315,11 @@ bool StickersManager::add_favorite_sticker_impl(FileId sticker_id, Promise return false; } - if (!favorite_sticker_ids_.empty() && favorite_sticker_ids_[0] == sticker_id) { + auto is_equal = [sticker_id](FileId file_id) { + return file_id == sticker_id || (file_id.get_remote() == sticker_id.get_remote() && sticker_id.get_remote() != 0); + }; + + if (!favorite_sticker_ids_.empty() && is_equal(favorite_sticker_ids_[0])) { if (favorite_sticker_ids_[0].get_remote() == 0 && sticker_id.get_remote() != 0) { favorite_sticker_ids_[0] = sticker_id; save_favorite_stickers_to_database(); @@ -4345,7 +4353,7 @@ bool StickersManager::add_favorite_sticker_impl(FileId sticker_id, Promise return false; } - auto it = std::find(favorite_sticker_ids_.begin(), favorite_sticker_ids_.end(), sticker_id); + auto it = std::find_if(favorite_sticker_ids_.begin(), favorite_sticker_ids_.end(), is_equal); if (it == favorite_sticker_ids_.end()) { if (static_cast(favorite_sticker_ids_.size()) == favorite_stickers_limit_) { favorite_sticker_ids_.back() = sticker_id; diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index c1bf4521..56005df3 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -1264,8 +1264,8 @@ Result FileManager::merge(FileId x_file_id, FileId y_file_id, bool no_sy if (x_node->remote_.full && y_node->remote_.full && !x_node->remote_.full.value().is_web() && !y_node->remote_.full.value().is_web() && y_node->remote_.is_full_alive && x_node->remote_.full.value().get_dc_id() != y_node->remote_.full.value().get_dc_id()) { - LOG(ERROR) << "File remote location was changed from " << y_node->remote_.full.value() << " to " - << x_node->remote_.full.value(); + LOG(WARNING) << "File remote location was changed from " << y_node->remote_.full.value() << " to " + << x_node->remote_.full.value(); } FileNodePtr nodes[] = {x_node, y_node, x_node}; @@ -2599,7 +2599,16 @@ Result FileManager::check_input_file_id(FileType type, Result re // But it will not be duped if has_input_media(), so for now we can't return main_file_id return dup_file_id(file_id); } - return FileId(file_node->main_file_id_.get(), file_id.get_remote()); + + int32 remote_id = file_id.get_remote(); + if (remote_id == 0) { + RemoteInfo info{file_view.remote_location(), FileLocationSource::FromUser, file_id}; + remote_id = remote_location_info_.add(info); + if (remote_location_info_.get(remote_id).file_id_ == file_id) { + get_file_id_info(file_id)->pin_flag_ = true; + } + } + return FileId(file_node->main_file_id_.get(), remote_id); } Result FileManager::get_input_thumbnail_file_id(const tl_object_ptr &thumbnail_input_file,