Improve StoryViewer getters.

This commit is contained in:
levlam 2023-12-25 16:32:41 +03:00
parent a4ed86c44e
commit 964663948d
4 changed files with 30 additions and 10 deletions

View File

@ -113,6 +113,9 @@ bool StoryInteractionInfo::set_recent_viewer_user_ids(vector<UserId> &&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<size_t>(view_count_)) {
return false;
}
if (recent_viewer_user_ids_ != user_ids) {
recent_viewer_user_ids_ = std::move(user_ids);
return true;

View File

@ -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()));
}

View File

@ -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<UserId> StoryViewers::get_user_ids() const {
return transform(story_viewers_, [](auto &viewer) { return viewer.get_user_id(); });
vector<UserId> StoryViewers::get_viewer_user_ids() const {
vector<UserId> 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<DialogId> StoryViewers::get_actor_dialog_ids() const {
return transform(story_viewers_, [](auto &viewer) { return viewer.get_actor_dialog_id(); });
}
td_api::object_ptr<td_api::storyInteractions> StoryViewers::get_story_interactions_object(

View File

@ -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<td_api::storyInteraction> 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<telegram_api::object_ptr<telegram_api::StoryView>> &&story_views, string &&next_offset);
vector<UserId> get_user_ids() const;
vector<UserId> get_viewer_user_ids() const;
vector<DialogId> get_actor_dialog_ids() const;
td_api::object_ptr<td_api::storyInteractions> get_story_interactions_object(ContactsManager *contacts_manager) const;
};