From 03c8bf0cd32322e5d2be683b81201d03944d68c0 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 14 Aug 2023 00:29:57 +0300 Subject: [PATCH] Support StoryInteractionInfo.has_viewers_. --- td/telegram/StoryInteractionInfo.cpp | 5 +++-- td/telegram/StoryInteractionInfo.h | 3 ++- td/telegram/StoryInteractionInfo.hpp | 9 +++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/td/telegram/StoryInteractionInfo.cpp b/td/telegram/StoryInteractionInfo.cpp index f82953be8..da6c23e73 100644 --- a/td/telegram/StoryInteractionInfo.cpp +++ b/td/telegram/StoryInteractionInfo.cpp @@ -41,6 +41,7 @@ StoryInteractionInfo::StoryInteractionInfo(Td *td, telegram_api::object_ptrhas_viewers_; } void StoryInteractionInfo::add_dependencies(Dependencies &dependencies) const { @@ -61,7 +62,7 @@ bool StoryInteractionInfo::set_recent_viewer_user_ids(vector &&user_ids) } bool StoryInteractionInfo::definitely_has_no_user(UserId user_id) const { - return !is_empty() && view_count_ <= static_cast(MAX_RECENT_VIEWERS) && + return !is_empty() && view_count_ == static_cast(recent_viewer_user_ids_.size()) && !contains(recent_viewer_user_ids_, user_id); } @@ -76,7 +77,7 @@ td_api::object_ptr StoryInteractionInfo::get_story bool operator==(const StoryInteractionInfo &lhs, const StoryInteractionInfo &rhs) { return lhs.recent_viewer_user_ids_ == rhs.recent_viewer_user_ids_ && lhs.view_count_ == rhs.view_count_ && - lhs.reaction_count_ == rhs.reaction_count_; + lhs.reaction_count_ == rhs.reaction_count_ && lhs.has_viewers_ == rhs.has_viewers_; } StringBuilder &operator<<(StringBuilder &string_builder, const StoryInteractionInfo &info) { diff --git a/td/telegram/StoryInteractionInfo.h b/td/telegram/StoryInteractionInfo.h index b05298056..dbe3eed97 100644 --- a/td/telegram/StoryInteractionInfo.h +++ b/td/telegram/StoryInteractionInfo.h @@ -22,6 +22,7 @@ class StoryInteractionInfo { vector recent_viewer_user_ids_; int32 view_count_ = -1; int32 reaction_count_ = 0; + bool has_viewers_ = false; static constexpr size_t MAX_RECENT_VIEWERS = 3; @@ -39,7 +40,7 @@ class StoryInteractionInfo { } bool has_hidden_viewers() const { - return view_count_ < 0 || (recent_viewer_user_ids_.empty() && view_count_ > 0); + return view_count_ < 0 || !has_viewers_; } void add_dependencies(Dependencies &dependencies) const; diff --git a/td/telegram/StoryInteractionInfo.hpp b/td/telegram/StoryInteractionInfo.hpp index b47afef0d..112010298 100644 --- a/td/telegram/StoryInteractionInfo.hpp +++ b/td/telegram/StoryInteractionInfo.hpp @@ -18,9 +18,12 @@ void StoryInteractionInfo::store(StorerT &storer) const { using td::store; bool has_recent_viewer_user_ids = !recent_viewer_user_ids_.empty(); bool has_reaction_count = reaction_count_ > 0; + bool know_has_viewers = true; BEGIN_STORE_FLAGS(); STORE_FLAG(has_recent_viewer_user_ids); STORE_FLAG(has_reaction_count); + STORE_FLAG(know_has_viewers); + STORE_FLAG(has_viewers_); END_STORE_FLAGS(); store(view_count_, storer); if (has_recent_viewer_user_ids) { @@ -36,9 +39,12 @@ void StoryInteractionInfo::parse(ParserT &parser) { using td::parse; bool has_recent_viewer_user_ids; bool has_reaction_count; + bool know_has_viewers; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_recent_viewer_user_ids); PARSE_FLAG(has_reaction_count); + PARSE_FLAG(know_has_viewers); + PARSE_FLAG(has_viewers_); END_PARSE_FLAGS(); parse(view_count_, parser); if (has_recent_viewer_user_ids) { @@ -47,6 +53,9 @@ void StoryInteractionInfo::parse(ParserT &parser) { if (has_reaction_count) { parse(reaction_count_, parser); } + if (!know_has_viewers) { + has_viewers_ = (view_count_ > 0 && !has_recent_viewer_user_ids) || reaction_count_ > 0; + } } } // namespace td