From 88eadb56fba26bef1cf77832a092a7f989577135 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 30 Jun 2023 17:12:19 +0300 Subject: [PATCH] Maintain ordered lists of all stories. --- td/telegram/StoryManager.cpp | 31 ++++++++++++++++++++++++++++++- td/telegram/StoryManager.h | 2 ++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index b00243d08..a91febafc 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -1800,6 +1800,16 @@ StoryId StoryManager::on_get_new_story(DialogId owner_dialog_id, change_story_files(story_full_id, story, old_file_ids); } + if (story_item->date_ <= 0) { + LOG(ERROR) << "Receive " << story_full_id << " sent at " << story_item->date_; + story_item->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->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->noforwards_ != story_item->noforwards_ || story->date_ != story_item->date_ || @@ -1884,6 +1894,17 @@ StoryId StoryManager::on_get_skipped_story(DialogId owner_dialog_id, inaccessible_story_full_ids_.erase(story_full_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_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->date_ != story_item->date_ || story->expire_date_ != story_item->expire_date_) { story->date_ = story_item->date_; story->expire_date_ = story_item->expire_date_; @@ -2160,13 +2181,20 @@ bool StoryManager::update_active_stories_order(DialogId owner_dialog_id, ActiveS if (owner_dialog_id == DialogId(td_->contacts_manager_->get_my_id())) { new_private_order += static_cast(1) << 36; } + CHECK(new_private_order != 0); int64 new_public_order = 0; if (is_subscribed_to_dialog_stories(owner_dialog_id)) { - const auto &story_list = story_lists_[are_dialog_stories_hidden(owner_dialog_id)]; + auto &story_list = story_lists_[are_dialog_stories_hidden(owner_dialog_id)]; if (DialogDate(active_stories->private_order_, owner_dialog_id) <= story_list.list_last_story_date_) { new_public_order = active_stories->private_order_; } + + if (active_stories->private_order_ != new_private_order) { + story_list.ordered_stories_.erase({active_stories->private_order_, owner_dialog_id}); + bool is_inserted = story_list.ordered_stories_.insert({new_private_order, owner_dialog_id}).second; + CHECK(is_inserted); + } } if (active_stories->private_order_ != new_private_order || active_stories->public_order_ != new_public_order) { @@ -2178,6 +2206,7 @@ bool StoryManager::update_active_stories_order(DialogId owner_dialog_id, ActiveS return true; } } + return false; } diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index 7353c0bc4..72b9d0ddb 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -101,6 +101,8 @@ class StoryManager final : public Actor { vector> load_list_queries_; + std::set ordered_stories_; // all known active stories from the story list + DialogDate list_last_story_date_ = MIN_DIALOG_DATE; // in memory };