SecretChatActor: try to answer on send_message with duplicated random_id

GitOrigin-RevId: b06b94b9b3e2bd0fb74cec78fa142f18a4af3c69
This commit is contained in:
Arseny Smirnov 2018-01-31 18:14:43 +03:00 committed by levlam
parent 533990288b
commit 9d9957d53e
2 changed files with 31 additions and 4 deletions

View File

@ -1535,8 +1535,11 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise
if (state->message->is_external) { if (state->message->is_external) {
LOG(INFO) << "Outbound secret message [send_message] failed, rewrite it with dummy " LOG(INFO) << "Outbound secret message [send_message] failed, rewrite it with dummy "
<< tag("logevent_id", state->message->logevent_id()) << tag("error", error); << tag("logevent_id", state->message->logevent_id()) << tag("error", error);
context_->on_send_message_error(state->message->random_id, std::move(error), state->send_result_ = [this, random_id = state->message->random_id, error_code = error.code(),
std::move(send_message_error_promise)); error_message = error.message()](Promise<> promise) {
this->context_->on_send_message_error(random_id, Status::Error(error_code, error_message), std::move(promise));
};
state->send_result_(std::move(send_message_error_promise));
} else { } else {
// Just resend. // Just resend.
LOG(INFO) << "Outbound secret message [send_message] failed, resend it " LOG(INFO) << "Outbound secret message [send_message] failed, resend it "
@ -1563,24 +1566,43 @@ void SecretChatActor::on_outbound_send_message_result(NetQueryPtr query, Promise
switch (result->get_id()) { switch (result->get_id()) {
case telegram_api::messages_sentEncryptedMessage::ID: { case telegram_api::messages_sentEncryptedMessage::ID: {
auto sent = move_tl_object_as<telegram_api::messages_sentEncryptedMessage>(result); auto sent = move_tl_object_as<telegram_api::messages_sentEncryptedMessage>(result);
context_->on_send_message_ok(state->message->random_id, MessageId(ServerMessageId(state->message->message_id)), state->send_result_ = [this, random_id = state->message->random_id,
sent->date_, nullptr, std::move(send_message_finish_promise)); message_id = MessageId(ServerMessageId(state->message->message_id)),
date = sent->date_](Promise<> promise) {
this->context_->on_send_message_ok(random_id, message_id, date, nullptr, std::move(promise));
};
state->send_result_(std::move(send_message_finish_promise));
return; return;
} }
case telegram_api::messages_sentEncryptedFile::ID: { case telegram_api::messages_sentEncryptedFile::ID: {
auto sent = move_tl_object_as<telegram_api::messages_sentEncryptedFile>(result); auto sent = move_tl_object_as<telegram_api::messages_sentEncryptedFile>(result);
std::function<telegram_api::object_ptr<telegram_api::EncryptedFile>()> get_file;
telegram_api::downcast_call( telegram_api::downcast_call(
*sent->file_, overloaded( *sent->file_, overloaded(
[&](telegram_api::encryptedFileEmpty &) { [&](telegram_api::encryptedFileEmpty &) {
state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file( state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file(
telegram_api::inputEncryptedFileEmpty()); telegram_api::inputEncryptedFileEmpty());
get_file = [] { return telegram_api::make_object<telegram_api::encryptedFileEmpty>(); };
}, },
[&](telegram_api::encryptedFile &file) { [&](telegram_api::encryptedFile &file) {
state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file( state->message->file = logevent::EncryptedInputFile::from_input_encrypted_file(
telegram_api::inputEncryptedFile(file.id_, file.access_hash_)); telegram_api::inputEncryptedFile(file.id_, file.access_hash_));
get_file = [id = file.id_, access_hash = file.access_hash_, size = file.size_,
dc_id = file.dc_id_, key_fingerprint = file.key_fingerprint_] {
return telegram_api::make_object<telegram_api::encryptedFile>(id, access_hash, size,
dc_id, key_fingerprint);
};
})); }));
context_->on_send_message_ok(state->message->random_id, MessageId(ServerMessageId(state->message->message_id)), context_->on_send_message_ok(state->message->random_id, MessageId(ServerMessageId(state->message->message_id)),
sent->date_, std::move(sent->file_), std::move(send_message_finish_promise)); sent->date_, std::move(sent->file_), std::move(send_message_finish_promise));
state->send_result_ = [this, random_id = state->message->random_id,
message_id = MessageId(ServerMessageId(state->message->message_id)), date = sent->date_,
get_file = std::move(get_file)](Promise<> promise) {
this->context_->on_send_message_ok(random_id, message_id, date, get_file(), std::move(promise));
};
state->send_result_(std::move(send_message_finish_promise));
return;
return; return;
} }
} }
@ -1686,6 +1708,9 @@ void SecretChatActor::on_outbound_outer_send_message_promise(uint64 state_id, Pr
CHECK(state); CHECK(state);
LOG(INFO) << "Outbound secret message [TODO] " << tag("logevent_id", state->message->logevent_id()); LOG(INFO) << "Outbound secret message [TODO] " << tag("logevent_id", state->message->logevent_id());
promise.set_value(Unit()); // Seems like this message is at least stored to binlog already promise.set_value(Unit()); // Seems like this message is at least stored to binlog already
if (state->send_result_) {
state->send_result_({});
}
} }
void SecretChatActor::outbound_loop(OutboundMessageState *state, uint64 state_id) { void SecretChatActor::outbound_loop(OutboundMessageState *state, uint64 state_id) {

View File

@ -562,6 +562,8 @@ class SecretChatActor : public NetQueryCallback {
uint64 net_query_id = 0; uint64 net_query_id = 0;
NetQueryRef net_query_ref; NetQueryRef net_query_ref;
bool net_query_may_fail = false; bool net_query_may_fail = false;
std::function<void(Promise<>)> send_result_;
}; };
std::map<uint64, uint64> random_id_to_outbound_message_state_token_; std::map<uint64, uint64> random_id_to_outbound_message_state_token_;
std::map<int32, uint64> out_seq_no_to_outbound_message_state_token_; std::map<int32, uint64> out_seq_no_to_outbound_message_state_token_;