From 5a19de8faa8bf29d6ca2d374b64e737c155117cb Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 19 Sep 2023 13:09:59 +0300 Subject: [PATCH] Add storyAreaTypeSuggestedReaction.total_count. --- td/generate/scheme/td_api.tl | 3 ++- td/telegram/MediaArea.cpp | 14 +++++++++++--- td/telegram/MediaArea.h | 3 ++- td/telegram/StoryInteractionInfo.cpp | 24 +++++++++++++++++++++--- td/telegram/StoryInteractionInfo.h | 6 ++++++ td/telegram/StoryInteractionInfo.hpp | 10 ++++++++++ td/telegram/StoryManager.cpp | 5 ++++- 7 files changed, 56 insertions(+), 9 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 8dd533116..645067b87 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3217,9 +3217,10 @@ storyAreaTypeVenue venue:venue = StoryAreaType; //@description An area pointing to a suggested reaction. App needs to show a clickable reaction on the area and call setStoryReaction when the are is clicked //@reaction_type Type of the reaction +//@total_count Number of times the reaction was added //@is_dark True, if reaction has a dark background //@is_flipped True, if reaction corner is flipped -storyAreaTypeSuggestedReaction reaction_type:ReactionType is_dark:Bool is_flipped:Bool = StoryAreaType; +storyAreaTypeSuggestedReaction reaction_type:ReactionType total_count:int32 is_dark:Bool is_flipped:Bool = StoryAreaType; //@description Describes a clickable rectangle area on a story media @position Position of the area @type Type of the area diff --git a/td/telegram/MediaArea.cpp b/td/telegram/MediaArea.cpp index de357c281..0d43e2353 100644 --- a/td/telegram/MediaArea.cpp +++ b/td/telegram/MediaArea.cpp @@ -128,7 +128,8 @@ bool MediaArea::has_reaction_type(const ReactionType &reaction_type) const { return reaction_type_ == reaction_type; } -td_api::object_ptr MediaArea::get_story_area_object() const { +td_api::object_ptr MediaArea::get_story_area_object( + const vector> &reaction_counts) const { CHECK(is_valid()); td_api::object_ptr type; switch (type_) { @@ -138,10 +139,17 @@ td_api::object_ptr MediaArea::get_story_area_object() const { case Type::Venue: type = td_api::make_object(venue_.get_venue_object()); break; - case Type::Reaction: + case Type::Reaction: { + int32 total_count = 0; + for (const auto &reaction_count : reaction_counts) { + if (reaction_count.first == reaction_type_) { + total_count = reaction_count.second; + } + } type = td_api::make_object(reaction_type_.get_reaction_type_object(), - is_dark_, is_flipped_); + total_count, is_dark_, is_flipped_); break; + } default: UNREACHABLE(); } diff --git a/td/telegram/MediaArea.h b/td/telegram/MediaArea.h index 75429e228..ba4e75535 100644 --- a/td/telegram/MediaArea.h +++ b/td/telegram/MediaArea.h @@ -47,7 +47,8 @@ class MediaArea { bool has_reaction_type(const ReactionType &reaction_type) const; - td_api::object_ptr get_story_area_object() const; + td_api::object_ptr get_story_area_object( + const vector> &reaction_counts) const; telegram_api::object_ptr get_input_media_area() const; diff --git a/td/telegram/StoryInteractionInfo.cpp b/td/telegram/StoryInteractionInfo.cpp index 963629195..7ef74ad7b 100644 --- a/td/telegram/StoryInteractionInfo.cpp +++ b/td/telegram/StoryInteractionInfo.cpp @@ -47,6 +47,24 @@ StoryInteractionInfo::StoryInteractionInfo(Td *td, telegram_api::object_ptrhas_viewers_; + + FlatHashSet added_reaction_types; + for (auto &reaction : story_views->reactions_) { + ReactionType reaction_type(reaction->reaction_); + if (reaction_type.is_empty()) { + LOG(ERROR) << "Receive empty " << to_string(reaction); + continue; + } + if (!added_reaction_types.insert(reaction_type).second) { + LOG(ERROR) << "Receive again " << to_string(reaction); + continue; + } + if (reaction->count_ == 0) { + LOG(ERROR) << "Receive " << to_string(reaction); + continue; + } + reaction_counts_.emplace_back(std::move(reaction_type), reaction->count_); + } } void StoryInteractionInfo::add_dependencies(Dependencies &dependencies) const { @@ -85,9 +103,9 @@ 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.forward_count_ == rhs.forward_count_ && lhs.reaction_count_ == rhs.reaction_count_ && - lhs.has_viewers_ == rhs.has_viewers_; + return lhs.recent_viewer_user_ids_ == rhs.recent_viewer_user_ids_ && lhs.reaction_counts_ == rhs.reaction_counts_ && + lhs.view_count_ == rhs.view_count_ && lhs.forward_count_ == rhs.forward_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 5bbbc8dc4..b8604c6b0 100644 --- a/td/telegram/StoryInteractionInfo.h +++ b/td/telegram/StoryInteractionInfo.h @@ -6,6 +6,7 @@ // #pragma once +#include "td/telegram/ReactionType.h" #include "td/telegram/td_api.h" #include "td/telegram/telegram_api.h" #include "td/telegram/UserId.h" @@ -20,6 +21,7 @@ class Td; class StoryInteractionInfo { vector recent_viewer_user_ids_; + vector> reaction_counts_; int32 view_count_ = -1; int32 forward_count_ = 0; int32 reaction_count_ = 0; @@ -63,6 +65,10 @@ class StoryInteractionInfo { return reaction_count_; } + const vector> &get_reaction_counts() const { + return reaction_counts_; + } + bool definitely_has_no_user(UserId user_id) const; bool set_recent_viewer_user_ids(vector &&user_ids); diff --git a/td/telegram/StoryInteractionInfo.hpp b/td/telegram/StoryInteractionInfo.hpp index 46c298b06..4f2c5385f 100644 --- a/td/telegram/StoryInteractionInfo.hpp +++ b/td/telegram/StoryInteractionInfo.hpp @@ -20,12 +20,14 @@ void StoryInteractionInfo::store(StorerT &storer) const { bool has_reaction_count = reaction_count_ > 0; bool know_has_viewers = true; bool has_forward_count = forward_count_ > 0; + bool has_reaction_counts = !reaction_counts_.empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_recent_viewer_user_ids); STORE_FLAG(has_reaction_count); STORE_FLAG(know_has_viewers); STORE_FLAG(has_viewers_); STORE_FLAG(has_forward_count); + STORE_FLAG(has_reaction_counts); END_STORE_FLAGS(); store(view_count_, storer); if (has_recent_viewer_user_ids) { @@ -37,6 +39,9 @@ void StoryInteractionInfo::store(StorerT &storer) const { if (has_forward_count) { store(forward_count_, storer); } + if (has_reaction_counts) { + store(reaction_counts_, storer); + } } template @@ -46,12 +51,14 @@ void StoryInteractionInfo::parse(ParserT &parser) { bool has_reaction_count; bool know_has_viewers; bool has_forward_count; + bool has_reaction_counts; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_recent_viewer_user_ids); PARSE_FLAG(has_reaction_count); PARSE_FLAG(know_has_viewers); PARSE_FLAG(has_viewers_); PARSE_FLAG(has_forward_count); + PARSE_FLAG(has_reaction_counts); END_PARSE_FLAGS(); parse(view_count_, parser); if (has_recent_viewer_user_ids) { @@ -63,6 +70,9 @@ void StoryInteractionInfo::parse(ParserT &parser) { if (has_forward_count) { parse(forward_count_, parser); } + if (has_reaction_counts) { + parse(reaction_counts_, parser); + } if (!know_has_viewers) { has_viewers_ = (view_count_ > 0 && !has_recent_viewer_user_ids) || reaction_count_ > 0; diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 26d7600af..b532e08de 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -3248,7 +3248,10 @@ td_api::object_ptr StoryManager::get_story_object(StoryFullId sto G()->unix_time_cached() >= get_story_viewers_expire_date(story) && interaction_info != nullptr && interaction_info->view_count_ > interaction_info->reaction_count_; - auto story_areas = transform(*areas, [](const MediaArea &media_area) { return media_area.get_story_area_object(); }); + const auto &reaction_counts = story->interaction_info_.get_reaction_counts(); + auto story_areas = transform(*areas, [&reaction_counts](const MediaArea &media_area) { + return media_area.get_story_area_object(reaction_counts); + }); story->is_update_sent_ = true;