Fix order of updates applying in secret chats.

GitOrigin-RevId: 3cf1c152c4faf21bc3d1f6cb58fcbce6417623ef
This commit is contained in:
levlam 2019-09-04 21:29:27 +03:00
parent 4d827dbc78
commit 331a48a898
2 changed files with 68 additions and 9 deletions

View File

@ -9485,15 +9485,32 @@ void MessagesManager::on_send_secret_message_success(int64 random_id, MessageId
void MessagesManager::delete_secret_messages(SecretChatId secret_chat_id, std::vector<int64> random_ids,
Promise<> promise) {
LOG(INFO) << "Delete messages with random_ids " << random_ids << " in " << secret_chat_id;
promise.set_value(Unit()); // TODO: set after event is saved
LOG(DEBUG) << "On delete messages in " << secret_chat_id << " with random_ids " << random_ids;
CHECK(secret_chat_id.is_valid());
DialogId dialog_id(secret_chat_id);
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
if (!have_dialog_force(dialog_id)) {
LOG(ERROR) << "Ignore delete secret messages in unknown " << dialog_id;
promise.set_value(Unit());
return;
}
auto pending_secret_message = make_unique<PendingSecretMessage>();
pending_secret_message->success_promise = std::move(promise);
pending_secret_message->type = PendingSecretMessage::Type::DeleteMessages;
pending_secret_message->dialog_id = dialog_id;
pending_secret_message->random_ids = std::move(random_ids);
add_secret_message(std::move(pending_secret_message));
}
void MessagesManager::finish_delete_secret_messages(DialogId dialog_id, std::vector<int64> random_ids,
Promise<> promise) {
LOG(INFO) << "Delete messages with random_ids " << random_ids << " in " << dialog_id;
promise.set_value(Unit()); // TODO: set after event is saved
Dialog *d = get_dialog(dialog_id);
CHECK(d != nullptr);
vector<MessageId> to_delete_message_ids;
for (auto &random_id : random_ids) {
auto message_id = get_message_id_by_random_id(d, random_id, "delete_secret_messages");
@ -9514,14 +9531,32 @@ void MessagesManager::delete_secret_messages(SecretChatId secret_chat_id, std::v
void MessagesManager::delete_secret_chat_history(SecretChatId secret_chat_id, MessageId last_message_id,
Promise<> promise) {
promise.set_value(Unit()); // TODO: set after event is saved
auto dialog_id = DialogId(secret_chat_id);
Dialog *d = get_dialog_force(dialog_id);
if (d == nullptr) {
LOG(ERROR) << "Ignore delete secret chat history in unknown " << dialog_id;
LOG(DEBUG) << "On delete history in " << secret_chat_id << " up to " << last_message_id;
CHECK(secret_chat_id.is_valid());
DialogId dialog_id(secret_chat_id);
if (!have_dialog_force(dialog_id)) {
LOG(ERROR) << "Ignore delete history in unknown " << dialog_id;
promise.set_value(Unit());
return;
}
auto pending_secret_message = make_unique<PendingSecretMessage>();
pending_secret_message->success_promise = std::move(promise);
pending_secret_message->type = PendingSecretMessage::Type::DeleteHistory;
pending_secret_message->dialog_id = dialog_id;
pending_secret_message->last_message_id = last_message_id;
add_secret_message(std::move(pending_secret_message));
}
void MessagesManager::finish_delete_secret_chat_history(DialogId dialog_id, MessageId last_message_id,
Promise<> promise) {
LOG(DEBUG) << "Delete history in " << dialog_id << " up to " << last_message_id;
promise.set_value(Unit()); // TODO: set after event is saved
Dialog *d = get_dialog(dialog_id);
CHECK(d != nullptr);
// TODO: probably last_message_id is not needed
delete_all_dialog_messages(d, false, true);
}
@ -9775,6 +9810,16 @@ void MessagesManager::finish_add_secret_message(unique_ptr<PendingSecretMessage>
return;
}
if (pending_secret_message->type == PendingSecretMessage::Type::DeleteMessages) {
return finish_delete_secret_messages(pending_secret_message->dialog_id,
std::move(pending_secret_message->random_ids),
std::move(pending_secret_message->success_promise));
}
if (pending_secret_message->type == PendingSecretMessage::Type::DeleteHistory) {
return finish_delete_secret_chat_history(pending_secret_message->dialog_id, pending_secret_message->last_message_id,
std::move(pending_secret_message->success_promise));
}
auto d = get_dialog(pending_secret_message->message_info.dialog_id);
CHECK(d != nullptr);
auto random_id = pending_secret_message->message_info.random_id;

View File

@ -1244,8 +1244,18 @@ class MessagesManager : public Actor {
};
struct PendingSecretMessage {
enum class Type { NewMessage, DeleteMessages, DeleteHistory };
Type type = Type::NewMessage;
// for NewMessage
MessageInfo message_info;
MultiPromiseActor load_data_multipromise{"LoadPendingSecretMessageDataMultiPromiseActor"};
// for DeleteMessages/DeleteHistory
DialogId dialog_id;
vector<int64> random_ids;
MessageId last_message_id;
Promise<> success_promise;
};
@ -1337,6 +1347,10 @@ class MessagesManager : public Actor {
void finish_add_secret_message(unique_ptr<PendingSecretMessage> pending_secret_message);
void finish_delete_secret_messages(DialogId dialog_id, std::vector<int64> random_ids, Promise<> promise);
void finish_delete_secret_chat_history(DialogId dialog_id, MessageId last_message_id, Promise<> promise);
void fix_message_info_dialog_id(MessageInfo &message_info) const;
MessageInfo parse_telegram_api_message(tl_object_ptr<telegram_api::Message> message_ptr, const char *source) const;