From 1eca39c4ee50d08a2f0730a65c6d9705e882b9fb Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 27 Nov 2020 01:58:36 +0300 Subject: [PATCH] Add toggleGroupCallMuteNewMembers method. --- td/generate/scheme/td_api.tl | 4 ++++ td/generate/scheme/td_api.tlo | Bin 188064 -> 188220 bytes td/telegram/GroupCallManager.cpp | 37 +++++++++++++++++++++++++++++++ td/telegram/GroupCallManager.h | 3 +++ td/telegram/Td.cpp | 8 +++++++ td/telegram/Td.h | 2 ++ td/telegram/UpdatesManager.cpp | 2 -- td/telegram/cli.cpp | 2 ++ 8 files changed, 56 insertions(+), 2 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 186bb475a..3148e9f78 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4316,6 +4316,10 @@ createChatGroupCall chat_id:int53 = GroupCallId; //@description Joins a group call @group_call_id Group call identifier @payload Group join payload, received from tgcalls @source Caller source identifier, received from tgcalls @is_muted True, if the user's microphone is muted joinGroupCall group_call_id:string payload:groupCallPayload source:int32 is_muted:Bool = GroupCallJoinResponse; +//@description Toggles whether new members of a group call can be unmuted only by administrators of the group call. Requires can_manage_calls rights in the corresponding chat and allowed_change_mute_mew_members group call flag +//@group_call_id Group call identifier @mute_new_members New value of the mute_new_members setting +toggleGroupCallMuteNewMembers group_call_id:string mute_new_members:Bool = Ok; + //@description Leaves a group call @group_call_id Group call identifier @source Caller source identifier leaveGroupCall group_call_id:string source:int32 = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index d47596aa36d0becfa9d25fccd7b785b860cd94c0..5a84fa1595a13b0fba1796f844695023d892e0f9 100644 GIT binary patch delta 77 zcmV-T0J8s}y$ig)3xI?Hv;xE#0gJcA83HrCD9QwBs~vQ2XJ>3>M{;j0BOGM)R*ic0W_0bwJ5jX)&jr>#Qz{4 delta 27 jcmdn9k9)yh?uHh|Elfuw8N0S0m1HvByM4-arWNb}q;Lys diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index ea5b7aa52..717b45927 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -103,6 +103,37 @@ class JoinGroupCallQuery : public Td::ResultHandler { } }; +class ToggleGroupCallSettingsQuery : public Td::ResultHandler { + Promise promise_; + + public: + explicit ToggleGroupCallSettingsQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(int32 flags, InputGroupCallId group_call_id, bool join_muted) { + send_query(G()->net_query_creator().create( + telegram_api::phone_toggleGroupCallSettings(flags, group_call_id.get_input_group_call(), join_muted))); + } + + 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 ToggleGroupCallSettingsQuery: " << 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 LeaveGroupCallQuery : public Td::ResultHandler { Promise promise_; @@ -368,6 +399,12 @@ void GroupCallManager::finish_join_group_call(InputGroupCallId group_call_id, ui pending_join_requests_.erase(it); } +void GroupCallManager::toggle_group_call_mute_new_members(InputGroupCallId group_call_id, bool mute_new_members, + Promise &&promise) { + int32 flags = telegram_api::phone_toggleGroupCallSettings::JOIN_MUTED_MASK; + td_->create_handler(std::move(promise))->send(flags, group_call_id, mute_new_members); +} + void GroupCallManager::leave_group_call(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 ee90d9427..ef6408d0f 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -35,6 +35,9 @@ class GroupCallManager : public Actor { int32 source, bool is_muted, Promise> &&promise); + void toggle_group_call_mute_new_members(InputGroupCallId group_call_id, bool mute_new_members, + Promise &&promise); + void leave_group_call(InputGroupCallId group_call_id, int32 source, Promise &&promise); void discard_group_call(InputGroupCallId group_call_id, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index ed57eb6da..bbf8377e8 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6050,6 +6050,14 @@ void Td::on_request(uint64 id, td_api::joinGroupCall &request) { std::move(promise)); } +void Td::on_request(uint64 id, const td_api::toggleGroupCallMuteNewMembers &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_mute_new_members(group_call_id, request.mute_new_members_, std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::leaveGroupCall &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index c36626a48..d4ac1d891 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -696,6 +696,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, td_api::joinGroupCall &request); + void on_request(uint64 id, const td_api::toggleGroupCallMuteNewMembers &request); + void on_request(uint64 id, const td_api::leaveGroupCall &request); void on_request(uint64 id, const td_api::discardGroupCall &request); diff --git a/td/telegram/UpdatesManager.cpp b/td/telegram/UpdatesManager.cpp index b516143a1..4448118f4 100644 --- a/td/telegram/UpdatesManager.cpp +++ b/td/telegram/UpdatesManager.cpp @@ -917,8 +917,6 @@ vector UpdatesManager::get_update_new_group_call_ids(const tel if (group_call_id.is_valid()) { group_call_ids.push_back(group_call_id); - } else { - LOG(ERROR) << "Receive unexpected " << to_string(update); } } } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 5ad4aa610..522e70444 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2844,6 +2844,8 @@ class CliClient final : public Actor { args, td_api::make_object("ufrag", "pwd", std::move(fingerprints)), 123, true)); } else if (op == "jgcc") { send_request(td_api::make_object(args, nullptr, 123, true)); + } else if (op == "tgcmnm" || op == "tgcmnme") { + send_request(td_api::make_object(args, op == "tgcmnme")); } else if (op == "lgc") { send_request(td_api::make_object(args, 123)); } else if (op == "dgc") {