Improve deletion of deleted being sent messages.

This commit is contained in:
levlam 2021-04-04 22:59:56 +03:00
parent d44e9e5577
commit 0b53ace8d0
2 changed files with 23 additions and 15 deletions

View File

@ -10458,13 +10458,25 @@ void MessagesManager::delete_messages(DialogId dialog_id, const vector<MessageId
} }
} }
void MessagesManager::delete_message_from_server(DialogId dialog_id, MessageId message_id, bool revoke) { void MessagesManager::delete_sent_message_from_server(DialogId dialog_id, MessageId message_id) {
if (message_id.is_valid()) { // being sent message was deleted by the user or is in an inaccessible channel
CHECK(message_id.is_server()); // don't need to send an update to the user, because the message has already been deleted
delete_messages_from_server(dialog_id, {message_id}, revoke, 0, Auto()); if (!have_input_peer(dialog_id, AccessRights::Read)) {
LOG(INFO) << "Ignore sent " << message_id << " in inaccessible " << dialog_id;
return;
}
LOG(INFO) << "Delete already deleted sent " << message_id << " in " << dialog_id << " from server";
if (have_message_force({dialog_id, message_id}, "delete_sent_message_from_server")) {
delete_messages(dialog_id, {message_id}, true, Auto());
} else { } else {
CHECK(message_id.is_scheduled_server()); if (message_id.is_valid()) {
delete_scheduled_messages_from_server(dialog_id, {message_id}, 0, Auto()); CHECK(message_id.is_server());
delete_messages_from_server(dialog_id, {message_id}, true, 0, Auto());
} else {
CHECK(message_id.is_scheduled_server());
delete_scheduled_messages_from_server(dialog_id, {message_id}, 0, Auto());
}
} }
} }
@ -13683,10 +13695,7 @@ FullMessageId MessagesManager::on_get_message(MessageInfo &&message_info, bool f
unique_ptr<Message> old_message = unique_ptr<Message> old_message =
delete_message(d, old_message_id, false, &need_update_dialog_pos, "add sent message"); delete_message(d, old_message_id, false, &need_update_dialog_pos, "add sent message");
if (old_message == nullptr) { if (old_message == nullptr) {
// message has already been deleted by the user or sent to inaccessible channel delete_sent_message_from_server(dialog_id, new_message->message_id);
// don't need to send update to the user, because the message has already been deleted
LOG(INFO) << "Delete already deleted sent " << new_message->message_id << " from server";
delete_message_from_server(dialog_id, new_message->message_id, true);
being_readded_message_id_ = FullMessageId(); being_readded_message_id_ = FullMessageId();
return FullMessageId(); return FullMessageId();
} }
@ -26961,6 +26970,7 @@ bool MessagesManager::on_update_message_id(int64 random_id, MessageId new_messag
being_sent_messages_.erase(it); being_sent_messages_.erase(it);
LOG(INFO) << "Save correspondence from " << new_message_id << " in " << dialog_id << " to " << old_message_id; LOG(INFO) << "Save correspondence from " << new_message_id << " in " << dialog_id << " to " << old_message_id;
CHECK(old_message_id.is_yet_unsent());
update_message_ids_[FullMessageId(dialog_id, new_message_id)] = old_message_id; update_message_ids_[FullMessageId(dialog_id, new_message_id)] = old_message_id;
return true; return true;
} }
@ -26985,6 +26995,7 @@ bool MessagesManager::on_update_scheduled_message_id(int64 random_id, ScheduledS
being_sent_messages_.erase(it); being_sent_messages_.erase(it);
LOG(INFO) << "Save correspondence from " << new_message_id << " in " << dialog_id << " to " << old_message_id; LOG(INFO) << "Save correspondence from " << new_message_id << " in " << dialog_id << " to " << old_message_id;
CHECK(old_message_id.is_yet_unsent());
update_scheduled_message_ids_[dialog_id][new_message_id] = old_message_id; update_scheduled_message_ids_[dialog_id][new_message_id] = old_message_id;
return true; return true;
} }
@ -28771,10 +28782,7 @@ FullMessageId MessagesManager::on_send_message_success(int64 random_id, MessageI
being_readded_message_id_ = {dialog_id, old_message_id}; being_readded_message_id_ = {dialog_id, old_message_id};
unique_ptr<Message> sent_message = delete_message(d, old_message_id, false, &need_update_dialog_pos, source); unique_ptr<Message> sent_message = delete_message(d, old_message_id, false, &need_update_dialog_pos, source);
if (sent_message == nullptr) { if (sent_message == nullptr) {
// message has already been deleted by the user or sent to inaccessible channel delete_sent_message_from_server(dialog_id, new_message_id);
// don't need to send update to the user, because the message has already been deleted
LOG(INFO) << "Delete already deleted sent " << new_message_id << " from server";
delete_message_from_server(dialog_id, new_message_id, true);
being_readded_message_id_ = FullMessageId(); being_readded_message_id_ = FullMessageId();
return {}; return {};
} }

View File

@ -1906,7 +1906,7 @@ class MessagesManager : public Actor {
void do_delete_all_dialog_messages(Dialog *d, unique_ptr<Message> &message, bool is_permanently_deleted, void do_delete_all_dialog_messages(Dialog *d, unique_ptr<Message> &message, bool is_permanently_deleted,
vector<int64> &deleted_message_ids); vector<int64> &deleted_message_ids);
void delete_message_from_server(DialogId dialog_id, MessageId message_ids, bool revoke); void delete_sent_message_from_server(DialogId dialog_id, MessageId message_id);
void delete_messages_from_server(DialogId dialog_id, vector<MessageId> message_ids, bool revoke, uint64 log_event_id, void delete_messages_from_server(DialogId dialog_id, vector<MessageId> message_ids, bool revoke, uint64 log_event_id,
Promise<Unit> &&promise); Promise<Unit> &&promise);