Make story.privacy_settings always non-null.

This commit is contained in:
levlam 2023-07-18 16:19:11 +03:00
parent fc97956447
commit a553447ac2
4 changed files with 24 additions and 4 deletions

View File

@ -4494,13 +4494,13 @@ jsonValueObject members:vector<jsonObjectMember> = 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<int53> = 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<int53> = StoryPrivacySettings;
@ -4968,7 +4968,7 @@ storyInteractionInfo view_count:int32 recent_viewer_user_ids:vector<int53> = 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;

View File

@ -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<td_api::story> StoryManager::get_story_object(StoryFullId sto
privacy_settings = td_api::make_object<td_api::storyPrivacySettingsEveryone>();
} else if (story->is_for_close_friends_) {
privacy_settings = td_api::make_object<td_api::storyPrivacySettingsCloseFriends>();
} 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<td_api::storyPrivacySettingsContacts>();
} else {
privacy_settings = td_api::make_object<td_api::storyPrivacySettingsSelectedContacts>();
}
}
}
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_;

View File

@ -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_;

View File

@ -331,6 +331,9 @@ td_api::object_ptr<td_api::userPrivacySettingRules> UserPrivacySettingRules::get
td_api::object_ptr<td_api::StoryPrivacySettings> 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<td_api::storyPrivacySettingsEveryone>();
}