diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 237bf521e..70bbb4de3 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -610,9 +610,9 @@ StoryManager::StoryManager(Td *td, ActorShared<> parent) : td_(td), parent_(std: } StoryManager::~StoryManager() { - Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), story_full_id_to_file_source_id_, stories_, - inaccessible_story_full_ids_, deleted_story_full_ids_, story_messages_, - active_stories_, max_read_story_ids_); + Scheduler::instance()->destroy_on_scheduler( + G()->get_gc_scheduler_id(), story_full_id_to_file_source_id_, stories_, stories_by_global_id_, + inaccessible_story_full_ids_, deleted_story_full_ids_, story_messages_, active_stories_, max_read_story_ids_); } void StoryManager::start_up() { @@ -1290,6 +1290,7 @@ StoryId StoryManager::on_get_story(DialogId owner_dialog_id, stories_.set(story_full_id, std::move(s)); is_changed = true; story_item->min_ = false; + register_story_global_id(story_full_id, story); inaccessible_story_full_ids_.erase(story_full_id); send_closure_later(G()->messages_manager(), @@ -1399,6 +1400,7 @@ StoryId StoryManager::on_get_skipped_story(DialogId owner_dialog_id, auto s = make_unique(); story = s.get(); stories_.set(story_full_id, std::move(s)); + register_story_global_id(story_full_id, story); inaccessible_story_full_ids_.erase(story_full_id); } @@ -1437,6 +1439,7 @@ void StoryManager::on_delete_story(DialogId owner_dialog_id, StoryId story_id) { story_id.get())); } delete_story_files(story); + unregister_story_global_id(story); stories_.erase(story_full_id); auto active_stories = get_active_stories(owner_dialog_id); @@ -1477,6 +1480,17 @@ void StoryManager::on_story_changed(StoryFullId story_full_id, const Story *stor } } +void StoryManager::register_story_global_id(StoryFullId story_full_id, Story *story) { + CHECK(story->global_id_ == 0); + story->global_id_ = ++max_story_global_id_; + stories_by_global_id_[story->global_id_] = story_full_id; +} + +void StoryManager::unregister_story_global_id(const Story *story) { + CHECK(story->global_id_ > 0); + stories_by_global_id_.erase(story->global_id_); +} + std::pair> StoryManager::on_get_stories( DialogId owner_dialog_id, vector &&expected_story_ids, telegram_api::object_ptr &&stories) { diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 9d69c35d8..cfe4d0ab0 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -48,6 +48,7 @@ class StoryManager final : public Actor { unique_ptr content_; FormattedText caption_; mutable int64 edit_generation_ = 0; + int64 global_id_ = 0; }; struct BeingEditedStory { @@ -193,6 +194,10 @@ class StoryManager final : public Actor { void on_story_changed(StoryFullId story_full_id, const Story *story, bool is_changed, bool need_save_to_database); + void register_story_global_id(StoryFullId story_full_id, Story *story); + + void unregister_story_global_id(const Story *story); + td_api::object_ptr get_story_info_object(StoryFullId story_full_id) const; td_api::object_ptr get_story_info_object(StoryFullId story_full_id, const Story *story) const; @@ -278,6 +283,8 @@ class StoryManager final : public Actor { WaitFreeHashMap, StoryFullIdHash> stories_; + WaitFreeHashMap stories_by_global_id_; + WaitFreeHashSet inaccessible_story_full_ids_; WaitFreeHashSet deleted_story_full_ids_; @@ -296,6 +303,8 @@ class StoryManager final : public Actor { uint32 send_story_count_ = 0; + int64 max_story_global_id_ = 0; + bool has_active_synchronize_archive_all_stories_query_ = false; FlatHashMap, FileIdHash> being_uploaded_files_;