Update remote_id in FileId list if possible.

GitOrigin-RevId: 3c42e3947ee454b786213e681e39220ab0fdccfe
This commit is contained in:
levlam 2018-03-08 21:04:28 +03:00
parent a25cfc3e06
commit ab9ce52e5c
4 changed files with 61 additions and 13 deletions

View File

@ -574,6 +574,11 @@ bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise<Un
}
if (!saved_animation_ids_.empty() && saved_animation_ids_[0] == animation_id) {
if (saved_animation_ids_[0].get_remote() == 0 && animation_id.get_remote() != 0) {
saved_animation_ids_[0] = animation_id;
save_saved_animations_to_database();
}
promise.set_value(Unit());
return false;
}
@ -612,6 +617,9 @@ bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise<Un
it = saved_animation_ids_.end() - 1;
}
std::rotate(saved_animation_ids_.begin(), it, it + 1);
if (saved_animation_ids_[0].get_remote() == 0 && animation_id.get_remote() != 0) {
saved_animation_ids_[0] = animation_id;
}
send_update_saved_animations();
return true;
@ -664,14 +672,20 @@ void AnimationsManager::send_update_saved_animations(bool from_database) {
}
send_closure(G()->td(), &Td::send_update, make_tl_object<td_api::updateSavedAnimations>(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);

View File

@ -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;

View File

@ -3517,6 +3517,11 @@ bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_i
vector<FileId> &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<td_api::updateRecentStickers>(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<Unit>
}
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<Unit>
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<td_api::updateFavoriteStickers>(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<string> StickersManager::get_sticker_emojis(const tl_object_ptr<td_api::InputFile> &input_file,
Promise<Unit> &&promise) {
auto r_file_id = td_->file_manager_->get_input_file_id(FileType::Sticker, input_file, DialogId(), false, false);

View File

@ -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<Unit> &&promise);
bool add_recent_sticker_impl(bool is_attached, FileId sticker_id, Promise<Unit> &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 <class T>
void store_sticker_set(const StickerSet *sticker_set, bool with_stickers, T &storer) const;