Remove unneeded add_*_inner proxy functions.

GitOrigin-RevId: ef4e8233590c1d4133c65275474c32f7f985d217
This commit is contained in:
levlam 2019-11-30 21:22:40 +03:00
parent af04f95daa
commit c3d470a27c
4 changed files with 65 additions and 102 deletions

View File

@ -629,7 +629,7 @@ void AnimationsManager::add_saved_animation(const tl_object_ptr<td_api::InputFil
return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
} }
add_saved_animation_inner(r_file_id.ok(), std::move(promise)); add_saved_animation_impl(r_file_id.ok(), true, std::move(promise));
} }
void AnimationsManager::send_save_gif_query(FileId animation_id, bool unsave, Promise<Unit> &&promise) { void AnimationsManager::send_save_gif_query(FileId animation_id, bool unsave, Promise<Unit> &&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); ->send(animation_id, file_view.remote_location().as_input_document(), unsave);
} }
void AnimationsManager::add_saved_animation_inner(FileId animation_id, Promise<Unit> &&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) { void AnimationsManager::add_saved_animation_by_id(FileId animation_id) {
// TODO log event // TODO log event
Promise<Unit> promise; add_saved_animation_impl(animation_id, false, Auto());
add_saved_animation_impl(animation_id, promise);
} }
bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise<Unit> &promise) { void AnimationsManager::add_saved_animation_impl(FileId animation_id, bool add_on_server, Promise<Unit> &&promise) {
CHECK(!td_->auth_manager_->is_bot()); CHECK(!td_->auth_manager_->is_bot());
auto file_view = td_->file_manager_->get_file_view(animation_id); auto file_view = td_->file_manager_->get_file_view(animation_id);
if (file_view.empty()) { if (file_view.empty()) {
promise.set_error(Status::Error(7, "Animation file not found")); return promise.set_error(Status::Error(7, "Animation file not found"));
return false;
} }
LOG(INFO) << "Add saved animation " << animation_id << " with main file " << file_view.file_id(); LOG(INFO) << "Add saved animation " << animation_id << " with main file " << file_view.file_id();
if (!are_saved_animations_loaded_) { if (!are_saved_animations_loaded_) {
load_saved_animations(PromiseCreator::lambda([animation_id, promise = std::move(promise)](Result<> result) mutable { load_saved_animations(
if (result.is_ok()) { PromiseCreator::lambda([animation_id, add_on_server, promise = std::move(promise)](Result<> result) mutable {
send_closure(G()->animations_manager(), &AnimationsManager::add_saved_animation_inner, animation_id, if (result.is_ok()) {
std::move(promise)); send_closure(G()->animations_manager(), &AnimationsManager::add_saved_animation_impl, animation_id,
} else { add_on_server, std::move(promise));
promise.set_error(result.move_as_error()); } else {
} promise.set_error(result.move_as_error());
})); }
return false; }));
return;
} }
auto is_equal = [animation_id](FileId file_id) { auto is_equal = [animation_id](FileId file_id) {
@ -692,31 +685,25 @@ bool AnimationsManager::add_saved_animation_impl(FileId animation_id, Promise<Un
save_saved_animations_to_database(); save_saved_animations_to_database();
} }
promise.set_value(Unit()); return promise.set_value(Unit());
return false;
} }
auto animation = get_animation(animation_id); auto animation = get_animation(animation_id);
if (animation == nullptr) { if (animation == nullptr) {
promise.set_error(Status::Error(7, "Animation not found")); return promise.set_error(Status::Error(7, "Animation not found"));
return false;
} }
if (animation->mime_type != "video/mp4") { if (animation->mime_type != "video/mp4") {
promise.set_error(Status::Error(7, "Only MPEG4 animations can be saved")); return promise.set_error(Status::Error(7, "Only MPEG4 animations can be saved"));
return false;
} }
if (!file_view.has_remote_location()) { if (!file_view.has_remote_location()) {
promise.set_error(Status::Error(7, "Can save only sent animations")); return promise.set_error(Status::Error(7, "Can save only sent animations"));
return false;
} }
if (file_view.remote_location().is_web()) { if (file_view.remote_location().is_web()) {
promise.set_error(Status::Error(7, "Can't save web animations")); return promise.set_error(Status::Error(7, "Can't save web animations"));
return false;
} }
if (!file_view.remote_location().is_document()) { if (!file_view.remote_location().is_document()) {
promise.set_error(Status::Error(7, "Can't save encrypted animations")); return promise.set_error(Status::Error(7, "Can't save encrypted animations"));
return false;
} }
auto it = std::find_if(saved_animation_ids_.begin(), saved_animation_ids_.end(), is_equal); 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<Un
} }
send_update_saved_animations(); send_update_saved_animations();
return true; if (add_on_server) {
send_save_gif_query(animation_id, false, std::move(promise));
}
} }
void AnimationsManager::remove_saved_animation(const tl_object_ptr<td_api::InputFile> &input_file, void AnimationsManager::remove_saved_animation(const tl_object_ptr<td_api::InputFile> &input_file,

View File

@ -109,9 +109,7 @@ class AnimationsManager : public Actor {
int32 get_saved_animations_hash(const char *source) const; int32 get_saved_animations_hash(const char *source) const;
void add_saved_animation_inner(FileId animation_id, Promise<Unit> &&promise); void add_saved_animation_impl(FileId animation_id, bool add_on_server, Promise<Unit> &&promise);
bool add_saved_animation_impl(FileId animation_id, Promise<Unit> &promise);
void load_saved_animations(Promise<Unit> &&promise); void load_saved_animations(Promise<Unit> &&promise);

View File

@ -4234,13 +4234,7 @@ void StickersManager::add_recent_sticker(bool is_attached, const tl_object_ptr<t
return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
} }
add_recent_sticker_inner(is_attached, r_file_id.ok(), std::move(promise)); add_recent_sticker_impl(is_attached, r_file_id.ok(), true, std::move(promise));
}
void StickersManager::add_recent_sticker_inner(bool is_attached, FileId sticker_id, Promise<Unit> &&promise) {
if (add_recent_sticker_impl(is_attached, sticker_id, promise)) {
send_save_recent_sticker_query(is_attached, sticker_id, false, std::move(promise));
}
} }
void StickersManager::send_save_recent_sticker_query(bool is_attached, FileId sticker_id, bool unsave, 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) { void StickersManager::add_recent_sticker_by_id(bool is_attached, FileId sticker_id) {
// TODO log event // TODO log event
Promise<Unit> promise; add_recent_sticker_impl(is_attached, sticker_id, false, Auto());
add_recent_sticker_impl(is_attached, sticker_id, promise);
} }
bool StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_id, Promise<Unit> &promise) { void StickersManager::add_recent_sticker_impl(bool is_attached, FileId sticker_id, bool add_on_server,
Promise<Unit> &&promise) {
CHECK(!td_->auth_manager_->is_bot()); CHECK(!td_->auth_manager_->is_bot());
LOG(INFO) << "Add recent " << (is_attached ? "attached " : "") << "sticker " << sticker_id; LOG(INFO) << "Add recent " << (is_attached ? "attached " : "") << "sticker " << sticker_id;
if (!are_recent_stickers_loaded_[is_attached]) { 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 { promise = std::move(promise)](Result<> result) mutable {
if (result.is_ok()) { if (result.is_ok()) {
send_closure(G()->stickers_manager(), &StickersManager::add_recent_sticker_inner, send_closure(G()->stickers_manager(), &StickersManager::add_recent_sticker_impl,
is_attached, sticker_id, std::move(promise)); is_attached, sticker_id, add_on_server, std::move(promise));
} else { } else {
promise.set_error(result.move_as_error()); promise.set_error(result.move_as_error());
} }
})); }));
return false; return;
} }
auto is_equal = [sticker_id](FileId file_id) { 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); save_recent_stickers_to_database(is_attached);
} }
promise.set_value(Unit()); return promise.set_value(Unit());
return false;
} }
auto sticker = get_sticker(sticker_id); auto sticker = get_sticker(sticker_id);
if (sticker == nullptr) { if (sticker == nullptr) {
promise.set_error(Status::Error(7, "Sticker not found")); return promise.set_error(Status::Error(7, "Sticker not found"));
return false;
} }
if (!sticker->set_id.is_valid()) { if (!sticker->set_id.is_valid()) {
promise.set_error(Status::Error(7, "Stickers without sticker set can't be added to recent")); return promise.set_error(Status::Error(7, "Stickers without sticker set can't be added to recent"));
return false;
} }
auto file_view = td_->file_manager_->get_file_view(sticker_id); auto file_view = td_->file_manager_->get_file_view(sticker_id);
if (!file_view.has_remote_location()) { if (!file_view.has_remote_location()) {
promise.set_error(Status::Error(7, "Can save only sent stickers")); return promise.set_error(Status::Error(7, "Can save only sent stickers"));
return false;
} }
if (file_view.remote_location().is_web()) { if (file_view.remote_location().is_web()) {
promise.set_error(Status::Error(7, "Can't save web stickers")); return promise.set_error(Status::Error(7, "Can't save web stickers"));
return false;
} }
if (!file_view.remote_location().is_document()) { if (!file_view.remote_location().is_document()) {
promise.set_error(Status::Error(7, "Can't save encrypted stickers")); return promise.set_error(Status::Error(7, "Can't save encrypted stickers"));
return false;
} }
need_update_recent_stickers_[is_attached] = true; 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(); 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<td_api::InputFile> &input_file, void StickersManager::remove_recent_sticker(bool is_attached, const tl_object_ptr<td_api::InputFile> &input_file,
@ -4646,13 +4636,7 @@ void StickersManager::add_favorite_sticker(const tl_object_ptr<td_api::InputFile
return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code return promise.set_error(Status::Error(7, r_file_id.error().message())); // TODO do not drop error code
} }
add_favorite_sticker_inner(r_file_id.ok(), std::move(promise)); add_favorite_sticker_impl(r_file_id.ok(), true, std::move(promise));
}
void StickersManager::add_favorite_sticker_inner(FileId sticker_id, Promise<Unit> &&promise) {
if (add_favorite_sticker_impl(sticker_id, promise)) {
send_fave_sticker_query(sticker_id, false, std::move(promise));
}
} }
void StickersManager::send_fave_sticker_query(FileId sticker_id, bool unsave, Promise<Unit> &&promise) { void StickersManager::send_fave_sticker_query(FileId sticker_id, bool unsave, Promise<Unit> &&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) { void StickersManager::add_favorite_sticker_by_id(FileId sticker_id) {
// TODO log event // TODO log event
Promise<Unit> promise; add_favorite_sticker_impl(sticker_id, false, Auto());
add_favorite_sticker_impl(sticker_id, promise);
} }
bool StickersManager::add_favorite_sticker_impl(FileId sticker_id, Promise<Unit> &promise) { void StickersManager::add_favorite_sticker_impl(FileId sticker_id, bool add_on_server, Promise<Unit> &&promise) {
CHECK(!td_->auth_manager_->is_bot()); CHECK(!td_->auth_manager_->is_bot());
if (!are_favorite_stickers_loaded_) { if (!are_favorite_stickers_loaded_) {
load_favorite_stickers(PromiseCreator::lambda([sticker_id, promise = std::move(promise)](Result<> result) mutable { load_favorite_stickers(
if (result.is_ok()) { PromiseCreator::lambda([sticker_id, add_on_server, promise = std::move(promise)](Result<> result) mutable {
send_closure(G()->stickers_manager(), &StickersManager::add_favorite_sticker_inner, sticker_id, if (result.is_ok()) {
std::move(promise)); send_closure(G()->stickers_manager(), &StickersManager::add_favorite_sticker_impl, sticker_id,
} else { add_on_server, std::move(promise));
promise.set_error(result.move_as_error()); } else {
} promise.set_error(result.move_as_error());
})); }
return false; }));
return;
} }
auto is_equal = [sticker_id](FileId file_id) { auto is_equal = [sticker_id](FileId file_id) {
@ -4700,32 +4684,26 @@ bool StickersManager::add_favorite_sticker_impl(FileId sticker_id, Promise<Unit>
save_favorite_stickers_to_database(); save_favorite_stickers_to_database();
} }
promise.set_value(Unit()); return promise.set_value(Unit());
return false;
} }
auto sticker = get_sticker(sticker_id); auto sticker = get_sticker(sticker_id);
if (sticker == nullptr) { if (sticker == nullptr) {
promise.set_error(Status::Error(7, "Sticker not found")); return promise.set_error(Status::Error(7, "Sticker not found"));
return false;
} }
if (!sticker->set_id.is_valid()) { if (!sticker->set_id.is_valid()) {
promise.set_error(Status::Error(7, "Stickers without sticker set can't be favorite")); return promise.set_error(Status::Error(7, "Stickers without sticker set can't be favorite"));
return false;
} }
auto file_view = td_->file_manager_->get_file_view(sticker_id); auto file_view = td_->file_manager_->get_file_view(sticker_id);
if (!file_view.has_remote_location()) { if (!file_view.has_remote_location()) {
promise.set_error(Status::Error(7, "Can add to favorites only sent stickers")); return promise.set_error(Status::Error(7, "Can add to favorites only sent stickers"));
return false;
} }
if (file_view.remote_location().is_web()) { if (file_view.remote_location().is_web()) {
promise.set_error(Status::Error(7, "Can't add to favorites web stickers")); return promise.set_error(Status::Error(7, "Can't add to favorites web stickers"));
return false;
} }
if (!file_view.remote_location().is_document()) { if (!file_view.remote_location().is_document()) {
promise.set_error(Status::Error(7, "Can't add to favorites encrypted stickers")); return promise.set_error(Status::Error(7, "Can't add to favorites encrypted stickers"));
return false;
} }
auto it = std::find_if(favorite_sticker_ids_.begin(), favorite_sticker_ids_.end(), is_equal); 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<Unit>
} }
send_update_favorite_stickers(); 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<td_api::InputFile> &input_file, void StickersManager::remove_favorite_sticker(const tl_object_ptr<td_api::InputFile> &input_file,

View File

@ -436,15 +436,11 @@ class StickersManager : public Actor {
void save_recent_stickers_to_database(bool is_attached); void save_recent_stickers_to_database(bool is_attached);
void add_recent_sticker_inner(bool is_attached, FileId sticker_id, Promise<Unit> &&promise); void add_recent_sticker_impl(bool is_attached, FileId sticker_id, bool add_on_server, Promise<Unit> &&promise);
bool add_recent_sticker_impl(bool is_attached, FileId sticker_id, Promise<Unit> &promise);
int32 get_favorite_stickers_hash() const; int32 get_favorite_stickers_hash() const;
void add_favorite_sticker_inner(FileId sticker_id, Promise<Unit> &&promise); void add_favorite_sticker_impl(FileId sticker_id, bool add_on_server, Promise<Unit> &&promise);
bool add_favorite_sticker_impl(FileId sticker_id, Promise<Unit> &promise);
void load_favorite_stickers(Promise<Unit> &&promise); void load_favorite_stickers(Promise<Unit> &&promise);