From 11ae0035628c5903de2807e88289343f4918237e Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 20 Jun 2023 16:12:12 +0300 Subject: [PATCH] Update recent story viewers from the full list. --- td/telegram/MessageViewer.cpp | 4 ++++ td/telegram/MessageViewer.h | 2 ++ td/telegram/StoryInteractionInfo.cpp | 7 +++++++ td/telegram/StoryInteractionInfo.h | 2 ++ td/telegram/StoryManager.cpp | 3 +++ 5 files changed, 18 insertions(+) diff --git a/td/telegram/MessageViewer.cpp b/td/telegram/MessageViewer.cpp index 3d0e877c7..3628a813d 100644 --- a/td/telegram/MessageViewer.cpp +++ b/td/telegram/MessageViewer.cpp @@ -87,6 +87,10 @@ void MessageViewers::add_sublist(const MessageViewer &offset, const MessageViewe } } +vector MessageViewers::get_user_ids() const { + return transform(message_viewers_, [](auto &viewer) { return viewer.get_user_id(); }); +} + td_api::object_ptr MessageViewers::get_message_viewers_object( ContactsManager *contacts_manager) const { return td_api::make_object( diff --git a/td/telegram/MessageViewer.h b/td/telegram/MessageViewer.h index a6046cd05..4df57c341 100644 --- a/td/telegram/MessageViewer.h +++ b/td/telegram/MessageViewer.h @@ -65,6 +65,8 @@ struct MessageViewers { void add_sublist(const MessageViewer &offset, const MessageViewers &sublist); + vector get_user_ids() const; + td_api::object_ptr get_message_viewers_object(ContactsManager *contacts_manager) const; }; diff --git a/td/telegram/StoryInteractionInfo.cpp b/td/telegram/StoryInteractionInfo.cpp index 7cc143295..9db1e4049 100644 --- a/td/telegram/StoryInteractionInfo.cpp +++ b/td/telegram/StoryInteractionInfo.cpp @@ -36,6 +36,13 @@ StoryInteractionInfo::StoryInteractionInfo(Td *td, telegram_api::object_ptr &&user_ids) { + if (user_ids.size() > MAX_RECENT_VIEWERS) { + user_ids.resize(MAX_RECENT_VIEWERS); + } + recent_viewer_user_ids_ = std::move(user_ids); +} + 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 e7a73b7d9..a7582ba3b 100644 --- a/td/telegram/StoryInteractionInfo.h +++ b/td/telegram/StoryInteractionInfo.h @@ -48,6 +48,8 @@ class StoryInteractionInfo { return view_count_; } + 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 21d6fa4c6..57729f17c 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -1161,6 +1161,9 @@ void StoryManager::on_get_story_viewers( MessageViewers story_viewers(std::move(view_list->views_)); if (story->content_ != nullptr) { if (story->interaction_info_.set_view_count(view_list->count_)) { + if (offset.is_empty()) { + story->interaction_info_.set_recent_viewer_user_ids(story_viewers.get_user_ids()); + } on_story_changed(story_full_id, story, true, true); } auto &cached_viewers = cached_story_viewers_[story_full_id];