From 3e95f8d9cca12da93216f396620c0ffcc401b0d2 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 27 Nov 2020 17:40:29 +0300 Subject: [PATCH] Add toggleGroupCallMemberIsMuted method. --- td/generate/scheme/td_api.tl | 4 +++ td/generate/scheme/td_api.tlo | Bin 188492 -> 188672 bytes td/telegram/GroupCallManager.cpp | 47 +++++++++++++++++++++++++++++++ td/telegram/GroupCallManager.h | 3 ++ td/telegram/Td.cpp | 9 ++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 8 ++++++ 7 files changed, 73 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 617559daa..01c91f887 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4324,6 +4324,10 @@ toggleGroupCallMuteNewMembers group_call_id:string mute_new_members:Bool = Ok; //@group_call_id Group call identifier @user_id User identifier inviteGroupCallMember group_call_id:string user_id:int32 = Ok; +//@description Toggles whether a group call member is muted. Requires can_manage_calls rights to mute other group call members +//@group_call_id Group call identifier @user_id User identifier @is_muted Pass true if the user must be muted and false otherwise +toggleGroupCallMemberIsMuted group_call_id:string user_id:int32 is_muted:Bool = Ok; + //@description Checks group call source for validness. If the method returns an error with a message "GROUP_CALL_JOIN_MISSING", the call needs to be rejoined @group_call_id Group call identifier @source Caller source identifier checkGroupCallSource group_call_id:string source:int32 = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 0c818aaaa3f60fce0e729de1324c4b590888679c..79d7d7ca86343e5632b019950d138b0d997491dc 100644 GIT binary patch delta 81 zcmV-X0IvVczzcxF3xI?Hv;xE#0gkuD83IGTAu#C3>M{;j promise_; + + public: + explicit EditGroupCallMemberQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(InputGroupCallId group_call_id, UserId user_id, bool is_muted) { + auto input_user = td->contacts_manager_->get_input_user(user_id); + CHECK(input_user != nullptr); + + int32 flags = 0; + if (is_muted) { + flags |= telegram_api::phone_editGroupCallMember::MUTED_MASK; + } + + send_query(G()->net_query_creator().create(telegram_api::phone_editGroupCallMember( + flags, false /*ignored*/, group_call_id.get_input_group_call(), std::move(input_user)))); + } + + 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 EditGroupCallMemberQuery: " << to_string(ptr); + td->updates_manager_->on_get_updates(std::move(ptr)); + + // TODO set promise after updates are processed + promise_.set_value(Unit()); + } + + void on_error(uint64 id, Status status) override { + promise_.set_error(std::move(status)); + } +}; + class CheckGroupCallQuery : public Td::ResultHandler { Promise promise_; @@ -480,6 +519,14 @@ void GroupCallManager::invite_group_call_member(InputGroupCallId group_call_id, td_->create_handler(std::move(promise))->send(group_call_id, user_id); } +void GroupCallManager::toggle_group_call_member_is_muted(InputGroupCallId group_call_id, UserId user_id, + bool is_muted, Promise &&promise) { + if (!td_->contacts_manager_->have_input_user(user_id)) { + return promise.set_error(Status::Error(400, "Have no access to the user")); + } + td_->create_handler(std::move(promise))->send(group_call_id, user_id, is_muted); +} + void GroupCallManager::check_group_call_source(InputGroupCallId group_call_id, int32 source, Promise &&promise) { td_->create_handler(std::move(promise))->send(group_call_id, source); } diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 5669e1723..40cba05f7 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -41,6 +41,9 @@ class GroupCallManager : public Actor { void invite_group_call_member(InputGroupCallId group_call_id, UserId user_id, Promise &&promise); + void toggle_group_call_member_is_muted(InputGroupCallId group_call_id, UserId user_id, bool is_muted, + Promise &&promise); + void check_group_call_source(InputGroupCallId group_call_id, int32 source, Promise &&promise); void leave_group_call(InputGroupCallId group_call_id, int32 source, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 24a411c93..c63987551 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6066,6 +6066,15 @@ void Td::on_request(uint64 id, const td_api::inviteGroupCallMember &request) { group_call_manager_->invite_group_call_member(group_call_id, UserId(request.user_id_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::toggleGroupCallMemberIsMuted &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + TRY_RESULT_PROMISE(promise, group_call_id, InputGroupCallId::from_group_call_id(request.group_call_id_)); + + group_call_manager_->toggle_group_call_member_is_muted(group_call_id, UserId(request.user_id_), request.is_muted_, + std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::checkGroupCallSource &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index c711c0201..b8d201fcc 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -700,6 +700,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::inviteGroupCallMember &request); + void on_request(uint64 id, const td_api::toggleGroupCallMemberIsMuted &request); + void on_request(uint64 id, const td_api::checkGroupCallSource &request); void on_request(uint64 id, const td_api::leaveGroupCall &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index a9adad591..22b7c8fd1 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2857,6 +2857,14 @@ class CliClient final : public Actor { std::tie(group_call_id, user_id) = split(args); send_request( td_api::make_object(as_group_call_id(group_call_id), as_user_id(user_id))); + } else if (op == "tgcmim") { + string group_call_id; + string user_id; + string is_muted; + std::tie(group_call_id, args) = split(args); + std::tie(user_id, is_muted) = split(args); + send_request(td_api::make_object(as_group_call_id(group_call_id), + as_user_id(user_id), as_bool(is_muted))); } else if (op == "cgcs") { send_request(td_api::make_object(as_group_call_id(args), 123)); } else if (op == "lgc") {