diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 853135f6c..c9f0fbedb 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4624,6 +4624,9 @@ joinGroupCall group_call_id:int32 participant_id:MessageSender audio_source:int3 //@description Starts screen sharing in a joined group call. Returns join response payload for tgcalls @group_call_id Group call identifier @payload Group call join payload; received from tgcalls startGroupCallScreenSharing group_call_id:int32 payload:string = Text; +//@description Ends screen sharing in a joined group call @group_call_id Group call identifier +endGroupCallScreenSharing group_call_id:int32 = Ok; + //@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-64 characters setGroupCallTitle group_call_id:int32 title:string = Ok; diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index 881a33fb8..5400dad6f 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -439,6 +439,38 @@ class JoinGroupCallPresentationQuery : public Td::ResultHandler { } }; +class LeaveGroupCallPresentationQuery : public Td::ResultHandler { + Promise promise_; + + public: + explicit LeaveGroupCallPresentationQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(InputGroupCallId input_group_call_id) { + send_query(G()->net_query_creator().create( + telegram_api::phone_leaveGroupCallPresentation(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(); + LOG(INFO) << "Receive result for LeaveGroupCallPresentationQuery: " << to_string(ptr); + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); + } + + void on_error(uint64 id, Status status) override { + if (status.message() == "PARTICIPANT_PRESENTATION_MISSING") { + promise_.set_value(Unit()); + return; + } + promise_.set_error(std::move(status)); + } +}; + class EditGroupCallTitleQuery : public Td::ResultHandler { Promise promise_; @@ -2476,6 +2508,36 @@ void GroupCallManager::start_group_call_screen_sharing(GroupCallId group_call_id } } +void GroupCallManager::end_group_call_screen_sharing(GroupCallId group_call_id, 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); + CHECK(group_call != nullptr); + if (!group_call->is_inited || !group_call->is_active) { + return promise.set_error(Status::Error(400, "GROUPCALL_JOIN_MISSING")); + } + if (!group_call->is_joined || group_call->is_being_left) { + if (is_group_call_being_joined(input_group_call_id) || group_call->need_rejoin) { + group_call->after_join.push_back( + PromiseCreator::lambda([actor_id = actor_id(this), group_call_id, + promise = std::move(promise)](Result &&result) mutable { + if (result.is_error()) { + promise.set_error(Status::Error(400, "GROUPCALL_JOIN_MISSING")); + } else { + send_closure(actor_id, &GroupCallManager::end_group_call_screen_sharing, group_call_id, + std::move(promise)); + } + })); + return; + } + return promise.set_error(Status::Error(400, "GROUPCALL_JOIN_MISSING")); + } + + cancel_join_group_call_presentation_request(input_group_call_id); + + td_->create_handler(std::move(promise))->send(input_group_call_id); +} + void GroupCallManager::try_load_group_call_administrators(InputGroupCallId input_group_call_id, DialogId dialog_id) { if (!dialog_id.is_valid() || !need_group_call_participants(input_group_call_id) || can_manage_group_calls(dialog_id).is_error()) { diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 3e19e6d74..67c407e6a 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -69,6 +69,8 @@ class GroupCallManager : public Actor { void start_group_call_screen_sharing(GroupCallId group_call_id, string &&payload, Promise &&promise); + void end_group_call_screen_sharing(GroupCallId group_call_id, Promise &&promise); + void set_group_call_title(GroupCallId group_call_id, string title, Promise &&promise); void toggle_group_call_start_subscribed(GroupCallId group_call_id, bool start_subscribed, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 5e3f7d886..1f7356ff0 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6050,6 +6050,13 @@ void Td::on_request(uint64 id, td_api::startGroupCallScreenSharing &request) { std::move(query_promise)); } +void Td::on_request(uint64 id, const td_api::endGroupCallScreenSharing &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + group_call_manager_->end_group_call_screen_sharing(GroupCallId(request.group_call_id_), + std::move(promise)); +} + void Td::on_request(uint64 id, td_api::setGroupCallTitle &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.title_); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 3400e0872..7dbc0a0cd 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -717,6 +717,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::startGroupCallScreenSharing &request); + void on_request(uint64 id, const td_api::endGroupCallScreenSharing &request); + void on_request(uint64 id, td_api::setGroupCallTitle &request); void on_request(uint64 id, const td_api::toggleGroupCallMuteNewParticipants &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 91c66dd06..eee145333 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2719,6 +2719,9 @@ class CliClient final : public Actor { as_message_sender(participant_id), group_call_source_, std::move(payload), true, invite_hash)); } + } else if (op == "egcss") { + string group_call_id = args; + send_request(td_api::make_object(as_group_call_id(group_call_id))); } else if (op == "sgct") { string chat_id; string title;