From ab9ce52e5ce0dec98c622839c6434e6d81706741 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 8 Mar 2018 21:04:28 +0300 Subject: [PATCH] Update remote_id in FileId list if possible. GitOrigin-RevId: 3c42e3947ee454b786213e681e39220ab0fdccfe --- td/telegram/AnimationsManager.cpp | 22 ++++++++++++--- td/telegram/AnimationsManager.h | 2 ++ td/telegram/StickersManager.cpp | 46 +++++++++++++++++++++++++------ td/telegram/StickersManager.h | 4 +++ 4 files changed, 61 insertions(+), 13 deletions(-) diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index 0ea5787a..6a372b1f 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -574,6 +574,11 @@ bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promisetd(), &Td::send_update, make_tl_object(std::move(animations))); - if (!from_database && G()->parameters().use_file_db) { - LOG(INFO) << "Save saved animations to database"; - AnimationListLogEvent log_event(saved_animation_ids_); - G()->td_db()->get_sqlite_pmc()->set("ans", log_event_store(log_event).as_slice().str(), Auto()); + if (!from_database) { + save_saved_animations_to_database(); } } } +void AnimationsManager::save_saved_animations_to_database() { + if (G()->parameters().use_file_db) { + LOG(INFO) << "Save saved animations to database"; + AnimationListLogEvent log_event(saved_animation_ids_); + G()->td_db()->get_sqlite_pmc()->set("ans", log_event_store(log_event).as_slice().str(), Auto()); + } +} + string AnimationsManager::get_animation_search_text(FileId file_id) const { auto animation = get_animation(file_id); CHECK(animation != nullptr); diff --git a/td/telegram/AnimationsManager.h b/td/telegram/AnimationsManager.h index 17fce985..3282d705 100644 --- a/td/telegram/AnimationsManager.h +++ b/td/telegram/AnimationsManager.h @@ -112,6 +112,8 @@ class AnimationsManager : public Actor { void send_update_saved_animations(bool from_database = false); + void save_saved_animations_to_database(); + void tear_down() override; class AnimationListLogEvent; diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 91568d13..dbe09da8 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -3517,6 +3517,11 @@ bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_i vector &sticker_ids = recent_sticker_ids_[is_attached]; if (!sticker_ids.empty() && sticker_ids[0] == sticker_id) { + if (sticker_ids[0].get_remote() == 0 && sticker_id.get_remote() != 0) { + sticker_ids[0] = sticker_id; + save_recent_stickers_to_database(is_attached); + } + promise.set_value(Unit()); return false; } @@ -3557,6 +3562,9 @@ bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_i it = sticker_ids.end() - 1; } std::rotate(sticker_ids.begin(), it, it + 1); + if (sticker_ids[0].get_remote() == 0 && sticker_id.get_remote() != 0) { + sticker_ids[0] = sticker_id; + } send_update_recent_stickers(); return true; @@ -3640,17 +3648,23 @@ void StickersManager::send_update_recent_stickers(bool from_database) { send_closure(G()->td(), &Td::send_update, make_tl_object(is_attached != 0, std::move(stickers))); - if (!from_database && G()->parameters().use_file_db) { - LOG(INFO) << "Save recent " << (is_attached ? "attached " : "") << "stickers to database"; - StickerListLogEvent log_event(recent_sticker_ids_[is_attached]); - G()->td_db()->get_sqlite_pmc()->set(is_attached ? "ssr1" : "ssr0", - log_event_store(log_event).as_slice().str(), Auto()); + if (!from_database) { + save_recent_stickers_to_database(is_attached != 0); } } } } } +void StickersManager::save_recent_stickers_to_database(bool is_attached) { + if (G()->parameters().use_file_db) { + LOG(INFO) << "Save recent " << (is_attached ? "attached " : "") << "stickers to database"; + StickerListLogEvent log_event(recent_sticker_ids_[is_attached]); + G()->td_db()->get_sqlite_pmc()->set(is_attached ? "ssr1" : "ssr0", log_event_store(log_event).as_slice().str(), + Auto()); + } +} + void StickersManager::on_update_recent_stickers_limit(int32 recent_stickers_limit) { if (recent_stickers_limit != recent_stickers_limit_) { if (recent_stickers_limit > 0) { @@ -3851,6 +3865,11 @@ bool StickersManager::add_favorite_sticker_impl(FileId sticker_id, Promise } if (!favorite_sticker_ids_.empty() && favorite_sticker_ids_[0] == sticker_id) { + if (favorite_sticker_ids_[0].get_remote() == 0 && sticker_id.get_remote() != 0) { + favorite_sticker_ids_[0] = sticker_id; + save_favorite_stickers_to_database(); + } + promise.set_value(Unit()); return false; } @@ -3889,6 +3908,9 @@ bool StickersManager::add_favorite_sticker_impl(FileId sticker_id, Promise it = favorite_sticker_ids_.end() - 1; } std::rotate(favorite_sticker_ids_.begin(), it, it + 1); + if (favorite_sticker_ids_[0].get_remote() == 0 && sticker_id.get_remote() != 0) { + favorite_sticker_ids_[0] = sticker_id; + } send_update_favorite_stickers(); return true; @@ -3942,14 +3964,20 @@ void StickersManager::send_update_favorite_stickers(bool from_database) { } send_closure(G()->td(), &Td::send_update, make_tl_object(std::move(stickers))); - if (!from_database && G()->parameters().use_file_db) { - LOG(INFO) << "Save favorite stickers to database"; - StickerListLogEvent log_event(favorite_sticker_ids_); - G()->td_db()->get_sqlite_pmc()->set("ssfav", log_event_store(log_event).as_slice().str(), Auto()); + if (!from_database) { + save_favorite_stickers_to_database(); } } } +void StickersManager::save_favorite_stickers_to_database() { + if (G()->parameters().use_file_db) { + LOG(INFO) << "Save favorite stickers to database"; + StickerListLogEvent log_event(favorite_sticker_ids_); + G()->td_db()->get_sqlite_pmc()->set("ssfav", log_event_store(log_event).as_slice().str(), Auto()); + } +} + vector StickersManager::get_sticker_emojis(const tl_object_ptr &input_file, Promise &&promise) { auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Sticker, input_file, DialogId(), false, false); diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index b9a0ed84..55be468f 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -367,6 +367,8 @@ class StickersManager : public Actor { void send_update_recent_stickers(bool from_database = false); + void save_recent_stickers_to_database(bool is_attached); + void add_recent_sticker_inner(bool is_attached, FileId sticker_id, Promise &&promise); bool add_recent_sticker_impl(bool is_attached, FileId sticker_id, Promise &promise); @@ -385,6 +387,8 @@ class StickersManager : public Actor { void send_update_favorite_stickers(bool from_database = false); + void save_favorite_stickers_to_database(); + template void store_sticker_set(const StickerSet *sticker_set, bool with_stickers, T &storer) const;