From 7b9abf3eca8439d74a181536683c9343990a15bb Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 27 Sep 2023 15:31:34 +0300 Subject: [PATCH] Explicitly restart timeout. --- td/telegram/StoryManager.cpp | 24 ++++++++++++++++-------- td/telegram/StoryManager.h | 4 ++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 66250e302..c323974f6 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -1580,7 +1580,7 @@ void StoryManager::on_story_expire_timeout(int64 story_global_id) { // timeout used monotonic time instead of wall clock time LOG(INFO) << "Receive timeout for non-expired " << story_full_id << ": expire_date = " << story->expire_date_ << ", current time = " << G()->unix_time(); - return on_story_changed(story_full_id, story, false, false); + return set_story_expire_timeout(story); } LOG(INFO) << "Have expired " << story_full_id; @@ -1626,7 +1626,7 @@ void StoryManager::on_story_can_get_viewers_timeout(int64 story_global_id) { LOG(INFO) << "Receive timeout for " << story_full_id << " with available viewers: expire_date = " << story->expire_date_ << ", current time = " << G()->unix_time(); - return on_story_changed(story_full_id, story, false, false); + return set_story_can_get_viewers_timeout(story); } // can_get_viewers flag could have been changed; reload the story to repair it @@ -3762,19 +3762,27 @@ void StoryManager::delete_story_from_database(StoryFullId story_full_id) { } } +void StoryManager::set_story_expire_timeout(const Story *story) { + CHECK(story->global_id_ > 0); + story_expire_timeout_.set_timeout_in(story->global_id_, story->expire_date_ - G()->unix_time()); +} + +void StoryManager::set_story_can_get_viewers_timeout(const Story *story) { + CHECK(story->global_id_ > 0); + story_can_get_viewers_timeout_.set_timeout_in(story->global_id_, + get_story_viewers_expire_date(story) - G()->unix_time() + 2); +} + void StoryManager::on_story_changed(StoryFullId story_full_id, const Story *story, bool is_changed, bool need_save_to_database, bool from_database) { if (!story_full_id.get_story_id().is_server()) { return; } if (is_active_story(story)) { - CHECK(story->global_id_ > 0); - story_expire_timeout_.set_timeout_in(story->global_id_, story->expire_date_ - G()->unix_time()); + set_story_expire_timeout(story); } - if (can_get_story_viewers(story_full_id, story, true).is_ok() && story->interaction_info_.get_reaction_count() == 0) { - CHECK(story->global_id_ > 0); - story_can_get_viewers_timeout_.set_timeout_in(story->global_id_, - get_story_viewers_expire_date(story) - G()->unix_time() + 2); + if (can_get_story_viewers(story_full_id, story, true).is_ok()) { + set_story_can_get_viewers_timeout(story); } if (story->content_ == nullptr) { return; diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 21e72e6c8..b5927762a 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -435,6 +435,10 @@ class StoryManager final : public Actor { ActiveStories *on_get_active_stories_from_database(StoryListId story_list_id, DialogId owner_dialog_id, const BufferSlice &value, const char *source); + void set_story_expire_timeout(const Story *story); + + void set_story_can_get_viewers_timeout(const Story *story); + void on_story_changed(StoryFullId story_full_id, const Story *story, bool is_changed, bool need_save_to_database, bool from_database = false);