diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 4ce9962fd..f2c416892 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -34987,6 +34987,16 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq on_dialog_updated(dialog_id, "update_has_contact_registered_message"); } + if (m->sender_user_id.is_valid()) { + auto story_full_id = get_message_content_story_full_id(td_, m->content.get()); + if (story_full_id.is_valid()) { + td_->story_manager_->on_story_replied(story_full_id, m->sender_user_id); + } + if (m->reply_to_story_full_id.is_valid()) { + td_->story_manager_->on_story_replied(m->reply_to_story_full_id, m->sender_user_id); + } + } + reget_message_from_server_if_needed(dialog_id, m); add_message_file_sources(dialog_id, m); diff --git a/td/telegram/StoryInteractionInfo.cpp b/td/telegram/StoryInteractionInfo.cpp index 9db1e4049..1e58d6f4f 100644 --- a/td/telegram/StoryInteractionInfo.cpp +++ b/td/telegram/StoryInteractionInfo.cpp @@ -9,6 +9,7 @@ #include "td/telegram/ContactsManager.h" #include "td/telegram/Td.h" +#include "td/utils/algorithm.h" #include "td/utils/logging.h" namespace td { @@ -43,6 +44,10 @@ void StoryInteractionInfo::set_recent_viewer_user_ids(vector &&user_ids) recent_viewer_user_ids_ = std::move(user_ids); } +bool StoryInteractionInfo::definitely_has_no_user(UserId user_id) const { + return !is_empty() && view_count_ <= MAX_RECENT_VIEWERS && !contains(recent_viewer_user_ids_, user_id); +} + td_api::object_ptr StoryInteractionInfo::get_story_interaction_info_object(Td *td) const { if (is_empty()) { return nullptr; diff --git a/td/telegram/StoryInteractionInfo.h b/td/telegram/StoryInteractionInfo.h index a7582ba3b..66504411d 100644 --- a/td/telegram/StoryInteractionInfo.h +++ b/td/telegram/StoryInteractionInfo.h @@ -48,6 +48,8 @@ class StoryInteractionInfo { return view_count_; } + bool definitely_has_no_user(UserId user_id) const; + void set_recent_viewer_user_ids(vector &&user_ids); td_api::object_ptr get_story_interaction_info_object(Td *td) const; diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index e2dea3944..3d9b8d0ac 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -1322,6 +1322,21 @@ void StoryManager::view_story_message(StoryFullId story_full_id) { } } +void StoryManager::on_story_replied(StoryFullId story_full_id, UserId replier_user_id) { + if (!replier_user_id.is_valid() || replier_user_id == td_->contacts_manager_->get_my_id()) { + return; + } + const Story *story = get_story(story_full_id); + if (story == nullptr || !story_full_id.get_story_id().is_server() || !is_story_owned(story_full_id.get_dialog_id())) { + return; + } + + if (story->content_ != nullptr && is_active_story(story) && + story->interaction_info_.definitely_has_no_user(replier_user_id)) { + 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 dba58842f..89e4a8d24 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -155,6 +155,8 @@ class StoryManager final : public Actor { void view_story_message(StoryFullId story_full_id); + void on_story_replied(StoryFullId story_full_id, UserId replier_user_id); + void get_story_viewers(StoryId story_id, const td_api::messageViewer *offset, int32 limit, Promise> &&promise);