From 9fc456f434a89b5cd4a0ccd658716fc0befbe7e6 Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 30 Aug 2022 12:03:26 +0300 Subject: [PATCH] Use SafePromise in CallManager. --- td/telegram/CallManager.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/td/telegram/CallManager.cpp b/td/telegram/CallManager.cpp index 702655775..0e4452102 100644 --- a/td/telegram/CallManager.cpp +++ b/td/telegram/CallManager.cpp @@ -66,8 +66,9 @@ void CallManager::create_call(UserId user_id, tl_object_ptr(std::move(promise), Status::Error(400, "Call not found")); send_closure(actor, &CallActor::create_call, user_id, std::move(input_user), std::move(protocol), is_video, - std::move(promise)); + std::move(safe_promise)); } void CallManager::accept_call(CallId call_id, CallProtocol &&protocol, Promise promise) { @@ -75,7 +76,8 @@ void CallManager::accept_call(CallId call_id, CallProtocol &&protocol, Promise(std::move(promise), Status::Error(400, "Call not found")); + send_closure(actor, &CallActor::accept_call, std::move(protocol), std::move(safe_promise)); } void CallManager::send_call_signaling_data(CallId call_id, string &&data, Promise promise) { @@ -83,7 +85,8 @@ void CallManager::send_call_signaling_data(CallId call_id, string &&data, Promis if (actor.empty()) { return promise.set_error(Status::Error(400, "Call not found")); } - send_closure(actor, &CallActor::send_call_signaling_data, std::move(data), std::move(promise)); + auto safe_promise = SafePromise(std::move(promise), Status::Error(400, "Call not found")); + send_closure(actor, &CallActor::send_call_signaling_data, std::move(data), std::move(safe_promise)); } void CallManager::discard_call(CallId call_id, bool is_disconnected, int32 duration, bool is_video, int64 connection_id, @@ -92,7 +95,9 @@ void CallManager::discard_call(CallId call_id, bool is_disconnected, int32 durat if (actor.empty()) { return promise.set_error(Status::Error(400, "Call not found")); } - send_closure(actor, &CallActor::discard_call, is_disconnected, duration, is_video, connection_id, std::move(promise)); + auto safe_promise = SafePromise(std::move(promise), Status::Error(400, "Call not found")); + send_closure(actor, &CallActor::discard_call, is_disconnected, duration, is_video, connection_id, + std::move(safe_promise)); } void CallManager::rate_call(CallId call_id, int32 rating, string comment, @@ -101,7 +106,8 @@ void CallManager::rate_call(CallId call_id, int32 rating, string comment, if (actor.empty()) { return promise.set_error(Status::Error(400, "Call not found")); } - send_closure(actor, &CallActor::rate_call, rating, std::move(comment), std::move(problems), std::move(promise)); + auto safe_promise = SafePromise(std::move(promise), Status::Error(400, "Call not found")); + send_closure(actor, &CallActor::rate_call, rating, std::move(comment), std::move(problems), std::move(safe_promise)); } void CallManager::send_call_debug_information(CallId call_id, string data, Promise promise) { @@ -109,7 +115,8 @@ void CallManager::send_call_debug_information(CallId call_id, string data, Promi if (actor.empty()) { return promise.set_error(Status::Error(400, "Call not found")); } - send_closure(actor, &CallActor::send_call_debug_information, std::move(data), std::move(promise)); + auto safe_promise = SafePromise(std::move(promise), Status::Error(400, "Call not found")); + send_closure(actor, &CallActor::send_call_debug_information, std::move(data), std::move(safe_promise)); } void CallManager::send_call_log(CallId call_id, td_api::object_ptr log_file, Promise promise) { @@ -117,7 +124,8 @@ void CallManager::send_call_log(CallId call_id, td_api::object_ptr(std::move(promise), Status::Error(400, "Call not found")); + send_closure(actor, &CallActor::send_call_log, std::move(log_file), std::move(safe_promise)); } CallId CallManager::create_call_actor() {