diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index e1ba68242..46d64e19a 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4553,6 +4553,9 @@ sendCallRating call_id:int32 rating:int32 comment:string problems:vector> promise_; + DialogId dialog_id_; + + public: + explicit GetGroupCallJoinAsQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send(DialogId dialog_id) { + dialog_id_ = dialog_id; + + auto input_peer = td->messages_manager_->get_input_peer(dialog_id, AccessRights::Read); + CHECK(input_peer != nullptr); + + send_query(G()->net_query_creator().create(telegram_api::phone_getGroupCallJoinAs(std::move(input_peer)))); + } + + void on_result(uint64 id, BufferSlice packet) override { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(id, result_ptr.move_as_error()); + } + + auto ptr = result_ptr.move_as_ok(); + LOG(INFO) << "Receive result for GetGroupCallJoinAsQuery: " << to_string(ptr); + + td->contacts_manager_->on_get_users(std::move(ptr->users_), "GetGroupCallJoinAsQuery"); + td->contacts_manager_->on_get_chats(std::move(ptr->chats_), "GetGroupCallJoinAsQuery"); + + vector> participant_aliaces; + for (auto &peer : ptr->peers_) { + DialogId dialog_id(peer); + if (!dialog_id.is_valid()) { + LOG(ERROR) << "Receive invalid " << dialog_id << " as join as peer for " << dialog_id_; + continue; + } + if (dialog_id.get_type() != DialogType::User) { + td->messages_manager_->force_create_dialog(dialog_id, "GetGroupCallJoinAsQuery"); + } + + participant_aliaces.push_back(td->messages_manager_->get_message_sender_object(dialog_id)); + } + + promise_.set_value(td_api::make_object(static_cast(participant_aliaces.size()), + std::move(participant_aliaces))); + } + + void on_error(uint64 id, Status status) override { + td->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetGroupCallJoinAsQuery"); + promise_.set_error(std::move(status)); + } +}; + class CreateGroupCallQuery : public Td::ResultHandler { Promise promise_; DialogId dialog_id_; @@ -780,6 +834,21 @@ bool GroupCallManager::can_manage_group_call(InputGroupCallId input_group_call_i return can_manage_group_calls(group_call->dialog_id).is_ok(); } +void GroupCallManager::get_group_call_join_as(DialogId dialog_id, + Promise> &&promise) { + if (!dialog_id.is_valid()) { + return promise.set_error(Status::Error(400, "Invalid chat identifier specified")); + } + if (!td_->messages_manager_->have_dialog_force(dialog_id)) { + return promise.set_error(Status::Error(400, "Chat not found")); + } + if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) { + return promise.set_error(Status::Error(400, "Can't access chat")); + } + + td_->create_handler(std::move(promise))->send(dialog_id); +} + void GroupCallManager::create_voice_chat(DialogId dialog_id, Promise &&promise) { if (!dialog_id.is_valid()) { return promise.set_error(Status::Error(400, "Invalid chat identifier specified")); diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 9f6ffc1f5..491097f5c 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -45,6 +45,8 @@ class GroupCallManager : public Actor { GroupCallId get_group_call_id(InputGroupCallId input_group_call_id, DialogId dialog_id); + void get_group_call_join_as(DialogId dialog_id, Promise> &&promise); + void create_voice_chat(DialogId dialog_id, Promise &&promise); void get_group_call(GroupCallId group_call_id, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index b674d1fd9..bc1b04a4b 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5963,6 +5963,12 @@ void Td::on_request(uint64 id, td_api::sendCallDebugInformation &request) { std::move(request.debug_information_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getAvailableVoiceChatAliases &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + group_call_manager_->get_group_call_join_as(DialogId(request.chat_id_), std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::createVoiceChat &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index c60301b92..eba92303c 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -699,6 +699,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::sendCallDebugInformation &request); + void on_request(uint64 id, const td_api::getAvailableVoiceChatAliases &request); + void on_request(uint64 id, const td_api::createVoiceChat &request); void on_request(uint64 id, const td_api::getGroupCall &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 1dbbb0524..a84803e86 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2665,6 +2665,8 @@ class CliClient final : public Actor { as_call_id(call_id), rating, "Wow, such good call! (TDLib test)", std::move(problems))); } else if (op == "scdi" || op == "SendCallDebugInformation") { send_request(td_api::make_object(as_call_id(args), "{}")); + } else if (op == "gavca") { + send_request(td_api::make_object(as_chat_id(args))); } else if (op == "cvc") { send_request(td_api::make_object(as_chat_id(args))); } else if (op == "ggc") {