Add more story_id checks.

This commit is contained in:
levlam 2024-02-13 13:41:05 +03:00
parent 0dc90cf820
commit e978e86c50
2 changed files with 15 additions and 5 deletions

View File

@ -8499,7 +8499,7 @@ closeStory story_sender_chat_id:int53 story_id:int32 = Ok;
//@description Returns reactions, which can be chosen for a story @row_size Number of reaction per row, 5-25 //@description Returns reactions, which can be chosen for a story @row_size Number of reaction per row, 5-25
getStoryAvailableReactions row_size:int32 = AvailableReactions; getStoryAvailableReactions row_size:int32 = AvailableReactions;
//@description Changes chosen reaction on a story //@description Changes chosen reaction on a story that has already been sent
//@story_sender_chat_id The identifier of the sender of the story //@story_sender_chat_id The identifier of the sender of the story
//@story_id The identifier of the story //@story_id The identifier of the story
//@reaction_type Type of the reaction to set; pass null to remove the reaction. `reactionTypeCustomEmoji` reactions can be used only by Telegram Premium users //@reaction_type Type of the reaction to set; pass null to remove the reaction. `reactionTypeCustomEmoji` reactions can be used only by Telegram Premium users

View File

@ -2765,7 +2765,9 @@ void StoryManager::update_interaction_info() {
auto story_full_id = it.first; auto story_full_id = it.first;
auto &story_ids = split_story_ids[story_full_id.get_dialog_id()]; auto &story_ids = split_story_ids[story_full_id.get_dialog_id()];
if (story_ids.size() < 100) { if (story_ids.size() < 100) {
story_ids.push_back(story_full_id.get_story_id()); auto story_id = story_full_id.get_story_id();
CHECK(story_id.is_server());
story_ids.push_back(story_id);
} }
} }
for (auto &story_ids : split_story_ids) { for (auto &story_ids : split_story_ids) {
@ -2779,8 +2781,10 @@ void StoryManager::increment_story_views(DialogId owner_dialog_id, PendingStoryV
const size_t MAX_VIEWED_STORIES = 200; // server-side limit const size_t MAX_VIEWED_STORIES = 200; // server-side limit
while (!story_views.story_ids_.empty() && viewed_story_ids.size() < MAX_VIEWED_STORIES) { while (!story_views.story_ids_.empty() && viewed_story_ids.size() < MAX_VIEWED_STORIES) {
auto story_id_it = story_views.story_ids_.begin(); auto story_id_it = story_views.story_ids_.begin();
viewed_story_ids.push_back(*story_id_it); auto story_id = *story_id_it;
story_views.story_ids_.erase(story_id_it); story_views.story_ids_.erase(story_id_it);
CHECK(story_id.is_server());
viewed_story_ids.push_back(story_id);
} }
CHECK(!viewed_story_ids.empty()); CHECK(!viewed_story_ids.empty());
story_views.has_query_ = true; story_views.has_query_ = true;
@ -2901,6 +2905,9 @@ void StoryManager::get_story_interactions(StoryId story_id, const string &query,
if (limit <= 0) { if (limit <= 0) {
return promise.set_error(Status::Error(400, "Parameter limit must be positive")); return promise.set_error(Status::Error(400, "Parameter limit must be positive"));
} }
if (!story_id.is_server()) {
return promise.set_value(td_api::make_object<td_api::storyInteractions>());
}
bool is_full = query.empty() && !only_contacts; bool is_full = query.empty() && !only_contacts;
bool is_first = is_full && offset.empty(); bool is_first = is_full && offset.empty();
@ -3002,6 +3009,9 @@ void StoryManager::get_dialog_story_interactions(StoryFullId story_full_id, Reac
if (limit <= 0) { if (limit <= 0) {
return promise.set_error(Status::Error(400, "Parameter limit must be positive")); return promise.set_error(Status::Error(400, "Parameter limit must be positive"));
} }
if (!story_full_id.get_story_id().is_server()) {
return promise.set_value(td_api::make_object<td_api::storyInteractions>());
}
auto query_promise = PromiseCreator::lambda( auto query_promise = PromiseCreator::lambda(
[actor_id = actor_id(this), story_full_id, promise = std::move(promise)]( [actor_id = actor_id(this), story_full_id, promise = std::move(promise)](
@ -3587,7 +3597,7 @@ StoryId StoryManager::on_get_story_info(DialogId owner_dialog_id, StoryInfo &&st
return StoryId(); return StoryId();
} }
td_->dialog_manager_->force_create_dialog(owner_dialog_id, "on_get_skipped_story"); td_->dialog_manager_->force_create_dialog(owner_dialog_id, "on_get_story_info");
StoryFullId story_full_id{owner_dialog_id, story_id}; StoryFullId story_full_id{owner_dialog_id, story_id};
Story *story = get_story_editable(story_full_id); Story *story = get_story_editable(story_full_id);
@ -4719,7 +4729,7 @@ void StoryManager::send_story(DialogId dialog_id, td_api::object_ptr<td_api::Inp
forward_from_story_full_id = forward_from_story_full_id =
StoryFullId(DialogId(from_story_full_id->sender_chat_id_), StoryId(from_story_full_id->story_id_)); StoryFullId(DialogId(from_story_full_id->sender_chat_id_), StoryId(from_story_full_id->story_id_));
const Story *story = get_story(forward_from_story_full_id); const Story *story = get_story(forward_from_story_full_id);
if (story == nullptr) { if (story == nullptr || story->content_ == nullptr) {
return promise.set_error(Status::Error(400, "Story to repost not found")); return promise.set_error(Status::Error(400, "Story to repost not found"));
} }
if (story->noforwards_) { if (story->noforwards_) {