From 238c282368751407a8151145a4ae28d879f95691 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 7 Feb 2024 20:03:46 +0300 Subject: [PATCH] Update server_total_count when topic list changes. --- td/telegram/SavedMessagesManager.cpp | 36 ++++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/td/telegram/SavedMessagesManager.cpp b/td/telegram/SavedMessagesManager.cpp index 56e6f4e0c..5b2035fcc 100644 --- a/td/telegram/SavedMessagesManager.cpp +++ b/td/telegram/SavedMessagesManager.cpp @@ -447,27 +447,37 @@ void SavedMessagesManager::on_topic_changed(SavedMessagesTopic *topic, const cha } topic->is_changed_ = false; - if (topic->private_order_ != 0) { - bool is_deleted = topic_list_.ordered_topics_.erase({topic->private_order_, topic->saved_messages_topic_id_}) > 0; - CHECK(is_deleted); - } + int64 new_private_order; if (topic->pinned_order_ != 0) { - topic->private_order_ = topic->pinned_order_; + new_private_order = topic->pinned_order_; } else if (topic->last_message_id_ != MessageId()) { - topic->private_order_ = get_topic_order(topic->last_message_date_, topic->last_message_id_); + new_private_order = get_topic_order(topic->last_message_date_, topic->last_message_id_); } else { - topic->private_order_ = 0; + new_private_order = 0; } if (topic->draft_message_date_ != 0) { int64 draft_order = get_topic_order(topic->draft_message_date_, MessageId()); - if (topic->private_order_ < draft_order) { - topic->private_order_ = draft_order; + if (new_private_order < draft_order) { + new_private_order = draft_order; } } - if (topic->private_order_ != 0) { - bool is_inserted = - topic_list_.ordered_topics_.insert({topic->private_order_, topic->saved_messages_topic_id_}).second; - CHECK(is_inserted); + if (topic->private_order_ != new_private_order) { + if (topic->private_order_ != 0) { + bool is_deleted = topic_list_.ordered_topics_.erase({topic->private_order_, topic->saved_messages_topic_id_}) > 0; + CHECK(is_deleted); + if (topic_list_.server_total_count_ > 0) { + topic_list_.server_total_count_--; + } + } + topic->private_order_ = new_private_order; + if (topic->private_order_ != 0) { + bool is_inserted = + topic_list_.ordered_topics_.insert({topic->private_order_, topic->saved_messages_topic_id_}).second; + CHECK(is_inserted); + if (topic_list_.server_total_count_ >= 0) { + topic_list_.server_total_count_++; + } + } } LOG(INFO) << "Update order of " << topic->saved_messages_topic_id_ << " to " << topic->private_order_ << " from " << source;