From 3bc3ef33354f4e80d451789127b96e087f050068 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 7 Aug 2023 20:04:06 +0300 Subject: [PATCH] Update reaction count when get story viewers. --- td/telegram/StoryInteractionInfo.h | 5 +++-- td/telegram/StoryManager.cpp | 12 +++++++----- td/telegram/StoryManager.h | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/td/telegram/StoryInteractionInfo.h b/td/telegram/StoryInteractionInfo.h index 9d5c7da33..9ebb72785 100644 --- a/td/telegram/StoryInteractionInfo.h +++ b/td/telegram/StoryInteractionInfo.h @@ -40,9 +40,10 @@ class StoryInteractionInfo { void add_dependencies(Dependencies &dependencies) const; - bool set_view_count(int32 view_count) { - if (view_count > view_count_) { + bool set_counts(int32 view_count, int32 reaction_count) { + if (view_count != view_count_ || reaction_count != reaction_count_) { view_count = view_count_; + reaction_count = reaction_count_; return true; } return false; diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index dd936bc53..fbd40cfda 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -2346,11 +2346,12 @@ void StoryManager::get_story_viewers(StoryId story_id, const string &query, bool return promise.set_value(td_api::make_object()); } - bool is_first = offset.empty() && query.empty() && !only_contacts; + bool is_full = query.empty() && !only_contacts; + bool is_first = is_full && offset.empty(); auto query_promise = PromiseCreator::lambda( - [actor_id = actor_id(this), story_id, is_first, promise = std::move(promise)]( + [actor_id = actor_id(this), story_id, is_full, is_first, promise = std::move(promise)]( Result> result) mutable { - send_closure(actor_id, &StoryManager::on_get_story_viewers, story_id, is_first, std::move(result), + send_closure(actor_id, &StoryManager::on_get_story_viewers, story_id, is_full, is_first, std::move(result), std::move(promise)); }); @@ -2359,7 +2360,8 @@ void StoryManager::get_story_viewers(StoryId story_id, const string &query, bool } void StoryManager::on_get_story_viewers( - StoryId story_id, bool is_first, Result> r_view_list, + StoryId story_id, bool is_full, bool is_first, + Result> r_view_list, Promise> &&promise) { G()->ignore_result_if_closing(r_view_list); if (r_view_list.is_error()) { @@ -2386,7 +2388,7 @@ void StoryManager::on_get_story_viewers( StoryViewers story_viewers(std::move(view_list->views_), std::move(view_list->next_offset_)); if (story->content_ != nullptr) { bool is_changed = false; - if (story->interaction_info_.set_view_count(view_list->count_)) { + if (is_full && story->interaction_info_.set_counts(view_list->count_, view_list->reactions_count_)) { is_changed = true; } if (is_first && story->interaction_info_.set_recent_viewer_user_ids(story_viewers.get_user_ids())) { diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 2bd6863c2..21b7cf66c 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -523,7 +523,7 @@ class StoryManager final : public Actor { void set_story_stealth_mode(StoryStealthMode stealth_mode); - void on_get_story_viewers(StoryId story_id, bool is_first, + void on_get_story_viewers(StoryId story_id, bool is_full, bool is_first, Result> r_view_list, Promise> &&promise);