From a553447ac24060287d23e044f73db8284331eaaf Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 18 Jul 2023 16:19:11 +0300 Subject: [PATCH] Make story.privacy_settings always non-null. --- td/generate/scheme/td_api.tl | 6 +++--- td/telegram/StoryManager.cpp | 17 ++++++++++++++++- td/telegram/StoryManager.h | 2 ++ td/telegram/UserPrivacySettingRule.cpp | 3 +++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index e135a275a..f8c9683fa 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4494,13 +4494,13 @@ jsonValueObject members:vector = JsonValue; //@description The story can be viewed by everyone storyPrivacySettingsEveryone = StoryPrivacySettings; -//@description The story can be viewed by all contacts except chosen users @except_user_ids User identifiers of the contacts that can't see the story +//@description The story can be viewed by all contacts except chosen users @except_user_ids User identifiers of the contacts that can't see the story; always empty for non-owned stories storyPrivacySettingsContacts except_user_ids:vector = StoryPrivacySettings; //@description The story can be viewed by all close friends storyPrivacySettingsCloseFriends = StoryPrivacySettings; -//@description The story can be viewed by certain specified users @user_ids Identifiers of the users +//@description The story can be viewed by certain specified users @user_ids Identifiers of the users; always empty for non-owned stories storyPrivacySettingsSelectedContacts user_ids:vector = StoryPrivacySettings; @@ -4968,7 +4968,7 @@ storyInteractionInfo view_count:int32 recent_viewer_user_ids:vector = Sto //@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 -//@privacy_settings Privacy rules affecting story visibility; may be null if the story isn't owned +//@privacy_settings Privacy rules affecting story visibility; may be approximate for non-owned stories //@content Content of the story //@caption Caption of the story story id:int32 sender_chat_id:int53 date:int32 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 privacy_settings:StoryPrivacySettings content:StoryContent caption:formattedText = Story; diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 587775070..b3e1763b5 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -744,6 +744,8 @@ void StoryManager::Story::store(StorerT &storer) const { STORE_FLAG(has_privacy_rules); STORE_FLAG(has_content); STORE_FLAG(has_caption); + STORE_FLAG(is_for_contacts_); + STORE_FLAG(is_for_selected_contacts_); END_STORE_FLAGS(); store(date_, storer); store(expire_date_, storer); @@ -783,6 +785,8 @@ void StoryManager::Story::parse(ParserT &parser) { PARSE_FLAG(has_privacy_rules); PARSE_FLAG(has_content); PARSE_FLAG(has_caption); + PARSE_FLAG(is_for_contacts_); + PARSE_FLAG(is_for_selected_contacts_); END_PARSE_FLAGS(); parse(date_, parser); parse(expire_date_, parser); @@ -2278,8 +2282,15 @@ td_api::object_ptr StoryManager::get_story_object(StoryFullId sto privacy_settings = td_api::make_object(); } else if (story->is_for_close_friends_) { privacy_settings = td_api::make_object(); - } else if (is_owned) { + } else { privacy_settings = story->privacy_rules_.get_story_privacy_settings_object(td_); + if (privacy_settings == nullptr) { + if (story->is_for_contacts_) { + privacy_settings = td_api::make_object(); + } else { + privacy_settings = td_api::make_object(); + } + } } bool is_being_edited = false; @@ -2494,12 +2505,16 @@ StoryId StoryManager::on_get_new_story(DialogId owner_dialog_id, if (story->is_edited_ != story_item->edited_ || story->is_pinned_ != story_item->pinned_ || story->is_public_ != story_item->public_ || story->is_for_close_friends_ != story_item->close_friends_ || + story->is_for_contacts_ != story_item->contacts_ || + story->is_for_selected_contacts_ != story_item->selected_contacts_ || story->noforwards_ != story_item->noforwards_ || story->date_ != story_item->date_ || story->expire_date_ != story_item->expire_date_) { story->is_edited_ = story_item->edited_; story->is_pinned_ = story_item->pinned_; story->is_public_ = story_item->public_; story->is_for_close_friends_ = story_item->close_friends_; + story->is_for_contacts_ = story_item->contacts_; + story->is_for_selected_contacts_ = story_item->selected_contacts_; story->noforwards_ = story_item->noforwards_; story->date_ = story_item->date_; story->expire_date_ = story_item->expire_date_; diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 6aff86696..79cb9ef3c 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -58,6 +58,8 @@ class StoryManager final : public Actor { bool is_pinned_ = false; bool is_public_ = false; bool is_for_close_friends_ = false; + bool is_for_contacts_ = false; + bool is_for_selected_contacts_ = false; bool noforwards_ = false; mutable bool is_update_sent_ = false; // whether the story is known to the app StoryInteractionInfo interaction_info_; diff --git a/td/telegram/UserPrivacySettingRule.cpp b/td/telegram/UserPrivacySettingRule.cpp index b11efcdb4..a46f174fc 100644 --- a/td/telegram/UserPrivacySettingRule.cpp +++ b/td/telegram/UserPrivacySettingRule.cpp @@ -331,6 +331,9 @@ td_api::object_ptr UserPrivacySettingRules::get td_api::object_ptr UserPrivacySettingRules::get_story_privacy_settings_object( Td *td) const { + if (rules_.empty()) { + return nullptr; + } if (rules_.size() == 1u && rules_[0].type_ == UserPrivacySettingRule::Type::AllowAll) { return td_api::make_object(); }