Repair last Saved Messages topic message by fetching history.

This commit is contained in:
levlam 2024-02-05 10:20:35 +03:00
parent db500ffae5
commit 741b0fc6af

View File

@ -336,13 +336,11 @@ void SavedMessagesManager::set_topic_last_message_id(SavedMessagesTopicId saved_
}
void SavedMessagesManager::do_set_topic_last_message_id(SavedMessagesTopic *topic, MessageId last_message_id) {
CHECK(last_message_id.is_valid());
CHECK(last_message_id.is_server());
if (topic->last_message_id_ == last_message_id) {
return;
}
CHECK(last_message_id == MessageId() || last_message_id.is_valid());
topic->last_message_id_ = last_message_id;
topic->is_changed_ = true;
}
@ -354,10 +352,11 @@ void SavedMessagesManager::on_topic_message_deleted(SavedMessagesTopicId saved_m
return;
}
topic->last_message_id_ = MessageId();
topic->is_changed_ = true;
do_set_topic_last_message_id(topic, MessageId());
on_topic_changed(saved_messages_topic_id, topic);
get_saved_messages_topic_history(saved_messages_topic_id, MessageId(), 0, 1, Auto());
}
void SavedMessagesManager::on_topic_changed(SavedMessagesTopicId saved_messages_topic_id, SavedMessagesTopic *topic) {
@ -591,19 +590,35 @@ void SavedMessagesManager::on_get_saved_messages_topic_history(
auto my_dialog_id = td_->dialog_manager_->get_my_dialog_id();
vector<td_api::object_ptr<td_api::message>> messages;
MessageId last_message_id;
for (auto &message : info.messages) {
auto full_message_id = td_->messages_manager_->on_get_message(std::move(message), false, false, false,
"on_get_saved_messages_topic_history");
auto dialog_id = full_message_id.get_dialog_id();
if (dialog_id != my_dialog_id) {
if (dialog_id != DialogId()) {
LOG(ERROR) << "Receive " << full_message_id << " in history of " << saved_messages_topic_id;
}
if (dialog_id == DialogId()) {
continue;
}
if (dialog_id != my_dialog_id) {
LOG(ERROR) << "Receive " << full_message_id << " in history of " << saved_messages_topic_id;
continue;
}
if (!last_message_id.is_valid()) {
last_message_id = full_message_id.get_message_id();
}
messages.push_back(
td_->messages_manager_->get_message_object(full_message_id, "on_get_saved_messages_topic_history"));
}
if (from_message_id == MessageId::max()) {
auto *topic = add_topic(saved_messages_topic_id);
if (info.messages.empty()) {
do_set_topic_last_message_id(topic, MessageId());
} else {
if (last_message_id.is_valid() && topic->last_message_id_ == MessageId()) {
do_set_topic_last_message_id(topic, last_message_id);
}
}
on_topic_changed(saved_messages_topic_id, topic);
}
promise.set_value(td_api::make_object<td_api::messages>(info.total_count, std::move(messages)));
}