Support StoryInteractionInfo.has_viewers_.

This commit is contained in:
levlam 2023-08-14 00:29:57 +03:00
parent a33ef5a055
commit 03c8bf0cd3
3 changed files with 14 additions and 3 deletions

View File

@ -41,6 +41,7 @@ StoryInteractionInfo::StoryInteractionInfo(Td *td, telegram_api::object_ptr<tele
LOG(ERROR) << "Receive " << reaction_count_ << " story reactions";
reaction_count_ = 0;
}
has_viewers_ = story_views->has_viewers_;
}
void StoryInteractionInfo::add_dependencies(Dependencies &dependencies) const {
@ -61,7 +62,7 @@ bool StoryInteractionInfo::set_recent_viewer_user_ids(vector<UserId> &&user_ids)
}
bool StoryInteractionInfo::definitely_has_no_user(UserId user_id) const {
return !is_empty() && view_count_ <= static_cast<int32>(MAX_RECENT_VIEWERS) &&
return !is_empty() && view_count_ == static_cast<int32>(recent_viewer_user_ids_.size()) &&
!contains(recent_viewer_user_ids_, user_id);
}
@ -76,7 +77,7 @@ td_api::object_ptr<td_api::storyInteractionInfo> 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) {

View File

@ -22,6 +22,7 @@ class StoryInteractionInfo {
vector<UserId> 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;

View File

@ -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