From 32a867ed8f16ecd0d80c58d5265bd6cfc9e0683d Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 15 Jul 2023 02:46:50 +0300 Subject: [PATCH] Add StoryManager::on_get_story_info. --- td/telegram/StoryManager.cpp | 39 ++++++++++++++++++++++-------------- td/telegram/StoryManager.h | 2 ++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 6145a70a7..b2a28ec47 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -2337,9 +2337,18 @@ StoryId StoryManager::on_get_new_story(DialogId owner_dialog_id, StoryId StoryManager::on_get_skipped_story(DialogId owner_dialog_id, telegram_api::object_ptr &&story_item) { CHECK(story_item != nullptr); - StoryId story_id(story_item->id_); + StoryInfo story_info; + story_info.story_id_ = StoryId(story_item->id_); + story_info.date_ = story_item->date_; + story_info.expire_date_ = story_item->expire_date_; + story_info.is_for_close_friends_ = story_item->close_friends_; + return on_get_story_info(owner_dialog_id, std::move(story_info)); +} + +StoryId StoryManager::on_get_story_info(DialogId owner_dialog_id, StoryInfo &&story_info) { + StoryId story_id = story_info.story_id_; if (!story_id.is_server()) { - LOG(ERROR) << "Receive " << to_string(story_item); + LOG(ERROR) << "Receive " << story_id; return StoryId(); } if (deleted_story_full_ids_.count({owner_dialog_id, story_id}) > 0) { @@ -2349,7 +2358,7 @@ StoryId StoryManager::on_get_skipped_story(DialogId owner_dialog_id, td_->messages_manager_->force_create_dialog(owner_dialog_id, "on_get_skipped_story"); StoryFullId story_full_id{owner_dialog_id, story_id}; - Story *story = get_story_force(story_full_id, "on_get_skipped_story"); + Story *story = get_story_editable(story_full_id); if (story == nullptr) { auto s = make_unique(); story = s.get(); @@ -2360,21 +2369,21 @@ StoryId StoryManager::on_get_skipped_story(DialogId owner_dialog_id, } CHECK(story != nullptr); - if (story_item->date_ <= 0) { - LOG(ERROR) << "Receive " << story_full_id << " sent at " << story_item->date_; - story_item->date_ = 1; + if (story_info.date_ <= 0) { + LOG(ERROR) << "Receive " << story_full_id << " sent at " << story_info.date_; + story_info.date_ = 1; } - if (story_item->expire_date_ <= story_item->date_) { - LOG(ERROR) << "Receive " << story_full_id << " sent at " << story_item->date_ << ", but expired at " - << story_item->expire_date_; - story_item->expire_date_ = story_item->date_ + 1; + if (story_info.expire_date_ <= story_info.date_) { + LOG(ERROR) << "Receive " << story_full_id << " sent at " << story_info.date_ << ", but expired at " + << story_info.expire_date_; + story_info.expire_date_ = story_info.date_ + 1; } - if (story->date_ != story_item->date_ || story->expire_date_ != story_item->expire_date_ || - story->is_for_close_friends_ != story_item->close_friends_) { - story->date_ = story_item->date_; - story->expire_date_ = story_item->expire_date_; - story->is_for_close_friends_ = story_item->close_friends_; + if (story->date_ != story_info.date_ || story->expire_date_ != story_info.expire_date_ || + story->is_for_close_friends_ != story_info.is_for_close_friends_) { + story->date_ = story_info.date_; + story->expire_date_ = story_info.expire_date_; + story->is_for_close_friends_ = story_info.is_for_close_friends_; on_story_changed(story_full_id, story, true, true); } return story_id; diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index d3f7850f7..1662aed23 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -343,6 +343,8 @@ class StoryManager final : public Actor { void unregister_story_global_id(const Story *story); + StoryId on_get_story_info(DialogId owner_dialog_id, StoryInfo &&story_info); + StoryInfo get_story_info(StoryFullId story_full_id) const; td_api::object_ptr get_story_info_object(StoryFullId story_full_id) const;