Fix handling of errors in CallActor::send_call_signaling_data.

This commit is contained in:
levlam 2021-03-05 02:47:27 +03:00
parent 1c3290bada
commit 2b090918c2
2 changed files with 50 additions and 42 deletions

View File

@ -189,8 +189,8 @@ void CallActor::send_call_signaling_data(string &&data, Promise<> promise) {
auto query = G()->net_query_creator().create(
telegram_api::phone_sendSignalingData(get_input_phone_call("send_call_signaling_data"), BufferSlice(data)));
send_with_promise(std::move(query),
PromiseCreator::lambda([promise = std::move(promise)](NetQueryPtr net_query) mutable {
auto res = fetch_result<telegram_api::phone_sendSignalingData>(std::move(net_query));
PromiseCreator::lambda([promise = std::move(promise)](Result<NetQueryPtr> r_net_query) mutable {
auto res = fetch_result<telegram_api::phone_sendSignalingData>(std::move(r_net_query));
if (res.is_error()) {
promise.set_error(res.move_as_error());
} else {
@ -298,14 +298,15 @@ void CallActor::rate_call(int32 rating, string comment, vector<td_api::object_pt
auto tl_query = telegram_api::phone_setCallRating(0, false /*ignored*/, get_input_phone_call("rate_call"), rating,
std::move(comment));
auto query = G()->net_query_creator().create(tl_query);
send_with_promise(std::move(query), PromiseCreator::lambda([actor_id = actor_id(this)](NetQueryPtr net_query) {
send_closure(actor_id, &CallActor::on_set_rating_query_result, std::move(net_query));
send_with_promise(std::move(query),
PromiseCreator::lambda([actor_id = actor_id(this)](Result<NetQueryPtr> r_net_query) {
send_closure(actor_id, &CallActor::on_set_rating_query_result, std::move(r_net_query));
}));
loop();
}
void CallActor::on_set_rating_query_result(NetQueryPtr net_query) {
auto res = fetch_result<telegram_api::phone_setCallRating>(std::move(net_query));
void CallActor::on_set_rating_query_result(Result<NetQueryPtr> r_net_query) {
auto res = fetch_result<telegram_api::phone_setCallRating>(std::move(r_net_query));
if (res.is_error()) {
return on_error(res.move_as_error());
}
@ -321,14 +322,15 @@ void CallActor::send_call_debug_information(string data, Promise<> promise) {
auto tl_query = telegram_api::phone_saveCallDebug(get_input_phone_call("send_call_debug_information"),
make_tl_object<telegram_api::dataJSON>(std::move(data)));
auto query = G()->net_query_creator().create(tl_query);
send_with_promise(std::move(query), PromiseCreator::lambda([actor_id = actor_id(this)](NetQueryPtr net_query) {
send_closure(actor_id, &CallActor::on_set_debug_query_result, std::move(net_query));
send_with_promise(std::move(query),
PromiseCreator::lambda([actor_id = actor_id(this)](Result<NetQueryPtr> r_net_query) {
send_closure(actor_id, &CallActor::on_set_debug_query_result, std::move(r_net_query));
}));
loop();
}
void CallActor::on_set_debug_query_result(NetQueryPtr net_query) {
auto res = fetch_result<telegram_api::phone_saveCallDebug>(std::move(net_query));
void CallActor::on_set_debug_query_result(Result<NetQueryPtr> r_net_query) {
auto res = fetch_result<telegram_api::phone_saveCallDebug>(std::move(r_net_query));
if (res.is_error()) {
return on_error(res.move_as_error());
}
@ -603,13 +605,14 @@ void CallActor::do_load_dh_config(Promise<std::shared_ptr<DhConfig>> promise) {
void CallActor::send_received_query() {
auto tl_query = telegram_api::phone_receivedCall(get_input_phone_call("send_received_query"));
auto query = G()->net_query_creator().create(tl_query);
send_with_promise(std::move(query), PromiseCreator::lambda([actor_id = actor_id(this)](NetQueryPtr net_query) {
send_closure(actor_id, &CallActor::on_received_query_result, std::move(net_query));
send_with_promise(std::move(query),
PromiseCreator::lambda([actor_id = actor_id(this)](Result<NetQueryPtr> r_net_query) {
send_closure(actor_id, &CallActor::on_received_query_result, std::move(r_net_query));
}));
}
void CallActor::on_received_query_result(NetQueryPtr net_query) {
auto res = fetch_result<telegram_api::phone_receivedCall>(std::move(net_query));
void CallActor::on_received_query_result(Result<NetQueryPtr> r_net_query) {
auto res = fetch_result<telegram_api::phone_receivedCall>(std::move(r_net_query));
if (res.is_error()) {
return on_error(res.move_as_error());
}
@ -637,13 +640,14 @@ void CallActor::try_send_request_query() {
set_timeout_in(timeout);
query->total_timeout_limit_ = max(timeout, 10.0);
request_query_ref_ = query.get_weak();
send_with_promise(std::move(query), PromiseCreator::lambda([actor_id = actor_id(this)](NetQueryPtr net_query) {
send_closure(actor_id, &CallActor::on_request_query_result, std::move(net_query));
send_with_promise(std::move(query),
PromiseCreator::lambda([actor_id = actor_id(this)](Result<NetQueryPtr> r_net_query) {
send_closure(actor_id, &CallActor::on_request_query_result, std::move(r_net_query));
}));
}
void CallActor::on_request_query_result(NetQueryPtr net_query) {
auto res = fetch_result<telegram_api::phone_requestCall>(std::move(net_query));
void CallActor::on_request_query_result(Result<NetQueryPtr> r_net_query) {
auto res = fetch_result<telegram_api::phone_requestCall>(std::move(r_net_query));
if (res.is_error()) {
return on_error(res.move_as_error());
}
@ -666,13 +670,14 @@ void CallActor::try_send_accept_query() {
call_state_.protocol.get_input_phone_call_protocol());
auto query = G()->net_query_creator().create(tl_query);
state_ = State::WaitAcceptResult;
send_with_promise(std::move(query), PromiseCreator::lambda([actor_id = actor_id(this)](NetQueryPtr net_query) {
send_closure(actor_id, &CallActor::on_accept_query_result, std::move(net_query));
send_with_promise(std::move(query),
PromiseCreator::lambda([actor_id = actor_id(this)](Result<NetQueryPtr> r_net_query) {
send_closure(actor_id, &CallActor::on_accept_query_result, std::move(r_net_query));
}));
}
void CallActor::on_accept_query_result(NetQueryPtr net_query) {
auto res = fetch_result<telegram_api::phone_acceptCall>(std::move(net_query));
void CallActor::on_accept_query_result(Result<NetQueryPtr> r_net_query) {
auto res = fetch_result<telegram_api::phone_acceptCall>(std::move(r_net_query));
if (res.is_error()) {
return on_error(res.move_as_error());
}
@ -690,13 +695,14 @@ void CallActor::try_send_confirm_query() {
call_state_.protocol.get_input_phone_call_protocol());
auto query = G()->net_query_creator().create(tl_query);
state_ = State::WaitConfirmResult;
send_with_promise(std::move(query), PromiseCreator::lambda([actor_id = actor_id(this)](NetQueryPtr net_query) {
send_closure(actor_id, &CallActor::on_confirm_query_result, std::move(net_query));
send_with_promise(std::move(query),
PromiseCreator::lambda([actor_id = actor_id(this)](Result<NetQueryPtr> r_net_query) {
send_closure(actor_id, &CallActor::on_confirm_query_result, std::move(r_net_query));
}));
}
void CallActor::on_confirm_query_result(NetQueryPtr net_query) {
auto res = fetch_result<telegram_api::phone_confirmCall>(std::move(net_query));
void CallActor::on_confirm_query_result(Result<NetQueryPtr> r_net_query) {
auto res = fetch_result<telegram_api::phone_confirmCall>(std::move(r_net_query));
if (res.is_error()) {
return on_error(res.move_as_error());
}
@ -720,13 +726,14 @@ void CallActor::try_send_discard_query() {
get_input_phone_call_discard_reason(call_state_.discard_reason), connection_id_);
auto query = G()->net_query_creator().create(tl_query);
state_ = State::WaitDiscardResult;
send_with_promise(std::move(query), PromiseCreator::lambda([actor_id = actor_id(this)](NetQueryPtr net_query) {
send_closure(actor_id, &CallActor::on_discard_query_result, std::move(net_query));
send_with_promise(std::move(query),
PromiseCreator::lambda([actor_id = actor_id(this)](Result<NetQueryPtr> r_net_query) {
send_closure(actor_id, &CallActor::on_discard_query_result, std::move(r_net_query));
}));
}
void CallActor::on_discard_query_result(NetQueryPtr net_query) {
auto res = fetch_result<telegram_api::phone_discardCall>(std::move(net_query));
void CallActor::on_discard_query_result(Result<NetQueryPtr> r_net_query) {
auto res = fetch_result<telegram_api::phone_discardCall>(std::move(r_net_query));
if (res.is_error()) {
return on_error(res.move_as_error());
}
@ -768,13 +775,14 @@ void CallActor::flush_call_state() {
void CallActor::start_up() {
auto tl_query = telegram_api::phone_getCallConfig();
auto query = G()->net_query_creator().create(tl_query);
send_with_promise(std::move(query), PromiseCreator::lambda([actor_id = actor_id(this)](NetQueryPtr net_query) {
send_closure(actor_id, &CallActor::on_get_call_config_result, std::move(net_query));
send_with_promise(std::move(query),
PromiseCreator::lambda([actor_id = actor_id(this)](Result<NetQueryPtr> r_net_query) {
send_closure(actor_id, &CallActor::on_get_call_config_result, std::move(r_net_query));
}));
}
void CallActor::on_get_call_config_result(NetQueryPtr net_query) {
auto res = fetch_result<telegram_api::phone_getCallConfig>(std::move(net_query));
void CallActor::on_get_call_config_result(Result<NetQueryPtr> r_net_query) {
auto res = fetch_result<telegram_api::phone_getCallConfig>(std::move(r_net_query));
if (res.is_error()) {
return on_error(res.move_as_error());
}

View File

@ -164,28 +164,28 @@ class CallActor : public NetQueryCallback {
Status do_update_call(telegram_api::phoneCallDiscarded &call);
void send_received_query();
void on_received_query_result(NetQueryPtr net_query);
void on_received_query_result(Result<NetQueryPtr> r_net_query);
void try_send_request_query();
void on_request_query_result(NetQueryPtr net_query);
void on_request_query_result(Result<NetQueryPtr> r_net_query);
void try_send_accept_query();
void on_accept_query_result(NetQueryPtr net_query);
void on_accept_query_result(Result<NetQueryPtr> r_net_query);
void try_send_confirm_query();
void on_confirm_query_result(NetQueryPtr net_query);
void on_confirm_query_result(Result<NetQueryPtr> r_net_query);
void try_send_discard_query();
void on_discard_query_result(NetQueryPtr net_query);
void on_discard_query_result(Result<NetQueryPtr> r_net_query);
void on_begin_exchanging_key();
void on_call_discarded(CallDiscardReason reason, bool need_rating, bool need_debug, bool is_video);
void on_set_rating_query_result(NetQueryPtr net_query);
void on_set_debug_query_result(NetQueryPtr net_query);
void on_set_rating_query_result(Result<NetQueryPtr> r_net_query);
void on_set_debug_query_result(Result<NetQueryPtr> r_net_query);
void on_get_call_config_result(NetQueryPtr net_query);
void on_get_call_config_result(Result<NetQueryPtr> r_net_query);
void flush_call_state();