Update recent story viewers from the full list.

This commit is contained in:
levlam 2023-06-20 16:12:12 +03:00
parent 4e2e6f6e61
commit 11ae003562
5 changed files with 18 additions and 0 deletions

View File

@ -87,6 +87,10 @@ void MessageViewers::add_sublist(const MessageViewer &offset, const MessageViewe
} }
} }
vector<UserId> MessageViewers::get_user_ids() const {
return transform(message_viewers_, [](auto &viewer) { return viewer.get_user_id(); });
}
td_api::object_ptr<td_api::messageViewers> MessageViewers::get_message_viewers_object( td_api::object_ptr<td_api::messageViewers> MessageViewers::get_message_viewers_object(
ContactsManager *contacts_manager) const { ContactsManager *contacts_manager) const {
return td_api::make_object<td_api::messageViewers>( return td_api::make_object<td_api::messageViewers>(

View File

@ -65,6 +65,8 @@ struct MessageViewers {
void add_sublist(const MessageViewer &offset, const MessageViewers &sublist); void add_sublist(const MessageViewer &offset, const MessageViewers &sublist);
vector<UserId> get_user_ids() const;
td_api::object_ptr<td_api::messageViewers> get_message_viewers_object(ContactsManager *contacts_manager) const; td_api::object_ptr<td_api::messageViewers> get_message_viewers_object(ContactsManager *contacts_manager) const;
}; };

View File

@ -36,6 +36,13 @@ StoryInteractionInfo::StoryInteractionInfo(Td *td, telegram_api::object_ptr<tele
} }
} }
void StoryInteractionInfo::set_recent_viewer_user_ids(vector<UserId> &&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<td_api::storyInteractionInfo> StoryInteractionInfo::get_story_interaction_info_object(Td *td) const { td_api::object_ptr<td_api::storyInteractionInfo> StoryInteractionInfo::get_story_interaction_info_object(Td *td) const {
if (is_empty()) { if (is_empty()) {
return nullptr; return nullptr;

View File

@ -48,6 +48,8 @@ class StoryInteractionInfo {
return view_count_; return view_count_;
} }
void set_recent_viewer_user_ids(vector<UserId> &&user_ids);
td_api::object_ptr<td_api::storyInteractionInfo> get_story_interaction_info_object(Td *td) const; td_api::object_ptr<td_api::storyInteractionInfo> get_story_interaction_info_object(Td *td) const;
}; };

View File

@ -1161,6 +1161,9 @@ void StoryManager::on_get_story_viewers(
MessageViewers story_viewers(std::move(view_list->views_)); MessageViewers story_viewers(std::move(view_list->views_));
if (story->content_ != nullptr) { if (story->content_ != nullptr) {
if (story->interaction_info_.set_view_count(view_list->count_)) { 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); on_story_changed(story_full_id, story, true, true);
} }
auto &cached_viewers = cached_story_viewers_[story_full_id]; auto &cached_viewers = cached_story_viewers_[story_full_id];