From 04c4e932fe537d72416706b61cbdc37a05da73f1 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 23 Jun 2023 13:40:59 +0300 Subject: [PATCH] Reload stories from viewed messages once in 5 minutes. --- td/telegram/MessagesManager.cpp | 5 +++++ td/telegram/StoryManager.cpp | 11 +++++++++++ td/telegram/StoryManager.h | 3 +++ 3 files changed, 19 insertions(+) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 847456ee4..18e7ad4a1 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -20102,6 +20102,11 @@ Status MessagesManager::view_messages(DialogId dialog_id, vector mess } } + auto story_full_id = get_message_content_story_full_id(td_, m->content.get()); + if (story_full_id.is_valid()) { + td_->story_manager_->view_story_message(story_full_id); + } + if (m->message_id.is_server() && d->open_count > 0) { auto &info = dialog_viewed_messages_[dialog_id]; if (info == nullptr) { diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 0532608e3..5c3b4178c 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -1078,6 +1078,17 @@ void StoryManager::close_story(DialogId owner_dialog_id, StoryId story_id, Promi promise.set_value(Unit()); } +void StoryManager::view_story_message(StoryFullId story_full_id) { + const Story *story = get_story(story_full_id); + if (story == nullptr || !story_full_id.get_story_id().is_server()) { + return; + } + + if (story->receive_date_ < G()->unix_time() - VIEWED_STORY_POLL_PERIOD) { + reload_story(story_full_id, Promise()); + } +} + void StoryManager::schedule_interaction_info_update() { if (interaction_info_update_timeout_.has_timeout()) { return; diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index c8dcb2814..cf800767e 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -131,6 +131,8 @@ class StoryManager final : public Actor { void close_story(DialogId owner_dialog_id, StoryId story_id, Promise &&promise); + void view_story_message(StoryFullId story_full_id); + void get_story_viewers(StoryId story_id, const td_api::messageViewer *offset, int32 limit, Promise> &&promise); @@ -190,6 +192,7 @@ class StoryManager final : public Actor { class ReadStoriesOnServerLogEvent; static constexpr int32 OPENED_STORY_POLL_PERIOD = 60; + static constexpr int32 VIEWED_STORY_POLL_PERIOD = 300; void start_up() final;