diff --git a/td/telegram/StoryInteractionInfo.cpp b/td/telegram/StoryInteractionInfo.cpp index d32ab3e0d..7bca7de2e 100644 --- a/td/telegram/StoryInteractionInfo.cpp +++ b/td/telegram/StoryInteractionInfo.cpp @@ -113,6 +113,9 @@ bool StoryInteractionInfo::set_recent_viewer_user_ids(vector &&user_ids) if (user_ids.size() > MAX_RECENT_VIEWERS) { user_ids.resize(MAX_RECENT_VIEWERS); } + if (recent_viewer_user_ids_.size() < user_ids.size() && user_ids.size() <= static_cast(view_count_)) { + return false; + } if (recent_viewer_user_ids_ != user_ids) { recent_viewer_user_ids_ = std::move(user_ids); return true; diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 25e9863cf..767fb0dca 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -2860,7 +2860,7 @@ void StoryManager::on_get_story_interactions( if (is_full && story->interaction_info_.set_counts(total_count, total_reaction_count)) { is_changed = true; } - if (is_first && story->interaction_info_.set_recent_viewer_user_ids(story_viewers.get_user_ids())) { + if (is_first && story->interaction_info_.set_recent_viewer_user_ids(story_viewers.get_viewer_user_ids())) { is_changed = true; } if (is_changed) { @@ -2868,8 +2868,7 @@ void StoryManager::on_get_story_interactions( } } - td_->contacts_manager_->on_view_dialog_active_stories( - transform(story_viewers.get_user_ids(), [](UserId user_id) { return DialogId(user_id); })); + td_->contacts_manager_->on_view_dialog_active_stories(story_viewers.get_actor_dialog_ids()); promise.set_value(story_viewers.get_story_interactions_object(td_->contacts_manager_.get())); } diff --git a/td/telegram/StoryViewer.cpp b/td/telegram/StoryViewer.cpp index c49296d8a..9f8629968 100644 --- a/td/telegram/StoryViewer.cpp +++ b/td/telegram/StoryViewer.cpp @@ -42,16 +42,27 @@ StoryViewers::StoryViewers(Td *td, int32 total_count, int32 total_forward_count, td->contacts_manager_->on_update_user_is_blocked(UserId(story_view->user_id_), story_view->blocked_, story_view->blocked_my_stories_from_); story_viewers_.emplace_back(std::move(story_view)); - auto user_id = story_viewers_.back().get_user_id(); - if (!user_id.is_valid()) { - LOG(ERROR) << "Receive invalid " << user_id << " as a viewer of a story"; + auto actor_dialog_id = story_viewers_.back().get_actor_dialog_id(); + if (!actor_dialog_id.is_valid()) { + LOG(ERROR) << "Receive invalid " << actor_dialog_id << " in story interaction"; story_viewers_.pop_back(); } } } -vector StoryViewers::get_user_ids() const { - return transform(story_viewers_, [](auto &viewer) { return viewer.get_user_id(); }); +vector StoryViewers::get_viewer_user_ids() const { + vector result; + for (const auto &story_viewer : story_viewers_) { + auto user_id = story_viewer.get_viewer_user_id(); + if (user_id.is_valid()) { + result.push_back(user_id); + } + } + return result; +} + +vector StoryViewers::get_actor_dialog_ids() const { + return transform(story_viewers_, [](auto &viewer) { return viewer.get_actor_dialog_id(); }); } td_api::object_ptr StoryViewers::get_story_interactions_object( diff --git a/td/telegram/StoryViewer.h b/td/telegram/StoryViewer.h index f3d3fbd3d..b8922c2a0 100644 --- a/td/telegram/StoryViewer.h +++ b/td/telegram/StoryViewer.h @@ -6,6 +6,7 @@ // #pragma once +#include "td/telegram/DialogId.h" #include "td/telegram/ReactionType.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" @@ -37,10 +38,14 @@ class StoryViewer { , reaction_type_(story_view->reaction_) { } - UserId get_user_id() const { + UserId get_viewer_user_id() const { return user_id_; } + DialogId get_actor_dialog_id() const { + return DialogId(user_id_); + } + td_api::object_ptr get_story_interaction_object(ContactsManager *contacts_manager) const; }; @@ -59,7 +64,9 @@ class StoryViewers { StoryViewers(Td *td, int32 total_count, int32 total_forward_count, int32 total_reaction_count, vector> &&story_views, string &&next_offset); - vector get_user_ids() const; + vector get_viewer_user_ids() const; + + vector get_actor_dialog_ids() const; td_api::object_ptr get_story_interactions_object(ContactsManager *contacts_manager) const; };