diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 7a236d53b..ce5fc2596 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4587,6 +4587,11 @@ resetGroupCallInviteHash group_call_id:int32 = Ok; //@group_call_id Group call identifier @user_ids User identifiers. At most 10 users can be invited simultaneously inviteGroupCallParticipants group_call_id:int32 user_ids:vector = Ok; +//@description Returns invite link to a voice chat in a public chat +//@group_call_id Group call identifier +//@can_self_unmute Pass true if the invite_link should contain an invite hash, passing which to joinGroupCall would allow the invited user to unmute themself. Requires groupCall.can_be_managed group call flag +getGroupCallInviteLink group_call_id:int32 can_self_unmute:Bool = HttpUrl; + //@description Starts recording of a group call. Requires groupCall.can_be_managed group call flag @group_call_id Group call identifier @title Group call recording title; 0-128 characters startGroupCallRecording group_call_id:int32 title:string = Ok; diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index abf0c3c6d..584028a8c 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -420,6 +420,37 @@ class InviteToGroupCallQuery : public Td::ResultHandler { } }; +class ExportGroupCallInviteQuery : public Td::ResultHandler { + Promise promise_; + + public: + explicit ExportGroupCallInviteQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(InputGroupCallId input_group_call_id, bool can_self_unmute) { + int32 flags = 0; + if (can_self_unmute) { + flags |= telegram_api::phone_exportGroupCallInvite::CAN_SELF_UNMUTE_MASK; + } + send_query(G()->net_query_creator().create(telegram_api::phone_exportGroupCallInvite( + flags, false /*ignored*/, input_group_call_id.get_input_group_call()))); + } + + 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(); + promise_.set_value(std::move(ptr->link_)); + } + + void on_error(uint64 id, Status status) override { + promise_.set_error(std::move(status)); + } +}; + class ToggleGroupCallRecordQuery : public Td::ResultHandler { Promise promise_; @@ -2302,6 +2333,22 @@ void GroupCallManager::invite_group_call_participants(GroupCallId group_call_id, td_->create_handler(std::move(promise))->send(input_group_call_id, std::move(input_users)); } +void GroupCallManager::get_group_call_invite_link(GroupCallId group_call_id, bool can_self_unmute, + Promise &&promise) { + TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id)); + + auto *group_call = get_group_call(input_group_call_id); + if (group_call == nullptr || !group_call->is_inited || !group_call->is_active) { + return promise.set_error(Status::Error(400, "Can't get group call invite link")); + } + + if (can_self_unmute && !group_call->can_be_managed) { + return promise.set_error(Status::Error(400, "Not enough rights in the group call")); + } + + td_->create_handler(std::move(promise))->send(input_group_call_id, can_self_unmute); +} + void GroupCallManager::toggle_group_call_recording(GroupCallId group_call_id, bool is_enabled, string title, Promise &&promise) { TRY_RESULT_PROMISE(promise, input_group_call_id, get_input_group_call_id(group_call_id)); diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 7715d7f31..abe76f6f8 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -72,6 +72,8 @@ class GroupCallManager : public Actor { void invite_group_call_participants(GroupCallId group_call_id, vector &&user_ids, Promise &&promise); + void get_group_call_invite_link(GroupCallId group_call_id, bool can_self_unmute, Promise &&promise); + void toggle_group_call_recording(GroupCallId group_call_id, bool is_enabled, string title, Promise &&promise); void set_group_call_participant_is_speaking(GroupCallId group_call_id, int32 audio_source, bool is_speaking, diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index cceec7fde..23c1d5c12 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6030,6 +6030,20 @@ void Td::on_request(uint64 id, const td_api::inviteGroupCallParticipants &reques std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getGroupCallInviteLink &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + auto query_promise = PromiseCreator::lambda([promise = std::move(promise)](Result result) mutable { + if (result.is_error()) { + promise.set_error(result.move_as_error()); + } else { + promise.set_value(td_api::make_object(result.move_as_ok())); + } + }); + group_call_manager_->get_group_call_invite_link(GroupCallId(request.group_call_id_), request.can_self_unmute_, + std::move(query_promise)); +} + void Td::on_request(uint64 id, td_api::startGroupCallRecording &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.title_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index f842229fe..8b022e1d8 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -715,6 +715,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::inviteGroupCallParticipants &request); + void on_request(uint64 id, const td_api::getGroupCallInviteLink &request); + void on_request(uint64 id, td_api::startGroupCallRecording &request); void on_request(uint64 id, const td_api::endGroupCallRecording &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 403869763..81427b40f 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2709,6 +2709,12 @@ class CliClient final : public Actor { get_args(args, group_call_id, user_ids); send_request(td_api::make_object(as_group_call_id(group_call_id), as_user_ids(user_ids))); + } else if (op == "ggcil") { + string group_call_id; + bool can_self_unmute; + get_args(args, group_call_id, can_self_unmute); + send_request( + td_api::make_object(as_group_call_id(group_call_id), can_self_unmute)); } else if (op == "sgcr") { string chat_id; string title;