Add more fields to class StoryViewer.

This commit is contained in:
levlam 2023-08-07 17:19:12 +03:00
parent de5718d0e5
commit 0eec3dda94
9 changed files with 49 additions and 27 deletions

View File

@ -4931,8 +4931,12 @@ messageLink link:string is_public:Bool = MessageLink;
messageLinkInfo is_public:Bool chat_id:int53 message_thread_id:int53 message:message media_timestamp:int32 for_album:Bool = MessageLinkInfo; messageLinkInfo is_public:Bool chat_id:int53 message_thread_id:int53 message:message media_timestamp:int32 for_album:Bool = MessageLinkInfo;
//@description Represents a viewer of a story @user_id User identifier of the viewer @view_date Approximate point in time (Unix timestamp) when the story was viewed //@description Represents a viewer of a story
storyViewer user_id:int53 view_date:int32 = StoryViewer; //@user_id User identifier of the viewer
//@view_date Approximate point in time (Unix timestamp) when the story was viewed
//@block_list Block list to which the user is added; may be null if none
//@chosen_reaction_type Type of the reaction that was chosen by the user; may be null if none
storyViewer user_id:int53 view_date:int32 block_list:BlockList chosen_reaction_type:ReactionType = StoryViewer;
//@description Represents a list of story viewers @viewers List of story viewers //@description Represents a list of story viewers @viewers List of story viewers
storyViewers viewers:vector<storyViewer> = StoryViewers; storyViewers viewers:vector<storyViewer> = StoryViewers;

View File

@ -95,7 +95,9 @@ telegram_api::object_ptr<telegram_api::Reaction> ReactionType::get_input_reactio
} }
td_api::object_ptr<td_api::ReactionType> ReactionType::get_reaction_type_object() const { td_api::object_ptr<td_api::ReactionType> ReactionType::get_reaction_type_object() const {
CHECK(!is_empty()); if (is_empty()) {
return nullptr;
}
if (is_custom_reaction()) { if (is_custom_reaction()) {
return td_api::make_object<td_api::reactionTypeCustomEmoji>(get_custom_emoji_id(reaction_)); return td_api::make_object<td_api::reactionTypeCustomEmoji>(get_custom_emoji_id(reaction_));
} }

View File

@ -49,11 +49,15 @@ void StoryInteractionInfo::add_dependencies(Dependencies &dependencies) const {
} }
} }
void StoryInteractionInfo::set_recent_viewer_user_ids(vector<UserId> &&user_ids) { bool StoryInteractionInfo::set_recent_viewer_user_ids(vector<UserId> &&user_ids) {
if (user_ids.size() > MAX_RECENT_VIEWERS) { if (user_ids.size() > MAX_RECENT_VIEWERS) {
user_ids.resize(MAX_RECENT_VIEWERS); user_ids.resize(MAX_RECENT_VIEWERS);
} }
if (recent_viewer_user_ids_ != user_ids) {
recent_viewer_user_ids_ = std::move(user_ids); recent_viewer_user_ids_ = std::move(user_ids);
return true;
}
return false;
} }
bool StoryInteractionInfo::definitely_has_no_user(UserId user_id) const { bool StoryInteractionInfo::definitely_has_no_user(UserId user_id) const {

View File

@ -54,7 +54,7 @@ class StoryInteractionInfo {
bool definitely_has_no_user(UserId user_id) const; bool definitely_has_no_user(UserId user_id) const;
void set_recent_viewer_user_ids(vector<UserId> &&user_ids); bool set_recent_viewer_user_ids(vector<UserId> &&user_ids);
td_api::object_ptr<td_api::storyInteractionInfo> get_story_interaction_info_object(Td *td) const; td_api::object_ptr<td_api::storyInteractionInfo> get_story_interaction_info_object(Td *td) const;

View File

@ -2341,12 +2341,12 @@ void StoryManager::get_story_viewers(StoryId story_id, const td_api::storyViewer
offset_date = offset->view_date_; offset_date = offset->view_date_;
offset_user_id = offset->user_id_; offset_user_id = offset->user_id_;
} }
StoryViewer offset_viewer{UserId(offset_user_id), offset_date}; bool is_first = offset_user_id <= 0 && offset_date <= 0;
auto query_promise = PromiseCreator::lambda( auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), story_id, offset_viewer, promise = std::move(promise)]( [actor_id = actor_id(this), story_id, is_first, promise = std::move(promise)](
Result<telegram_api::object_ptr<telegram_api::stories_storyViewsList>> result) mutable { Result<telegram_api::object_ptr<telegram_api::stories_storyViewsList>> result) mutable {
send_closure(actor_id, &StoryManager::on_get_story_viewers, story_id, offset_viewer, std::move(result), send_closure(actor_id, &StoryManager::on_get_story_viewers, story_id, is_first, std::move(result),
std::move(promise)); std::move(promise));
}); });
@ -2355,8 +2355,7 @@ void StoryManager::get_story_viewers(StoryId story_id, const td_api::storyViewer
} }
void StoryManager::on_get_story_viewers( void StoryManager::on_get_story_viewers(
StoryId story_id, StoryViewer offset, StoryId story_id, bool is_first, Result<telegram_api::object_ptr<telegram_api::stories_storyViewsList>> r_view_list,
Result<telegram_api::object_ptr<telegram_api::stories_storyViewsList>> r_view_list,
Promise<td_api::object_ptr<td_api::storyViewers>> &&promise) { Promise<td_api::object_ptr<td_api::storyViewers>> &&promise) {
G()->ignore_result_if_closing(r_view_list); G()->ignore_result_if_closing(r_view_list);
if (r_view_list.is_error()) { if (r_view_list.is_error()) {
@ -2382,10 +2381,14 @@ void StoryManager::on_get_story_viewers(
StoryViewers story_viewers(std::move(view_list->views_)); StoryViewers story_viewers(std::move(view_list->views_));
if (story->content_ != nullptr) { if (story->content_ != nullptr) {
bool is_changed = false;
if (story->interaction_info_.set_view_count(view_list->count_)) { if (story->interaction_info_.set_view_count(view_list->count_)) {
if (offset.is_empty()) { is_changed = true;
story->interaction_info_.set_recent_viewer_user_ids(story_viewers.get_user_ids());
} }
if (is_first && story->interaction_info_.set_recent_viewer_user_ids(story_viewers.get_user_ids())) {
is_changed = true;
}
if (is_changed) {
on_story_changed(story_full_id, story, true, true); on_story_changed(story_full_id, story, true, true);
} }
} }

View File

@ -522,7 +522,7 @@ class StoryManager final : public Actor {
void set_story_stealth_mode(StoryStealthMode stealth_mode); void set_story_stealth_mode(StoryStealthMode stealth_mode);
void on_get_story_viewers(StoryId story_id, StoryViewer offset, void on_get_story_viewers(StoryId story_id, bool is_first,
Result<telegram_api::object_ptr<telegram_api::stories_storyViewsList>> r_view_list, Result<telegram_api::object_ptr<telegram_api::stories_storyViewsList>> r_view_list,
Promise<td_api::object_ptr<td_api::storyViewers>> &&promise); Promise<td_api::object_ptr<td_api::storyViewers>> &&promise);

View File

@ -6,6 +6,7 @@
// //
#include "td/telegram/StoryViewer.h" #include "td/telegram/StoryViewer.h"
#include "td/telegram/BlockListId.h"
#include "td/telegram/ContactsManager.h" #include "td/telegram/ContactsManager.h"
#include "td/utils/algorithm.h" #include "td/utils/algorithm.h"
@ -14,22 +15,24 @@
namespace td { namespace td {
td_api::object_ptr<td_api::storyViewer> StoryViewer::get_story_viewer_object(ContactsManager *contacts_manager) const { td_api::object_ptr<td_api::storyViewer> StoryViewer::get_story_viewer_object(ContactsManager *contacts_manager) const {
auto block_list_id = BlockListId(is_blocked_, is_blocked_for_stories_);
return td_api::make_object<td_api::storyViewer>( return td_api::make_object<td_api::storyViewer>(
contacts_manager->get_user_id_object(user_id_, "get_story_viewer_object"), date_); contacts_manager->get_user_id_object(user_id_, "get_story_viewer_object"), date_,
block_list_id.get_block_list_object(), reaction_type_.get_reaction_type_object());
} }
StringBuilder &operator<<(StringBuilder &string_builder, const StoryViewer &viewer) { StringBuilder &operator<<(StringBuilder &string_builder, const StoryViewer &viewer) {
return string_builder << '[' << viewer.user_id_ << " at " << viewer.date_ << ']'; return string_builder << '[' << viewer.user_id_ << " with " << viewer.reaction_type_ << " at " << viewer.date_ << ']';
} }
StoryViewers::StoryViewers(vector<telegram_api::object_ptr<telegram_api::storyView>> &&story_views) { StoryViewers::StoryViewers(vector<telegram_api::object_ptr<telegram_api::storyView>> &&story_views) {
for (auto &story_view : story_views) { for (auto &story_view : story_views) {
UserId user_id(story_view->user_id_); story_viewers_.emplace_back(std::move(story_view));
auto user_id = story_viewers_.back().get_user_id();
if (!user_id.is_valid()) { if (!user_id.is_valid()) {
LOG(ERROR) << "Receive " << user_id << " as story viewer"; LOG(ERROR) << "Receive invalid " << user_id << " as a viewer of a story";
continue; story_viewers_.pop_back();
} }
story_viewers_.emplace_back(user_id, story_view->date_);
} }
} }

View File

@ -6,6 +6,7 @@
// //
#pragma once #pragma once
#include "td/telegram/ReactionType.h"
#include "td/telegram/td_api.h" #include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h" #include "td/telegram/telegram_api.h"
#include "td/telegram/UserId.h" #include "td/telegram/UserId.h"
@ -20,21 +21,25 @@ class ContactsManager;
class StoryViewer { class StoryViewer {
UserId user_id_; UserId user_id_;
int32 date_ = 0; int32 date_ = 0;
bool is_blocked_ = false;
bool is_blocked_for_stories_ = false;
ReactionType reaction_type_;
friend StringBuilder &operator<<(StringBuilder &string_builder, const StoryViewer &viewer); friend StringBuilder &operator<<(StringBuilder &string_builder, const StoryViewer &viewer);
public: public:
StoryViewer(UserId user_id, int32 date) : user_id_(user_id), date_(td::max(date, static_cast<int32>(0))) { StoryViewer(telegram_api::object_ptr<telegram_api::storyView> &&story_view)
: user_id_(story_view->user_id_)
, date_(td::max(story_view->date_, static_cast<int32>(0)))
, is_blocked_(story_view->blocked_)
, is_blocked_for_stories_(story_view->blocked_my_stories_from_)
, reaction_type_(story_view->reaction_) {
} }
UserId get_user_id() const { UserId get_user_id() const {
return user_id_; return user_id_;
} }
bool is_empty() const {
return user_id_ == UserId() && date_ == 0;
}
td_api::object_ptr<td_api::storyViewer> get_story_viewer_object(ContactsManager *contacts_manager) const; td_api::object_ptr<td_api::storyViewer> get_story_viewer_object(ContactsManager *contacts_manager) const;
}; };

View File

@ -4155,7 +4155,8 @@ class CliClient final : public Actor {
UserId offset_user_id; UserId offset_user_id;
get_args(args, story_id, limit, offset_date, offset_user_id); get_args(args, story_id, limit, offset_date, offset_user_id);
send_request(td_api::make_object<td_api::getStoryViewers>( send_request(td_api::make_object<td_api::getStoryViewers>(
story_id, td_api::make_object<td_api::storyViewer>(offset_user_id, offset_date), as_limit(limit))); story_id, td_api::make_object<td_api::storyViewer>(offset_user_id, offset_date, nullptr, nullptr),
as_limit(limit)));
} else if (op == "rst") { } else if (op == "rst") {
ChatId story_sender_chat_id; ChatId story_sender_chat_id;
StoryId story_id; StoryId story_id;