diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index c323974f6..c1b29f7f1 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -3217,7 +3217,12 @@ void StoryManager::unregister_story(StoryFullId story_full_id, MessageFullId mes StoryManager::StoryInfo StoryManager::get_story_info(StoryFullId story_full_id) const { const auto *story = get_story(story_full_id); auto story_id = story_full_id.get_story_id(); - if (story == nullptr || (story_id.is_server() && !is_active_story(story))) { + if (story == nullptr) { + LOG(INFO) << "Tried to get info about deleted " << story_full_id; + return {}; + } + if (story_id.is_server() && !is_active_story(story)) { + LOG(INFO) << "Tried to get info about expired " << story_full_id; return {}; } StoryInfo story_info; @@ -3346,6 +3351,9 @@ td_api::object_ptr StoryManager::get_chat_active_stor stories.push_back(std::move(story_info)); } } + if (stories.size() != active_stories->story_ids_.size()) { + send_closure_later(G()->story_manager(), &StoryManager::update_active_stories, owner_dialog_id); + } if (story_list_id.is_valid()) { order = active_stories->public_order_; } @@ -4008,6 +4016,15 @@ void StoryManager::on_update_dialog_stories_hidden(DialogId owner_dialog_id, boo } } +void StoryManager::update_active_stories(DialogId owner_dialog_id) { + auto active_stories = get_active_stories(owner_dialog_id); + if (active_stories != nullptr) { + auto story_ids = active_stories->story_ids_; + on_update_active_stories(owner_dialog_id, active_stories->max_read_story_id_, std::move(story_ids), Promise(), + "update_active_stories"); + } +} + void StoryManager::on_update_active_stories(DialogId owner_dialog_id, StoryId max_read_story_id, vector &&story_ids, Promise &&promise, const char *source, bool from_database) { @@ -4235,6 +4252,9 @@ void StoryManager::save_active_stories(DialogId owner_dialog_id, const ActiveSto saved_active_stories.story_infos_.push_back(std::move(story_info)); } } + if (saved_active_stories.story_infos_.size() != active_stories->story_ids_.size()) { + send_closure_later(G()->story_manager(), &StoryManager::update_active_stories, owner_dialog_id); + } if (saved_active_stories.story_infos_.empty()) { LOG(INFO) << "Have no active stories to save"; G()->td_db()->get_story_db_async()->delete_active_stories(owner_dialog_id, std::move(promise)); diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index b5927762a..b1915f6f2 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -555,6 +555,8 @@ class StoryManager final : public Actor { void on_update_dialog_has_pinned_stories(DialogId owner_dialog_id, bool has_pinned_stories); + void update_active_stories(DialogId owner_dialog_id); + void on_update_active_stories(DialogId owner_dialog_id, StoryId max_read_story_id, vector &&story_ids, Promise &&promise, const char *source, bool from_database = false);