Add Story.can_get_statistics.

This commit is contained in:
levlam 2023-11-17 14:58:51 +03:00
parent cda21980b0
commit a689c8df56
5 changed files with 40 additions and 21 deletions

View File

@ -3491,6 +3491,7 @@ storyInteractionInfo view_count:int32 forward_count:int32 reaction_count:int32 r
//@can_be_forwarded True, if the story can be forwarded as a message. Otherwise, screenshots and saving of the story content must be also forbidden
//@can_be_replied True, if the story can be replied in the chat with the story sender
//@can_toggle_is_pinned True, if the story's is_pinned value can be changed
//@can_get_statistics True, if the story statistics are available through getStoryStatistics
//@can_get_viewers True, if users viewed the story can be received through getStoryViewers
//@has_expired_viewers True, if users viewed the story can't be received, because the story has expired more than getOption("story_viewers_expiration_delay") seconds ago
//@interaction_info Information about interactions with the story; may be null if the story isn't owned or there were no interactions
@ -3499,7 +3500,7 @@ storyInteractionInfo view_count:int32 forward_count:int32 reaction_count:int32 r
//@content Content of the story
//@areas Clickable areas to be shown on the story content
//@caption Caption of the story
story id:int32 sender_chat_id:int53 date:int32 is_being_sent:Bool is_being_edited:Bool is_edited:Bool is_pinned:Bool is_visible_only_for_self:Bool can_be_deleted:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_replied:Bool can_toggle_is_pinned:Bool can_get_viewers:Bool has_expired_viewers:Bool interaction_info:storyInteractionInfo chosen_reaction_type:ReactionType privacy_settings:StoryPrivacySettings content:StoryContent areas:vector<storyArea> caption:formattedText = Story;
story id:int32 sender_chat_id:int53 date:int32 is_being_sent:Bool is_being_edited:Bool is_edited:Bool is_pinned:Bool is_visible_only_for_self:Bool can_be_deleted:Bool can_be_edited:Bool can_be_forwarded:Bool can_be_replied:Bool can_toggle_is_pinned:Bool can_get_statistics:Bool can_get_viewers:Bool has_expired_viewers:Bool interaction_info:storyInteractionInfo chosen_reaction_type:ReactionType privacy_settings:StoryPrivacySettings content:StoryContent areas:vector<storyArea> caption:formattedText = Story;
//@description Represents a list of stories @total_count Approximate total number of stories found @stories The list of stories
stories total_count:int32 stories:vector<story> = Stories;

View File

@ -8461,6 +8461,7 @@ void ContactsManager::get_channel_statistics_dc_id_impl(ChannelId channel_id, bo
}
bool ContactsManager::can_get_channel_message_statistics(DialogId dialog_id) const {
CHECK(!td_->auth_manager_->is_bot());
if (dialog_id.get_type() != DialogType::Channel) {
return false;
}
@ -8471,7 +8472,23 @@ bool ContactsManager::can_get_channel_message_statistics(DialogId dialog_id) con
return false;
}
if (td_->auth_manager_->is_bot()) {
auto channel_full = get_channel_full(channel_id);
if (channel_full != nullptr) {
return channel_full->stats_dc_id.is_exact();
}
return c->status.can_post_messages();
}
bool ContactsManager::can_get_channel_story_statistics(DialogId dialog_id) const {
CHECK(!td_->auth_manager_->is_bot());
if (dialog_id.get_type() != DialogType::Channel) {
return false;
}
auto channel_id = dialog_id.get_channel_id();
const Channel *c = get_channel(channel_id);
if (c == nullptr || c->is_megagroup) {
return false;
}

View File

@ -503,6 +503,8 @@ class ContactsManager final : public Actor {
bool can_get_channel_message_statistics(DialogId dialog_id) const;
bool can_get_channel_story_statistics(DialogId dialog_id) const;
struct CanTransferOwnershipResult {
enum class Type : uint8 { Ok, PasswordNeeded, PasswordTooFresh, SessionTooFresh };
Type type = Type::Ok;

View File

@ -1712,19 +1712,17 @@ StoryManager::Story *StoryManager::on_get_story_from_database(StoryFullId story_
}
bool StoryManager::can_get_story_statistics(StoryFullId story_full_id) {
return can_get_story_statistics(story_full_id.get_dialog_id(),
get_story_force(story_full_id, "can_get_story_statistics"));
return can_get_story_statistics(story_full_id, get_story_force(story_full_id, "can_get_story_statistics"));
}
bool StoryManager::can_get_story_statistics(DialogId owner_dialog_id, const Story *story) const {
bool StoryManager::can_get_story_statistics(StoryFullId story_full_id, const Story *story) const {
if (td_->auth_manager_->is_bot()) {
return false;
}
if (owner_dialog_id.get_type() != DialogType::Channel ||
!td_->contacts_manager_->is_broadcast_channel(owner_dialog_id.get_channel_id())) {
if (story == nullptr || !story_full_id.get_story_id().is_server()) {
return false;
}
return true;
return td_->contacts_manager_->can_get_channel_story_statistics(story_full_id.get_dialog_id());
}
const StoryManager::ActiveStories *StoryManager::get_active_stories(DialogId owner_dialog_id) const {
@ -2989,21 +2987,22 @@ td_api::object_ptr<td_api::story> StoryManager::get_story_object(StoryFullId sto
}
}
bool is_being_sent = !story_id.is_server();
auto is_being_sent = !story_id.is_server();
auto changelog_dialog_id = get_changelog_story_dialog_id();
bool is_visible_only_for_self = !story_id.is_server() || owner_dialog_id == changelog_dialog_id ||
auto is_visible_only_for_self = !story_id.is_server() || owner_dialog_id == changelog_dialog_id ||
(!story->is_pinned_ && !is_active_story(story));
bool can_be_deleted = can_delete_story(story_full_id, story);
bool can_be_edited = can_edit_story(story_full_id, story);
bool can_be_forwarded = !story->noforwards_ && story_id.is_server() &&
auto can_be_deleted = can_delete_story(story_full_id, story);
auto can_be_edited = can_edit_story(story_full_id, story);
auto can_be_forwarded = !story->noforwards_ && story_id.is_server() &&
privacy_settings->get_id() == td_api::storyPrivacySettingsEveryone::ID;
bool can_be_replied =
auto can_be_replied =
story_id.is_server() && owner_dialog_id != changelog_dialog_id && owner_dialog_id.get_type() == DialogType::User;
bool can_toggle_is_pinned = can_toggle_story_is_pinned(story_full_id, story);
auto can_toggle_is_pinned = can_toggle_story_is_pinned(story_full_id, story);
auto unix_time = G()->unix_time();
bool can_get_viewers = can_get_story_viewers(story_full_id, story, unix_time).is_ok();
auto can_get_statistics = can_get_story_statistics(story_full_id, story);
auto can_get_viewers = can_get_story_viewers(story_full_id, story, unix_time).is_ok();
auto interaction_info = story->interaction_info_.get_story_interaction_info_object(td_);
bool has_expired_viewers = is_my_story(owner_dialog_id) && story_id.is_server() &&
auto has_expired_viewers = is_my_story(owner_dialog_id) && story_id.is_server() &&
unix_time >= get_story_viewers_expire_date(story) && interaction_info != nullptr &&
interaction_info->view_count_ > interaction_info->reaction_count_;
const auto &reaction_counts = story->interaction_info_.get_reaction_counts();
@ -3016,9 +3015,9 @@ td_api::object_ptr<td_api::story> StoryManager::get_story_object(StoryFullId sto
return td_api::make_object<td_api::story>(
story_id.get(), td_->messages_manager_->get_chat_id_object(owner_dialog_id, "get_story_object"), story->date_,
is_being_sent, is_being_edited, is_edited, story->is_pinned_, is_visible_only_for_self, can_be_deleted,
can_be_edited, can_be_forwarded, can_be_replied, can_toggle_is_pinned, can_get_viewers, has_expired_viewers,
std::move(interaction_info), story->chosen_reaction_type_.get_reaction_type_object(), std::move(privacy_settings),
get_story_content_object(td_, content), std::move(story_areas),
can_be_edited, can_be_forwarded, can_be_replied, can_toggle_is_pinned, can_get_statistics, can_get_viewers,
has_expired_viewers, std::move(interaction_info), story->chosen_reaction_type_.get_reaction_type_object(),
std::move(privacy_settings), get_story_content_object(td_, content), std::move(story_areas),
get_formatted_text_object(*caption, true, get_story_content_duration(td_, content)));
}

View File

@ -370,7 +370,7 @@ class StoryManager final : public Actor {
bool can_access_expired_story(DialogId owner_dialog_id, const Story *story) const;
bool can_get_story_statistics(DialogId owner_dialog_id, const Story *story) const;
bool can_get_story_statistics(StoryFullId story_full_id, const Story *story) const;
bool can_get_story_view_count(DialogId owner_dialog_id);