Add MessagesManager::on_message_deleted_from_database.

This commit is contained in:
levlam 2023-05-01 15:48:35 +03:00
parent 3c2e08633b
commit 730dac8dfe
2 changed files with 53 additions and 45 deletions

View File

@ -16498,51 +16498,7 @@ unique_ptr<MessagesManager::Message> MessagesManager::do_delete_message(Dialog *
Promise<Unit>());
}
if (d->reply_markup_message_id == message_id) {
set_dialog_reply_markup(d, MessageId());
}
// if last_read_inbox_message_id is not known, we can't be sure whether unread_count should be decreased or not
if (has_incoming_notification(d->dialog_id, result.get()) && message_id > d->last_read_inbox_message_id &&
d->is_last_read_inbox_message_id_inited && !td_->auth_manager_->is_bot()) {
int32 server_unread_count = d->server_unread_count;
int32 local_unread_count = d->local_unread_count;
int32 &unread_count = message_id.is_server() ? server_unread_count : local_unread_count;
if (unread_count == 0) {
if (need_unread_counter(d->order)) {
LOG(ERROR) << "Unread count became negative in " << d->dialog_id << " after deletion of " << message_id
<< ". Last read is " << d->last_read_inbox_message_id;
}
} else {
unread_count--;
set_dialog_last_read_inbox_message_id(d, MessageId::min(), server_unread_count, local_unread_count, false,
source);
}
}
if (result->contains_unread_mention) {
if (d->unread_mention_count == 0) {
if (is_dialog_inited(d)) {
LOG(ERROR) << "Unread mention count became negative in " << d->dialog_id << " after deletion of "
<< message_id;
}
} else {
set_dialog_unread_mention_count(d, d->unread_mention_count - 1);
send_update_chat_unread_mention_count(d);
}
}
if (has_unread_message_reactions(d->dialog_id, result.get())) {
if (d->unread_reaction_count == 0) {
if (is_dialog_inited(d)) {
LOG(ERROR) << "Unread reaction count became negative in " << d->dialog_id << " after deletion of "
<< message_id;
}
} else {
set_dialog_unread_reaction_count(d, d->unread_reaction_count - 1);
send_update_chat_unread_reaction_count(d, "do_delete_message");
}
}
update_message_count_by_index(d, -1, result.get());
update_reply_count_by_message(d, -1, result.get());
on_message_deleted_from_database(d, result.get(), source);
}
on_message_deleted(d, result.get(), is_permanently_deleted, source);
@ -16550,6 +16506,56 @@ unique_ptr<MessagesManager::Message> MessagesManager::do_delete_message(Dialog *
return result;
}
void MessagesManager::on_message_deleted_from_database(Dialog *d, const Message *m, const char *source) {
CHECK(d != nullptr);
CHECK(m != nullptr);
auto message_id = m->message_id;
if (d->reply_markup_message_id == message_id) {
set_dialog_reply_markup(d, MessageId());
}
// if last_read_inbox_message_id is not known, we can't be sure whether unread_count should be decreased or not
if (has_incoming_notification(d->dialog_id, m) && message_id > d->last_read_inbox_message_id &&
d->is_last_read_inbox_message_id_inited && !td_->auth_manager_->is_bot()) {
int32 server_unread_count = d->server_unread_count;
int32 local_unread_count = d->local_unread_count;
int32 &unread_count = message_id.is_server() ? server_unread_count : local_unread_count;
if (unread_count == 0) {
if (need_unread_counter(d->order)) {
LOG(ERROR) << "Unread count became negative in " << d->dialog_id << " after deletion of " << message_id
<< ". Last read is " << d->last_read_inbox_message_id;
}
} else {
unread_count--;
set_dialog_last_read_inbox_message_id(d, MessageId::min(), server_unread_count, local_unread_count, false,
source);
}
}
if (m->contains_unread_mention) {
if (d->unread_mention_count == 0) {
if (is_dialog_inited(d)) {
LOG(ERROR) << "Unread mention count became negative in " << d->dialog_id << " after deletion of " << message_id;
}
} else {
set_dialog_unread_mention_count(d, d->unread_mention_count - 1);
send_update_chat_unread_mention_count(d);
}
}
if (has_unread_message_reactions(d->dialog_id, m)) {
if (d->unread_reaction_count == 0) {
if (is_dialog_inited(d)) {
LOG(ERROR) << "Unread reaction count became negative in " << d->dialog_id << " after deletion of "
<< message_id;
}
} else {
set_dialog_unread_reaction_count(d, d->unread_reaction_count - 1);
send_update_chat_unread_reaction_count(d, source);
}
}
update_message_count_by_index(d, -1, m);
update_reply_count_by_message(d, -1, m);
}
void MessagesManager::on_message_deleted(Dialog *d, Message *m, bool is_permanently_deleted, const char *source) {
// also called for unloaded messages, but not for scheduled messages
CHECK(m->message_id.is_valid());

View File

@ -2138,6 +2138,8 @@ class MessagesManager final : public Actor {
unique_ptr<Message> do_delete_scheduled_message(Dialog *d, MessageId message_id, bool is_permanently_deleted,
const char *source);
void on_message_deleted_from_database(Dialog *d, const Message *m, const char *source);
void on_message_deleted(Dialog *d, Message *m, bool is_permanently_deleted, const char *source);
static bool is_deleted_message(const Dialog *d, MessageId message_id);