Add td_api::CallProblem.

GitOrigin-RevId: 421cd01239ef43d3073556f3a222db17d5d0d3e5
This commit is contained in:
levlam 2019-08-06 20:07:23 +03:00
parent a5a7e30ec5
commit 1afdf258ab
8 changed files with 92 additions and 11 deletions

View File

@ -1627,6 +1627,30 @@ callStateDiscarded reason:CallDiscardReason need_rating:Bool need_debug_informat
callStateError error:error = CallState;
//@class CallProblem @description Describes a type of a problem that happened during a call
//@description The user heard his own voice
callProblemEcho = CallProblem;
//@description The user heard background noice
callProblemNoice = CallProblem;
//@description The other side kept disappearing
callProblemInterruptions = CallProblem;
//@description The speech was distorted
callProblemDistortedSpeech = CallProblem;
//@description The user couldn't hear the other side
callProblemSilentLocal = CallProblem;
//@description The other side couldn't hear the user
callProblemSilentRemote = CallProblem;
//@description The call ended unexpectedly
callProblemDropped = CallProblem;
//@description Describes a call @id Call identifier, not persistent @user_id Peer user identifier @is_outgoing True, if the call is outgoing @state Call state
call id:int32 user_id:int32 is_outgoing:Bool state:CallState = Call;
@ -3415,8 +3439,8 @@ acceptCall call_id:int32 protocol:callProtocol = Ok;
//@description Discards a call @call_id Call identifier @is_disconnected True, if the user was disconnected @duration The call duration, in seconds @connection_id Identifier of the connection used during the call
discardCall call_id:int32 is_disconnected:Bool duration:int32 connection_id:int64 = Ok;
//@description Sends a call rating @call_id Call identifier @rating Call rating; 1-5 @comment An optional user comment if the rating is less than 5
sendCallRating call_id:int32 rating:int32 comment:string = Ok;
//@description Sends a call rating @call_id Call identifier @rating Call rating; 1-5 @comment An optional user comment if the rating is less than 5 @problems List of problems with the call, specified by the user
sendCallRating call_id:int32 rating:int32 comment:string problems:vector<CallProblem> = Ok;
//@description Sends debug information for a call @call_id Call identifier @debug_information Debug information in application-specific format
sendCallDebugInformation call_id:int32 debug_information:string = Ok;

Binary file not shown.

View File

@ -29,9 +29,10 @@
#include "td/utils/Random.h"
#include <tuple>
#include <unordered_set>
namespace td {
// CallProtocol
CallProtocol CallProtocol::from_telegram_api(const telegram_api::phoneCallProtocol &protocol) {
CallProtocol res;
res.udp_p2p = protocol.udp_p2p_;
@ -110,7 +111,6 @@ tl_object_ptr<td_api::CallState> CallState::as_td_api() const {
}
}
// CallActor
CallActor::CallActor(CallId call_id, ActorShared<> parent, Promise<int64> promise)
: parent_(std::move(parent)), call_id_promise_(std::move(promise)), local_call_id_(call_id) {
}
@ -186,11 +186,53 @@ void CallActor::accept_call(CallProtocol &&protocol, Promise<> promise) {
loop();
}
void CallActor::rate_call(int32 rating, string comment, Promise<> promise) {
void CallActor::rate_call(int32 rating, string comment, vector<td_api::object_ptr<td_api::CallProblem>> &&problems,
Promise<> promise) {
if (!call_state_.need_rating) {
return promise.set_error(Status::Error(400, "Unexpected sendCallRating"));
}
promise.set_value(Unit());
if (rating == 5) {
comment.clear();
}
std::unordered_set<string> tags;
for (auto &problem : problems) {
if (problem == nullptr) {
continue;
}
const char *tag = [problem_id = problem->get_id()] {
switch (problem_id) {
case td_api::callProblemEcho::ID:
return "echo";
case td_api::callProblemNoice::ID:
return "noise";
case td_api::callProblemInterruptions::ID:
return "interruptions";
case td_api::callProblemDistortedSpeech::ID:
return "distorted_speech";
case td_api::callProblemSilentLocal::ID:
return "silent_local";
case td_api::callProblemSilentRemote::ID:
return "silent_remote";
case td_api::callProblemDropped::ID:
return "dropped";
default:
UNREACHABLE();
return "";
}
}();
if (tags.insert(tag).second) {
if (!comment.empty()) {
comment += ' ';
}
comment += '#';
comment += tag;
}
}
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(create_storer(tl_query));

View File

@ -81,7 +81,8 @@ class CallActor : public NetQueryCallback {
bool is_video, Promise<CallId> &&promise);
void discard_call(bool is_disconnected, int32 duration, bool is_video, int64 connection_id, Promise<> promise);
void accept_call(CallProtocol &&protocol, Promise<> promise);
void rate_call(int32 rating, string comment, Promise<> promise);
void rate_call(int32 rating, string comment, vector<td_api::object_ptr<td_api::CallProblem>> &&problems,
Promise<> promise);
void send_call_debug_information(string data, Promise<> promise);
void update_call(tl_object_ptr<telegram_api::PhoneCall> call);

View File

@ -71,12 +71,13 @@ void CallManager::accept_call(CallId call_id, CallProtocol &&protocol, Promise<>
send_closure(actor, &CallActor::accept_call, std::move(protocol), std::move(promise));
}
void CallManager::rate_call(CallId call_id, int32 rating, string comment, Promise<> promise) {
void CallManager::rate_call(CallId call_id, int32 rating, string comment,
vector<td_api::object_ptr<td_api::CallProblem>> &&problems, Promise<> promise) {
auto actor = get_call_actor(call_id);
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(promise));
send_closure(actor, &CallActor::rate_call, rating, std::move(comment), std::move(problems), std::move(promise));
}
void CallManager::send_call_debug_information(CallId call_id, string data, Promise<> promise) {

View File

@ -9,6 +9,7 @@
#include "td/telegram/CallActor.h"
#include "td/telegram/CallId.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/actor/actor.h"
@ -32,7 +33,8 @@ class CallManager : public Actor {
void discard_call(CallId call_id, bool is_disconnected, int32 duration, bool is_video, int64 connection_id,
Promise<> promise);
void accept_call(CallId call_id, CallProtocol &&protocol, Promise<> promise);
void rate_call(CallId call_id, int32 rating, string comment, Promise<> promise);
void rate_call(CallId call_id, int32 rating, string comment,
vector<td_api::object_ptr<td_api::CallProblem>> &&problems, Promise<> promise);
void send_call_debug_information(CallId call_id, string data, Promise<> promise);
private:

View File

@ -5925,7 +5925,7 @@ void Td::on_request(uint64 id, td_api::sendCallRating &request) {
CLEAN_INPUT_STRING(request.comment_);
CREATE_OK_REQUEST_PROMISE();
send_closure(G()->call_manager(), &CallManager::rate_call, CallId(request.call_id_), request.rating_,
std::move(request.comment_), std::move(promise));
std::move(request.comment_), std::move(request.problems_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::sendCallDebugInformation &request) {

View File

@ -2491,8 +2491,19 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::acceptCall>(
as_call_id(args), td_api::make_object<td_api::callProtocol>(true, true, 65, 65)));
} else if (op == "scr" || op == "SendCallRating") {
string call_id;
string rating;
std::tie(call_id, rating) = split(args);
vector<td_api::object_ptr<td_api::CallProblem>> problems;
problems.emplace_back(td_api::make_object<td_api::callProblemNoice>());
problems.emplace_back(td_api::make_object<td_api::callProblemNoice>());
problems.emplace_back(nullptr);
problems.emplace_back(td_api::make_object<td_api::callProblemNoice>());
problems.emplace_back(td_api::make_object<td_api::callProblemEcho>());
problems.emplace_back(td_api::make_object<td_api::callProblemDistortedSpeech>());
send_request(
td_api::make_object<td_api::sendCallRating>(as_call_id(args), 5, "Wow, such good call! (TDLib test)"));
td_api::make_object<td_api::sendCallRating>(as_call_id(call_id), to_integer<int32>(rating), "Wow, such good call! (TDLib test)", std::move(problems)));
} else if (op == "scdi" || op == "SendCallDebugInformation") {
send_request(td_api::make_object<td_api::sendCallDebugInformation>(as_call_id(args), "{}"));
} else if (op == "gcil") {