From c3d470a27c9a79b705774b6daa8b553c68aaf714 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 30 Nov 2019 21:22:40 +0300 Subject: [PATCH] Remove unneeded add_*_inner proxy functions. GitOrigin-RevId: ef4e8233590c1d4133c65275474c32f7f985d217 --- td/telegram/AnimationsManager.cpp | 57 ++++++++---------- td/telegram/AnimationsManager.h | 4 +- td/telegram/StickersManager.cpp | 98 ++++++++++++------------------- td/telegram/StickersManager.h | 8 +-- 4 files changed, 65 insertions(+), 102 deletions(-) diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index 10ec5c9ca..62530fc1b 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -629,7 +629,7 @@ void AnimationsManager::add_saved_animation(const tl_object_ptr &&promise) { @@ -646,38 +646,31 @@ void AnimationsManager::send_save_gif_query(FileId animation_id, bool unsave, Pr ->send(animation_id, file_view.remote_location().as_input_document(), unsave); } -void AnimationsManager::add_saved_animation_inner(FileId animation_id, Promise &&promise) { - if (add_saved_animation_impl(animation_id, promise)) { - send_save_gif_query(animation_id, false, std::move(promise)); - } -} - void AnimationsManager::add_saved_animation_by_id(FileId animation_id) { // TODO log event - Promise promise; - add_saved_animation_impl(animation_id, promise); + add_saved_animation_impl(animation_id, false, Auto()); } -bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise &promise) { +void AnimationsManager::add_saved_animation_impl(FileId animation_id, bool add_on_server, Promise &&promise) { CHECK(!td_->auth_manager_->is_bot()); auto file_view = td_->file_manager_->get_file_view(animation_id); if (file_view.empty()) { - promise.set_error(Status::Error(7, "Animation file not found")); - return false; + return promise.set_error(Status::Error(7, "Animation file not found")); } LOG(INFO) << "Add saved animation " << animation_id << " with main file " << file_view.file_id(); if (!are_saved_animations_loaded_) { - load_saved_animations(PromiseCreator::lambda([animation_id, promise = std::move(promise)](Result<> result) mutable { - if (result.is_ok()) { - send_closure(G()->animations_manager(), &AnimationsManager::add_saved_animation_inner, animation_id, - std::move(promise)); - } else { - promise.set_error(result.move_as_error()); - } - })); - return false; + load_saved_animations( + PromiseCreator::lambda([animation_id, add_on_server, promise = std::move(promise)](Result<> result) mutable { + if (result.is_ok()) { + send_closure(G()->animations_manager(), &AnimationsManager::add_saved_animation_impl, animation_id, + add_on_server, std::move(promise)); + } else { + promise.set_error(result.move_as_error()); + } + })); + return; } auto is_equal = [animation_id](FileId file_id) { @@ -692,31 +685,25 @@ bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promisemime_type != "video/mp4") { - promise.set_error(Status::Error(7, "Only MPEG4 animations can be saved")); - return false; + return promise.set_error(Status::Error(7, "Only MPEG4 animations can be saved")); } if (!file_view.has_remote_location()) { - promise.set_error(Status::Error(7, "Can save only sent animations")); - return false; + return promise.set_error(Status::Error(7, "Can save only sent animations")); } if (file_view.remote_location().is_web()) { - promise.set_error(Status::Error(7, "Can't save web animations")); - return false; + return promise.set_error(Status::Error(7, "Can't save web animations")); } if (!file_view.remote_location().is_document()) { - promise.set_error(Status::Error(7, "Can't save encrypted animations")); - return false; + return promise.set_error(Status::Error(7, "Can't save encrypted animations")); } auto it = std::find_if(saved_animation_ids_.begin(), saved_animation_ids_.end(), is_equal); @@ -735,7 +722,9 @@ bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise &input_file, diff --git a/td/telegram/AnimationsManager.h b/td/telegram/AnimationsManager.h index 102f44096..ed86e6728 100644 --- a/td/telegram/AnimationsManager.h +++ b/td/telegram/AnimationsManager.h @@ -109,9 +109,7 @@ class AnimationsManager : public Actor { int32 get_saved_animations_hash(const char *source) const; - void add_saved_animation_inner(FileId animation_id, Promise &&promise); - - bool add_saved_animation_impl(FileId animation_id, Promise &promise); + void add_saved_animation_impl(FileId animation_id, bool add_on_server, Promise &&promise); void load_saved_animations(Promise &&promise); diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 68aef461a..4e2aaf7c0 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -4234,13 +4234,7 @@ void StickersManager::add_recent_sticker(bool is_attached, const tl_object_ptr &&promise) { - if (add_recent_sticker_impl(is_attached, sticker_id, promise)) { - send_save_recent_sticker_query(is_attached, sticker_id, false, std::move(promise)); - } + add_recent_sticker_impl(is_attached, r_file_id.ok(), true, std::move(promise)); } void StickersManager::send_save_recent_sticker_query(bool is_attached, FileId sticker_id, bool unsave, @@ -4260,25 +4254,25 @@ void StickersManager::send_save_recent_sticker_query(bool is_attached, FileId st void StickersManager::add_recent_sticker_by_id(bool is_attached, FileId sticker_id) { // TODO log event - Promise promise; - add_recent_sticker_impl(is_attached, sticker_id, promise); + add_recent_sticker_impl(is_attached, sticker_id, false, Auto()); } -bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_id, Promise &promise) { +void StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_id, bool add_on_server, + Promise &&promise) { CHECK(!td_->auth_manager_->is_bot()); LOG(INFO) << "Add recent " << (is_attached ? "attached " : "") << "sticker " << sticker_id; if (!are_recent_stickers_loaded_[is_attached]) { - load_recent_stickers(is_attached, PromiseCreator::lambda([is_attached, sticker_id, + load_recent_stickers(is_attached, PromiseCreator::lambda([is_attached, sticker_id, add_on_server, promise = std::move(promise)](Result<> result) mutable { if (result.is_ok()) { - send_closure(G()->stickers_manager(), &StickersManager::add_recent_sticker_inner, - is_attached, sticker_id, std::move(promise)); + send_closure(G()->stickers_manager(), &StickersManager::add_recent_sticker_impl, + is_attached, sticker_id, add_on_server, std::move(promise)); } else { promise.set_error(result.move_as_error()); } })); - return false; + return; } auto is_equal = [sticker_id](FileId file_id) { @@ -4292,32 +4286,26 @@ bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_i save_recent_stickers_to_database(is_attached); } - promise.set_value(Unit()); - return false; + return promise.set_value(Unit()); } auto sticker = get_sticker(sticker_id); if (sticker == nullptr) { - promise.set_error(Status::Error(7, "Sticker not found")); - return false; + return promise.set_error(Status::Error(7, "Sticker not found")); } if (!sticker->set_id.is_valid()) { - promise.set_error(Status::Error(7, "Stickers without sticker set can't be added to recent")); - return false; + return promise.set_error(Status::Error(7, "Stickers without sticker set can't be added to recent")); } auto file_view = td_->file_manager_->get_file_view(sticker_id); if (!file_view.has_remote_location()) { - promise.set_error(Status::Error(7, "Can save only sent stickers")); - return false; + return promise.set_error(Status::Error(7, "Can save only sent stickers")); } if (file_view.remote_location().is_web()) { - promise.set_error(Status::Error(7, "Can't save web stickers")); - return false; + return promise.set_error(Status::Error(7, "Can't save web stickers")); } if (!file_view.remote_location().is_document()) { - promise.set_error(Status::Error(7, "Can't save encrypted stickers")); - return false; + return promise.set_error(Status::Error(7, "Can't save encrypted stickers")); } need_update_recent_stickers_[is_attached] = true; @@ -4337,7 +4325,9 @@ bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_i } send_update_recent_stickers(); - return true; + if (add_on_server) { + send_save_recent_sticker_query(is_attached, sticker_id, false, std::move(promise)); + } } void StickersManager::remove_recent_sticker(bool is_attached, const tl_object_ptr &input_file, @@ -4646,13 +4636,7 @@ void StickersManager::add_favorite_sticker(const tl_object_ptr &&promise) { - if (add_favorite_sticker_impl(sticker_id, promise)) { - send_fave_sticker_query(sticker_id, false, std::move(promise)); - } + add_favorite_sticker_impl(r_file_id.ok(), true, std::move(promise)); } void StickersManager::send_fave_sticker_query(FileId sticker_id, bool unsave, Promise &&promise) { @@ -4671,23 +4655,23 @@ void StickersManager::send_fave_sticker_query(FileId sticker_id, bool unsave, Pr void StickersManager::add_favorite_sticker_by_id(FileId sticker_id) { // TODO log event - Promise promise; - add_favorite_sticker_impl(sticker_id, promise); + add_favorite_sticker_impl(sticker_id, false, Auto()); } -bool StickersManager::add_favorite_sticker_impl(FileId sticker_id, Promise &promise) { +void StickersManager::add_favorite_sticker_impl(FileId sticker_id, bool add_on_server, Promise &&promise) { CHECK(!td_->auth_manager_->is_bot()); if (!are_favorite_stickers_loaded_) { - load_favorite_stickers(PromiseCreator::lambda([sticker_id, promise = std::move(promise)](Result<> result) mutable { - if (result.is_ok()) { - send_closure(G()->stickers_manager(), &StickersManager::add_favorite_sticker_inner, sticker_id, - std::move(promise)); - } else { - promise.set_error(result.move_as_error()); - } - })); - return false; + load_favorite_stickers( + PromiseCreator::lambda([sticker_id, add_on_server, promise = std::move(promise)](Result<> result) mutable { + if (result.is_ok()) { + send_closure(G()->stickers_manager(), &StickersManager::add_favorite_sticker_impl, sticker_id, + add_on_server, std::move(promise)); + } else { + promise.set_error(result.move_as_error()); + } + })); + return; } auto is_equal = [sticker_id](FileId file_id) { @@ -4700,32 +4684,26 @@ bool StickersManager::add_favorite_sticker_impl(FileId sticker_id, Promise save_favorite_stickers_to_database(); } - promise.set_value(Unit()); - return false; + return promise.set_value(Unit()); } auto sticker = get_sticker(sticker_id); if (sticker == nullptr) { - promise.set_error(Status::Error(7, "Sticker not found")); - return false; + return promise.set_error(Status::Error(7, "Sticker not found")); } if (!sticker->set_id.is_valid()) { - promise.set_error(Status::Error(7, "Stickers without sticker set can't be favorite")); - return false; + return promise.set_error(Status::Error(7, "Stickers without sticker set can't be favorite")); } auto file_view = td_->file_manager_->get_file_view(sticker_id); if (!file_view.has_remote_location()) { - promise.set_error(Status::Error(7, "Can add to favorites only sent stickers")); - return false; + return promise.set_error(Status::Error(7, "Can add to favorites only sent stickers")); } if (file_view.remote_location().is_web()) { - promise.set_error(Status::Error(7, "Can't add to favorites web stickers")); - return false; + return promise.set_error(Status::Error(7, "Can't add to favorites web stickers")); } if (!file_view.remote_location().is_document()) { - promise.set_error(Status::Error(7, "Can't add to favorites encrypted stickers")); - return false; + return promise.set_error(Status::Error(7, "Can't add to favorites encrypted stickers")); } auto it = std::find_if(favorite_sticker_ids_.begin(), favorite_sticker_ids_.end(), is_equal); @@ -4743,7 +4721,9 @@ bool StickersManager::add_favorite_sticker_impl(FileId sticker_id, Promise } send_update_favorite_stickers(); - return true; + if (add_on_server) { + send_fave_sticker_query(sticker_id, false, std::move(promise)); + } } void StickersManager::remove_favorite_sticker(const tl_object_ptr &input_file, diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index 08df1eb07..f0078e825 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -436,15 +436,11 @@ class StickersManager : public Actor { 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); + void add_recent_sticker_impl(bool is_attached, FileId sticker_id, bool add_on_server, Promise &&promise); int32 get_favorite_stickers_hash() const; - void add_favorite_sticker_inner(FileId sticker_id, Promise &&promise); - - bool add_favorite_sticker_impl(FileId sticker_id, Promise &promise); + void add_favorite_sticker_impl(FileId sticker_id, bool add_on_server, Promise &&promise); void load_favorite_stickers(Promise &&promise);