diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 4147284e4..de02d6d8a 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4553,8 +4553,8 @@ createVoiceChat chat_id:int53 = GroupCallId; //@description Returns information about a group call @group_call_id Group call identifier getGroupCall group_call_id:int32 = GroupCall; -//@description Joins a group call @group_call_id Group call identifier @payload Group join payload, received from tgcalls. Use null to cancel previous joinGroupCall request @source Caller synchronization source identifier; received from tgcalls @is_muted True, if the user's microphone is muted -joinGroupCall group_call_id:int32 payload:groupCallPayload source:int32 is_muted:Bool = GroupCallJoinResponse; +//@description Joins a group call @group_call_id Group call identifier @as_chat_id If not 0, identifier of the chat, which will be used to join the call @payload Group join payload, received from tgcalls. Use null to cancel previous joinGroupCall request @source Caller synchronization source identifier; received from tgcalls @is_muted True, if the user's microphone is muted +joinGroupCall group_call_id:int32 as_chat_id:int53 payload:groupCallPayload source:int32 is_muted:Bool = GroupCallJoinResponse; //@description Sets group call title. Requires groupCall.can_be_managed group call flag @group_call_id Group call identifier @title New group call title; 1-128 characters setGroupCallTitle group_call_id:int32 title:string = Ok; diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index fec63f9fe..1ebbd9e99 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -184,18 +184,25 @@ class GetGroupCallParticipantsQuery : public Td::ResultHandler { class JoinGroupCallQuery : public Td::ResultHandler { Promise promise_; InputGroupCallId input_group_call_id_; + DialogId as_dialog_id_; uint64 generation_ = 0; public: explicit JoinGroupCallQuery(Promise &&promise) : promise_(std::move(promise)) { } - NetQueryRef send(InputGroupCallId input_group_call_id, const string &payload, bool is_muted, uint64 generation) { + NetQueryRef send(InputGroupCallId input_group_call_id, DialogId as_dialog_id, const string &payload, bool is_muted, + uint64 generation) { input_group_call_id_ = input_group_call_id; + as_dialog_id_ = as_dialog_id; generation_ = generation; - auto join_as_input_peer = - td->messages_manager_->get_input_peer(DialogId(td->contacts_manager_->get_my_id()), AccessRights::Read); + tl_object_ptr join_as_input_peer; + if (as_dialog_id.is_valid()) { + join_as_input_peer = td->messages_manager_->get_input_peer(as_dialog_id, AccessRights::Read); + } else { + join_as_input_peer = make_tl_object(); + } CHECK(join_as_input_peer != nullptr); int32 flags = 0; @@ -1526,7 +1533,7 @@ int32 GroupCallManager::cancel_join_group_call_request(InputGroupCallId input_gr return audio_source; } -void GroupCallManager::join_group_call(GroupCallId group_call_id, +void GroupCallManager::join_group_call(GroupCallId group_call_id, DialogId as_dialog_id, td_api::object_ptr &&payload, int32 audio_source, bool is_muted, Promise> &&promise) { @@ -1546,6 +1553,15 @@ void GroupCallManager::join_group_call(GroupCallId group_call_id, cancel_join_group_call_request(input_group_call_id); + if (as_dialog_id != DialogId()) { + if (!td_->messages_manager_->have_dialog_force(as_dialog_id)) { + return promise.set_error(Status::Error(400, "Chat not found")); + } + if (!td_->messages_manager_->have_input_peer(as_dialog_id, AccessRights::Read)) { + return promise.set_error(Status::Error(400, "Can't access the chat")); + } + } + if (audio_source == 0) { return promise.set_error(Status::Error(400, "Audio source must be non-zero")); } @@ -1606,12 +1622,20 @@ void GroupCallManager::join_group_call(GroupCallId group_call_id, result.move_as_error()); }); request->query_ref = td_->create_handler(std::move(query_promise)) - ->send(input_group_call_id, json_payload, is_muted, generation); + ->send(input_group_call_id, as_dialog_id, json_payload, is_muted, generation); - if (group_call->is_inited && td_->contacts_manager_->have_user_force(td_->contacts_manager_->get_my_id())) { + if (group_call->is_inited) { GroupCallParticipant group_call_participant; group_call_participant.is_self = true; - group_call_participant.dialog_id = DialogId(td_->contacts_manager_->get_my_id()); + if (as_dialog_id.is_valid()) { + // dialog already exists + group_call_participant.dialog_id = as_dialog_id; + } else { + // create dialog with self + DialogId my_dialog_id(td_->contacts_manager_->get_my_id()); + td_->messages_manager_->force_create_dialog(my_dialog_id, "join_group_call"); + group_call_participant.dialog_id = my_dialog_id; + } group_call_participant.audio_source = audio_source; group_call_participant.joined_date = G()->unix_time(); // if can_self_unmute has never been inited from self-participant, diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 07011d559..7ef87bbf2 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -50,8 +50,8 @@ class GroupCallManager : public Actor { void reload_group_call(InputGroupCallId input_group_call_id, Promise> &&promise); - void join_group_call(GroupCallId group_call_id, td_api::object_ptr &&payload, - int32 audio_source, bool is_muted, + void join_group_call(GroupCallId group_call_id, DialogId as_dialog_id, + td_api::object_ptr &&payload, int32 audio_source, bool is_muted, Promise> &&promise); void set_group_call_title(GroupCallId group_call_id, string title, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 8ddbe7172..ce4f0bcb3 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5985,8 +5985,9 @@ void Td::on_request(uint64 id, const td_api::getGroupCall &request) { void Td::on_request(uint64 id, td_api::joinGroupCall &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); - group_call_manager_->join_group_call(GroupCallId(request.group_call_id_), std::move(request.payload_), - request.source_, request.is_muted_, std::move(promise)); + group_call_manager_->join_group_call(GroupCallId(request.group_call_id_), DialogId(request.as_chat_id_), + std::move(request.payload_), request.source_, request.is_muted_, + std::move(promise)); } void Td::on_request(uint64 id, td_api::setGroupCallTitle &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 50c3b629a..3378316ba 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2670,15 +2670,18 @@ class CliClient final : public Actor { } else if (op == "ggc") { send_request(td_api::make_object(as_group_call_id(args))); } else if (op == "jgc") { + string group_call_id; + string chat_id; + get_args(args, group_call_id, chat_id); vector> fingerprints; fingerprints.push_back(td_api::make_object("hash", "setup", "fingerprint")); fingerprints.push_back(td_api::make_object("h2", "s2", "fingerprint2")); send_request(td_api::make_object( - as_group_call_id(args), + as_group_call_id(group_call_id), as_chat_id(chat_id), td_api::make_object("ufrag", "pwd", std::move(fingerprints)), group_call_source_, true)); } else if (op == "jgcc") { - send_request(td_api::make_object(as_group_call_id(args), nullptr, 0, true)); + send_request(td_api::make_object(as_group_call_id(args), 0, nullptr, 0, true)); } else if (op == "sgct") { string chat_id; string title;