Store yet unsent message IDs separately for different threads.

GitOrigin-RevId: f68b88a1ea05dcb3096357328635191cae02edcb
This commit is contained in:
levlam 2020-09-28 16:08:35 +03:00
parent 1d9989cbd7
commit ab99fc7a8d
2 changed files with 18 additions and 0 deletions

View File

@ -14391,6 +14391,16 @@ unique_ptr<MessagesManager::Message> MessagesManager::do_delete_message(Dialog *
void MessagesManager::on_message_deleted(Dialog *d, Message *m, bool is_permanently_deleted, const char *source) {
// also called for unloaded messages
if (m->message_id.is_yet_unsent() && m->top_thread_message_id.is_valid()) {
auto it = d->yet_unsent_thread_message_ids.find(m->top_thread_message_id);
CHECK(it != d->yet_unsent_thread_message_ids.end());
auto is_deleted = it->second.erase(m->message_id) > 0;
CHECK(is_deleted);
if (it->second.empty()) {
d->yet_unsent_thread_message_ids.erase(it);
}
}
cancel_send_deleted_message(d->dialog_id, m, is_permanently_deleted);
CHECK(m->message_id.is_valid());
@ -30942,6 +30952,11 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq
}
}
if (m->message_id.is_yet_unsent() && m->top_thread_message_id.is_valid()) {
auto is_inserted = d->yet_unsent_thread_message_ids[m->top_thread_message_id].insert(m->message_id).second;
CHECK(is_inserted);
}
switch (dialog_id.get_type()) {
case DialogType::User:
case DialogType::Chat:

View File

@ -1250,6 +1250,9 @@ class MessagesManager : public Actor {
// application start, used to guarantee that all assigned message identifiers
// are different
std::unordered_map<MessageId, std::set<MessageId>, MessageIdHash>
yet_unsent_thread_message_ids; // top_thread_message_id -> yet unsent message IDs
std::unordered_map<ScheduledServerMessageId, int32, ScheduledServerMessageIdHash> scheduled_message_date;
std::unordered_map<MessageId, MessageId, MessageIdHash> yet_unsent_message_id_to_persistent_message_id;