diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index bf2553f72..c1c827489 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3315,8 +3315,11 @@ storyInteractionInfo view_count:int32 reaction_count:int32 recent_viewer_user_id //@is_edited True, if the story was edited //@is_pinned True, if the story is saved in the sender's profile and will be available there after expiration //@is_visible_only_for_self True, if the story is visible only for the current user +//@can_be_deleted True, if the story can be deleted +//@can_be_edited True, if the story can be edited //@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_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 @@ -3325,7 +3328,7 @@ storyInteractionInfo view_count:int32 reaction_count:int32 recent_viewer_user_id //@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_forwarded:Bool can_be_replied:Bool can_get_viewers:Bool has_expired_viewers:Bool interaction_info:storyInteractionInfo chosen_reaction_type:ReactionType privacy_settings:StoryPrivacySettings content:StoryContent areas:vector 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_viewers:Bool has_expired_viewers:Bool interaction_info:storyInteractionInfo chosen_reaction_type:ReactionType privacy_settings:StoryPrivacySettings content:StoryContent areas:vector 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 = Stories; diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 02422ab85..e9d8bbb44 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -1504,25 +1504,27 @@ bool StoryManager::can_delete_stories(DialogId owner_dialog_id) const { } } -bool StoryManager::can_edit_story(StoryFullId story_full_id, const Story *story) { +bool StoryManager::can_edit_story(StoryFullId story_full_id, const Story *story) const { + if (!story_full_id.get_story_id().is_server()) { + return false; + } + auto owner_dialog_id = story_full_id.get_dialog_id(); + return can_edit_stories(owner_dialog_id) || (story->is_outgoing_ && can_post_stories(owner_dialog_id)); +} + +bool StoryManager::can_toggle_story_is_pinned(StoryFullId story_full_id, const Story *story) const { if (!story_full_id.get_story_id().is_server()) { return false; } return can_edit_stories(story_full_id.get_dialog_id()); } -bool StoryManager::can_toggle_story_is_pinned(StoryFullId story_full_id, const Story *story) { - if (!story_full_id.get_story_id().is_server()) { - return false; - } - return can_edit_stories(story_full_id.get_dialog_id()); -} - -bool StoryManager::can_delete_story(StoryFullId story_full_id, const Story *story) { +bool StoryManager::can_delete_story(StoryFullId story_full_id, const Story *story) const { if (!story_full_id.get_story_id().is_server()) { return true; } - return can_delete_stories(story_full_id.get_dialog_id()); + auto owner_dialog_id = story_full_id.get_dialog_id(); + return can_delete_stories(owner_dialog_id) || (story->is_outgoing_ && can_post_stories(owner_dialog_id)); } bool StoryManager::is_active_story(const Story *story) { @@ -2859,9 +2861,13 @@ td_api::object_ptr StoryManager::get_story_object(StoryFullId sto 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 || (!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() && privacy_settings->get_id() == td_api::storyPrivacySettingsEveryone::ID; - bool can_be_replied = story_id.is_server() && owner_dialog_id != changelog_dialog_id; + bool 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); bool can_get_viewers = can_get_story_viewers(story_full_id, story, false).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() && @@ -2874,9 +2880,9 @@ td_api::object_ptr StoryManager::get_story_object(StoryFullId sto return td_api::make_object( 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_forwarded, - can_be_replied, can_get_viewers, has_expired_viewers, std::move(interaction_info), - story->chosen_reaction_type_.get_reaction_type_object(), std::move(privacy_settings), + 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), get_formatted_text_object(*caption, true, get_story_content_duration(td_, content))); } diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index dab7bc556..ffeedb07f 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -365,11 +365,11 @@ class StoryManager final : public Actor { bool can_delete_stories(DialogId owner_dialog_id) const; - bool can_edit_story(StoryFullId story_full_id, const Story *story); + bool can_edit_story(StoryFullId story_full_id, const Story *story) const; - bool can_toggle_story_is_pinned(StoryFullId story_full_id, const Story *story); + bool can_toggle_story_is_pinned(StoryFullId story_full_id, const Story *story) const; - bool can_delete_story(StoryFullId story_full_id, const Story *story); + bool can_delete_story(StoryFullId story_full_id, const Story *story) const; int32 get_story_viewers_expire_date(const Story *story) const;