Use send_closure_later to avoid cycles between ContactsManager and StoryManager.
This commit is contained in:
parent
c4f3dd013d
commit
32f6026278
@ -178,7 +178,8 @@ class AddContactQuery final : public Td::ResultHandler {
|
||||
}
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::contacts_addContact(flags, false /*ignored*/, std::move(input_user), contact.get_first_name(),
|
||||
contact.get_last_name(), contact.get_phone_number())));
|
||||
contact.get_last_name(), contact.get_phone_number()),
|
||||
{{DialogId(user_id)}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -10479,7 +10480,7 @@ void ContactsManager::on_get_user(tl_object_ptr<telegram_api::User> &&user_ptr,
|
||||
|
||||
if (is_me_regular_user && (stories_available || stories_unavailable)) {
|
||||
// update at the end, because it calls need_poll_active_stories
|
||||
on_update_user_story_ids(u, user_id, StoryId(user->stories_max_id_), StoryId());
|
||||
on_update_user_story_ids_impl(u, user_id, StoryId(user->stories_max_id_), StoryId());
|
||||
}
|
||||
|
||||
if (u->cache_version != User::CACHE_VERSION && u->is_received) {
|
||||
@ -11953,7 +11954,8 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
|
||||
}
|
||||
if (u->is_is_contact_changed) {
|
||||
td_->messages_manager_->on_dialog_user_is_contact_updated(DialogId(user_id), u->is_contact);
|
||||
td_->story_manager_->on_dialog_active_stories_order_updated(DialogId(user_id), "is_contact");
|
||||
send_closure_later(td_->story_manager_actor_, &StoryManager::on_dialog_active_stories_order_updated,
|
||||
DialogId(user_id), "is_contact");
|
||||
if (is_user_contact(u, user_id, false)) {
|
||||
auto user_full = get_user_full(user_id);
|
||||
if (user_full != nullptr && user_full->need_phone_number_privacy_exception) {
|
||||
@ -11975,7 +11977,8 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
|
||||
u->is_is_deleted_changed = false;
|
||||
}
|
||||
if (u->is_is_premium_changed) {
|
||||
td_->story_manager_->on_dialog_active_stories_order_updated(DialogId(user_id), "is_premium");
|
||||
send_closure_later(td_->story_manager_actor_, &StoryManager::on_dialog_active_stories_order_updated,
|
||||
DialogId(user_id), "is_premium");
|
||||
u->is_is_premium_changed = false;
|
||||
}
|
||||
if (u->is_name_changed) {
|
||||
@ -12012,7 +12015,8 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo
|
||||
}
|
||||
}
|
||||
if (u->is_stories_hidden_changed) {
|
||||
td_->story_manager_->on_dialog_active_stories_order_updated(DialogId(user_id), "stories_hidden");
|
||||
send_closure_later(td_->story_manager_actor_, &StoryManager::on_dialog_active_stories_order_updated,
|
||||
DialogId(user_id), "stories_hidden");
|
||||
u->is_stories_hidden_changed = false;
|
||||
}
|
||||
if (!td_->auth_manager_->is_bot()) {
|
||||
@ -12606,7 +12610,8 @@ void ContactsManager::on_get_user_full(tl_object_ptr<telegram_api::userFull> &&u
|
||||
|
||||
td_->messages_manager_->on_update_dialog_is_translatable(DialogId(user_id), !user->translations_disabled_);
|
||||
|
||||
td_->story_manager_->on_get_user_stories(DialogId(user_id), std::move(user->stories_), Promise<Unit>());
|
||||
send_closure_later(td_->story_manager_actor_, &StoryManager::on_get_user_stories, DialogId(user_id),
|
||||
std::move(user->stories_), Promise<Unit>());
|
||||
|
||||
UserFull *user_full = add_user_full(user_id);
|
||||
user_full->expires_at = Time::now() + USER_FULL_EXPIRE_TIME;
|
||||
@ -13557,15 +13562,15 @@ void ContactsManager::on_update_user_story_ids(UserId user_id, StoryId max_activ
|
||||
|
||||
User *u = get_user_force(user_id, "on_update_user_story_ids");
|
||||
if (u != nullptr) {
|
||||
on_update_user_story_ids(u, user_id, max_active_story_id, max_read_story_id);
|
||||
on_update_user_story_ids_impl(u, user_id, max_active_story_id, max_read_story_id);
|
||||
update_user(u, user_id);
|
||||
} else {
|
||||
LOG(INFO) << "Ignore update user has stories about unknown " << user_id;
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_user_story_ids(User *u, UserId user_id, StoryId max_active_story_id,
|
||||
StoryId max_read_story_id) {
|
||||
void ContactsManager::on_update_user_story_ids_impl(User *u, UserId user_id, StoryId max_active_story_id,
|
||||
StoryId max_read_story_id) {
|
||||
if (td_->auth_manager_->is_bot()) {
|
||||
return;
|
||||
}
|
||||
|
@ -1410,7 +1410,7 @@ class ContactsManager final : public Actor {
|
||||
void on_update_user_photo(User *u, UserId user_id, tl_object_ptr<telegram_api::UserProfilePhoto> &&photo,
|
||||
const char *source);
|
||||
void on_update_user_emoji_status(User *u, UserId user_id, EmojiStatus emoji_status);
|
||||
void on_update_user_story_ids(User *u, UserId user_id, StoryId max_active_story_id, StoryId max_read_story_id);
|
||||
void on_update_user_story_ids_impl(User *u, UserId user_id, StoryId max_active_story_id, StoryId max_read_story_id);
|
||||
void on_update_user_max_read_story_id(User *u, UserId user_id, StoryId max_read_story_id);
|
||||
void on_update_user_stories_hidden(User *u, UserId user_id, bool stories_hidden);
|
||||
void on_update_user_is_contact(User *u, UserId user_id, bool is_contact, bool is_mutual_contact,
|
||||
|
@ -445,7 +445,8 @@ class GetUserStoriesQuery final : public Td::ResultHandler {
|
||||
if (r_input_user.is_error()) {
|
||||
return on_error(r_input_user.move_as_error());
|
||||
}
|
||||
send_query(G()->net_query_creator().create(telegram_api::stories_getUserStories(r_input_user.move_as_ok())));
|
||||
send_query(G()->net_query_creator().create(telegram_api::stories_getUserStories(r_input_user.move_as_ok()),
|
||||
{{DialogId(user_id)}}));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
@ -1925,6 +1926,7 @@ void StoryManager::get_dialog_expiring_stories(DialogId owner_dialog_id,
|
||||
return promise.set_value(get_chat_active_stories_object(owner_dialog_id, nullptr));
|
||||
}
|
||||
|
||||
LOG(INFO) << "Get active stories in " << owner_dialog_id;
|
||||
auto active_stories = get_active_stories_force(owner_dialog_id, "get_dialog_expiring_stories");
|
||||
if (active_stories != nullptr) {
|
||||
if (!promise) {
|
||||
@ -1946,6 +1948,11 @@ void StoryManager::get_dialog_expiring_stories(DialogId owner_dialog_id,
|
||||
td_->create_handler<GetUserStoriesQuery>(std::move(query_promise))->send(owner_dialog_id.get_user_id());
|
||||
}
|
||||
|
||||
void StoryManager::reload_dialog_expiring_stories(DialogId dialog_id) {
|
||||
td_->messages_manager_->force_create_dialog(dialog_id, "reload_dialog_expiring_stories", true);
|
||||
load_dialog_expiring_stories(dialog_id, 0, "reload_dialog_expiring_stories");
|
||||
}
|
||||
|
||||
class StoryManager::LoadDialogExpiringStoriesLogEvent {
|
||||
public:
|
||||
DialogId dialog_id_;
|
||||
@ -3145,7 +3152,9 @@ void StoryManager::on_update_active_stories(DialogId owner_dialog_id, StoryId ma
|
||||
|
||||
if (story_ids.empty()) {
|
||||
if (owner_dialog_id.get_type() == DialogType::User) {
|
||||
td_->contacts_manager_->on_update_user_story_ids(owner_dialog_id.get_user_id(), StoryId(), StoryId());
|
||||
// use send_closure_later because story order can be updated from update_user
|
||||
send_closure_later(td_->contacts_manager_actor_, &ContactsManager::on_update_user_story_ids,
|
||||
owner_dialog_id.get_user_id(), StoryId(), StoryId());
|
||||
}
|
||||
auto *active_stories = get_active_stories(owner_dialog_id);
|
||||
if (active_stories != nullptr) {
|
||||
@ -3187,8 +3196,9 @@ void StoryManager::on_update_active_stories(DialogId owner_dialog_id, StoryId ma
|
||||
}
|
||||
}
|
||||
if (owner_dialog_id.get_type() == DialogType::User) {
|
||||
td_->contacts_manager_->on_update_user_story_ids(owner_dialog_id.get_user_id(), story_ids.back(),
|
||||
max_read_story_id);
|
||||
// use send_closure_later because story order can be updated from update_user
|
||||
send_closure_later(td_->contacts_manager_actor_, &ContactsManager::on_update_user_story_ids,
|
||||
owner_dialog_id.get_user_id(), story_ids.back(), max_read_story_id);
|
||||
}
|
||||
bool need_save_to_database = false;
|
||||
if (active_stories->max_read_story_id_ != max_read_story_id || active_stories->story_ids_ != story_ids) {
|
||||
|
@ -233,6 +233,8 @@ class StoryManager final : public Actor {
|
||||
void get_dialog_expiring_stories(DialogId owner_dialog_id,
|
||||
Promise<td_api::object_ptr<td_api::chatActiveStories>> &&promise);
|
||||
|
||||
void reload_dialog_expiring_stories(DialogId dialog_id);
|
||||
|
||||
void open_story(DialogId owner_dialog_id, StoryId story_id, Promise<Unit> &&promise);
|
||||
|
||||
void close_story(DialogId owner_dialog_id, StoryId story_id, Promise<Unit> &&promise);
|
||||
|
Loading…
Reference in New Issue
Block a user