From 6790c309acd79d404b32444e37fe5b8c770d6cd1 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 12 May 2022 16:34:13 +0300 Subject: [PATCH] Move data reloading to UpdatesManager. --- td/telegram/AnimationsManager.cpp | 6 ----- td/telegram/AnimationsManager.h | 2 -- td/telegram/ContactsManager.cpp | 12 --------- td/telegram/ContactsManager.h | 6 ++--- td/telegram/NotificationSettingsManager.cpp | 4 --- td/telegram/StickersManager.cpp | 24 +++--------------- td/telegram/StickersManager.h | 10 +++----- td/telegram/UpdatesManager.cpp | 27 ++++++++++++++++++--- td/telegram/UpdatesManager.h | 2 ++ 9 files changed, 36 insertions(+), 57 deletions(-) diff --git a/td/telegram/AnimationsManager.cpp b/td/telegram/AnimationsManager.cpp index 152b1af38..6b1ad0b36 100644 --- a/td/telegram/AnimationsManager.cpp +++ b/td/telegram/AnimationsManager.cpp @@ -880,12 +880,6 @@ string AnimationsManager::get_animation_search_text(FileId file_id) const { return animation->file_name; } -void AnimationsManager::after_get_difference() { - if (td_->is_online() && !td_->auth_manager_->is_bot()) { - get_saved_animations(Auto()); - } -} - void AnimationsManager::get_current_state(vector> &updates) const { if (td_->auth_manager_->is_bot()) { return; diff --git a/td/telegram/AnimationsManager.h b/td/telegram/AnimationsManager.h index e9d9a65ad..e07856531 100644 --- a/td/telegram/AnimationsManager.h +++ b/td/telegram/AnimationsManager.h @@ -89,8 +89,6 @@ class AnimationsManager final : public Actor { string get_animation_search_text(FileId file_id) const; - void after_get_difference(); - void get_current_state(vector> &updates) const; private: diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 30eea6f50..76a8cba97 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -16715,18 +16715,6 @@ UserId ContactsManager::get_support_user(Promise &&promise) { return UserId(); } -void ContactsManager::after_get_difference() { - if (td_->auth_manager_->is_bot()) { - return; - } - get_user(get_my_id(), 3, Promise()); - - if (td_->is_online()) { - reload_created_public_dialogs(PublicDialogType::HasUsername, Promise>()); - reload_created_public_dialogs(PublicDialogType::IsLocationBased, Promise>()); - } -} - void ContactsManager::get_current_state(vector> &updates) const { for (auto user_id : unknown_users_) { if (!have_min_user(user_id)) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index a5bbf54d0..55335e2ef 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -439,6 +439,8 @@ class ContactsManager final : public Actor { void check_created_public_dialogs_limit(PublicDialogType type, Promise &&promise); + void reload_created_public_dialogs(PublicDialogType type, Promise> &&promise); + vector get_dialogs_for_discussion(Promise &&promise); vector get_inactive_channels(Promise &&promise); @@ -601,8 +603,6 @@ class ContactsManager final : public Actor { void repair_chat_participants(ChatId chat_id); - void after_get_difference(); - void get_current_state(vector> &updates) const; static tl_object_ptr convert_date_range( @@ -1455,8 +1455,6 @@ class ContactsManager final : public Actor { static void return_created_public_dialogs(Promise> &&promise, const vector &channel_ids); - void reload_created_public_dialogs(PublicDialogType type, Promise> &&promise); - void finish_get_created_public_dialogs(PublicDialogType type, Result &&result); void update_created_public_channels(Channel *c, ChannelId channel_id); diff --git a/td/telegram/NotificationSettingsManager.cpp b/td/telegram/NotificationSettingsManager.cpp index 2db6030b1..17c693bb7 100644 --- a/td/telegram/NotificationSettingsManager.cpp +++ b/td/telegram/NotificationSettingsManager.cpp @@ -1472,10 +1472,6 @@ void NotificationSettingsManager::after_get_difference() { if (!channels_notification_settings_.is_synchronized) { send_get_scope_notification_settings_query(NotificationSettingsScope::Channel, Promise<>()); } - - if (td_->is_online() && !are_saved_ringtones_reloaded_) { - reload_saved_ringtones(Auto()); - } } void NotificationSettingsManager::on_binlog_events(vector &&events) { diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 5e8bf36a0..406c1fdc1 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1462,6 +1462,10 @@ void StickersManager::reload_special_sticker_set_by_type(SpecialStickerSetType t if (G()->close_flag()) { return; } + if (disable_animated_emojis_ && + (type == SpecialStickerSetType::animated_emoji() || type == SpecialStickerSetType::animated_emoji_click())) { + return; + } auto &sticker_set = add_special_sticker_set(type); if (sticker_set.is_being_reloaded_) { @@ -7627,26 +7631,6 @@ td_api::object_ptr StickersManager::get_emoji_suggestions_url_r return result; } -void StickersManager::after_get_difference() { - if (td_->auth_manager_->is_bot()) { - return; - } - reload_reactions(); - if (td_->is_online()) { - get_installed_sticker_sets(false, Auto()); - get_installed_sticker_sets(true, Auto()); - get_featured_sticker_sets(0, 1000, Auto()); - get_recent_stickers(false, Auto()); - get_recent_stickers(true, Auto()); - get_favorite_stickers(Auto()); - - if (!disable_animated_emojis_) { - reload_special_sticker_set_by_type(SpecialStickerSetType::animated_emoji()); - reload_special_sticker_set_by_type(SpecialStickerSetType::animated_emoji_click()); - } - } -} - void StickersManager::get_current_state(vector> &updates) const { if (td_->auth_manager_->is_bot()) { return; diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index cc73761c2..38b147c0b 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -133,6 +133,10 @@ class StickersManager final : public Actor { void view_featured_sticker_sets(const vector &sticker_set_ids); + void reload_reactions(); + + void reload_special_sticker_set_by_type(SpecialStickerSetType type, bool is_recursive = false); + void on_get_available_reactions(tl_object_ptr &&available_reactions_ptr); void on_get_installed_sticker_sets(bool is_masks, tl_object_ptr &&stickers_ptr); @@ -319,8 +323,6 @@ class StickersManager final : public Actor { void send_get_attached_stickers_query(FileId file_id, Promise &&promise); - void after_get_difference(); - void get_current_state(vector> &updates) const; template @@ -702,8 +704,6 @@ class StickersManager final : public Actor { void load_reactions(); - void reload_reactions(); - void update_active_reactions(); td_api::object_ptr get_update_reactions_object() const; @@ -719,8 +719,6 @@ class StickersManager final : public Actor { void load_special_sticker_set(SpecialStickerSet &sticker_set); - void reload_special_sticker_set_by_type(SpecialStickerSetType type, bool is_recursive = false); - void reload_special_sticker_set(SpecialStickerSet &sticker_set, int32 hash); static void add_sticker_thumbnail(Sticker *s, PhotoSize thumbnail); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index ed1bde9db..64f0a83f3 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -38,10 +38,12 @@ #include "td/telegram/PollId.h" #include "td/telegram/PollManager.h" #include "td/telegram/PrivacyManager.h" +#include "td/telegram/PublicDialogType.h" #include "td/telegram/ScheduledServerMessageId.h" #include "td/telegram/SecretChatId.h" #include "td/telegram/SecretChatsManager.h" #include "td/telegram/ServerMessageId.h" +#include "td/telegram/SpecialStickerSetType.h" #include "td/telegram/StateManager.h" #include "td/telegram/StickerSetId.h" #include "td/telegram/StickersManager.h" @@ -1557,15 +1559,34 @@ void UpdatesManager::after_get_difference() { << postponed_pts_updates_.size() << " pending pts updates"; } - td_->animations_manager_->after_get_difference(); - td_->contacts_manager_->after_get_difference(); td_->download_manager_->after_get_difference(); td_->inline_queries_manager_->after_get_difference(); td_->messages_manager_->after_get_difference(); td_->notification_settings_manager_->after_get_difference(); - td_->stickers_manager_->after_get_difference(); send_closure_later(td_->notification_manager_actor_, &NotificationManager::after_get_difference); send_closure(G()->state_manager(), &StateManager::on_synchronized, true); + + try_reload_data(); +} + +void UpdatesManager::try_reload_data() { + if (td_->auth_manager_->is_bot() || running_get_difference_ || !td_->is_online()) { + return; + } + + td_->animations_manager_->get_saved_animations(Auto()); + td_->contacts_manager_->reload_created_public_dialogs(PublicDialogType::HasUsername, Auto()); + td_->contacts_manager_->reload_created_public_dialogs(PublicDialogType::IsLocationBased, Auto()); + td_->notification_settings_manager_->reload_saved_ringtones(Auto()); + td_->stickers_manager_->reload_reactions(); + td_->stickers_manager_->get_installed_sticker_sets(false, Auto()); + td_->stickers_manager_->get_installed_sticker_sets(true, Auto()); + td_->stickers_manager_->get_featured_sticker_sets(0, 1000, Auto()); + td_->stickers_manager_->get_recent_stickers(false, Auto()); + td_->stickers_manager_->get_recent_stickers(true, Auto()); + td_->stickers_manager_->get_favorite_stickers(Auto()); + td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::animated_emoji()); + td_->stickers_manager_->reload_special_sticker_set_by_type(SpecialStickerSetType::animated_emoji_click()); } void UpdatesManager::on_pending_updates(vector> &&updates, int32 seq_begin, diff --git a/td/telegram/UpdatesManager.h b/td/telegram/UpdatesManager.h index 172e73fe6..f7355ec86 100644 --- a/td/telegram/UpdatesManager.h +++ b/td/telegram/UpdatesManager.h @@ -331,6 +331,8 @@ class UpdatesManager final : public Actor { void after_get_difference(); + void try_reload_data(); + static bool have_update_pts_changed(const vector> &updates); static bool check_pts_update_dialog_id(DialogId dialog_id);