Add storyAreaTypeSuggestedReaction.total_count.
This commit is contained in:
parent
fde0c8a0b1
commit
5a19de8faa
@ -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
|
||||
|
@ -128,7 +128,8 @@ bool MediaArea::has_reaction_type(const ReactionType &reaction_type) const {
|
||||
return reaction_type_ == reaction_type;
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::storyArea> MediaArea::get_story_area_object() const {
|
||||
td_api::object_ptr<td_api::storyArea> MediaArea::get_story_area_object(
|
||||
const vector<std::pair<ReactionType, int32>> &reaction_counts) const {
|
||||
CHECK(is_valid());
|
||||
td_api::object_ptr<td_api::StoryAreaType> type;
|
||||
switch (type_) {
|
||||
@ -138,10 +139,17 @@ td_api::object_ptr<td_api::storyArea> MediaArea::get_story_area_object() const {
|
||||
case Type::Venue:
|
||||
type = td_api::make_object<td_api::storyAreaTypeVenue>(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<td_api::storyAreaTypeSuggestedReaction>(reaction_type_.get_reaction_type_object(),
|
||||
is_dark_, is_flipped_);
|
||||
total_count, is_dark_, is_flipped_);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
@ -47,7 +47,8 @@ class MediaArea {
|
||||
|
||||
bool has_reaction_type(const ReactionType &reaction_type) const;
|
||||
|
||||
td_api::object_ptr<td_api::storyArea> get_story_area_object() const;
|
||||
td_api::object_ptr<td_api::storyArea> get_story_area_object(
|
||||
const vector<std::pair<ReactionType, int32>> &reaction_counts) const;
|
||||
|
||||
telegram_api::object_ptr<telegram_api::MediaArea> get_input_media_area() const;
|
||||
|
||||
|
@ -47,6 +47,24 @@ StoryInteractionInfo::StoryInteractionInfo(Td *td, telegram_api::object_ptr<tele
|
||||
reaction_count_ = 0;
|
||||
}
|
||||
has_viewers_ = story_views->has_viewers_;
|
||||
|
||||
FlatHashSet<ReactionType, ReactionTypeHash> 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<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.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) {
|
||||
|
@ -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<UserId> recent_viewer_user_ids_;
|
||||
vector<std::pair<ReactionType, int32>> 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<std::pair<ReactionType, int32>> &get_reaction_counts() const {
|
||||
return reaction_counts_;
|
||||
}
|
||||
|
||||
bool definitely_has_no_user(UserId user_id) const;
|
||||
|
||||
bool set_recent_viewer_user_ids(vector<UserId> &&user_ids);
|
||||
|
@ -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 <class ParserT>
|
||||
@ -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;
|
||||
|
@ -3248,7 +3248,10 @@ td_api::object_ptr<td_api::story> 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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user