From 3e351a09468d89fe1109629a58f10ab6d04b6aa6 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 9 Jul 2021 18:36:35 +0300 Subject: [PATCH] Use getGroupCall to sync participants. --- td/telegram/GroupCallManager.cpp | 41 ++++++++++++++++++++++---------- td/telegram/GroupCallManager.h | 3 ++- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index 93fe9d726..1db5f28b9 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -1896,26 +1896,43 @@ void GroupCallManager::sync_group_call_participants(InputGroupCallId input_group group_call->need_syncing_participants = false; LOG(INFO) << "Force participants synchronization in " << input_group_call_id << " from " << group_call->dialog_id; - auto promise = PromiseCreator::lambda([actor_id = actor_id(this), input_group_call_id](Result &&result) { - if (result.is_error()) { - send_closure(actor_id, &GroupCallManager::on_sync_group_call_participants_failed, input_group_call_id); - } + auto promise = PromiseCreator::lambda([actor_id = actor_id(this), input_group_call_id]( + Result> &&result) { + send_closure(actor_id, &GroupCallManager::on_sync_group_call_participants, input_group_call_id, std::move(result)); }); - td_->create_handler(std::move(promise))->send(input_group_call_id, string(), 100); + + td_->create_handler(std::move(promise))->send(input_group_call_id, 100); } -void GroupCallManager::on_sync_group_call_participants_failed(InputGroupCallId input_group_call_id) { +void GroupCallManager::on_sync_group_call_participants(InputGroupCallId input_group_call_id, + Result> &&result) { if (G()->close_flag() || !need_group_call_participants(input_group_call_id)) { return; } - auto group_call = get_group_call(input_group_call_id); - CHECK(group_call != nullptr && group_call->is_inited); - CHECK(group_call->syncing_participants); - group_call->syncing_participants = false; + if (result.is_error()) { + auto group_call = get_group_call(input_group_call_id); + CHECK(group_call != nullptr && group_call->is_inited); + CHECK(group_call->syncing_participants); + group_call->syncing_participants = false; - sync_participants_timeout_.add_timeout_in(group_call->group_call_id.get(), - group_call->need_syncing_participants ? 0.0 : 1.0); + sync_participants_timeout_.add_timeout_in(group_call->group_call_id.get(), + group_call->need_syncing_participants ? 0.0 : 1.0); + return; + } + + auto call = result.move_as_ok(); + if (call->call_->get_id() == telegram_api::groupCall::ID) { + auto *group_call = static_cast(call->call_.get()); + auto participants = make_tl_object( + group_call->participants_count_, std::move(call->participants_), std::move(call->participants_next_offset_), + std::move(call->chats_), std::move(call->users_), group_call->version_); + on_get_group_call_participants(input_group_call_id, std::move(participants), true, string()); + } + + if (update_group_call(call->call_, DialogId()) != input_group_call_id) { + LOG(ERROR) << "Expected " << input_group_call_id << ", but received " << to_string(result.ok()); + } } GroupCallParticipantOrder GroupCallManager::get_real_participant_order( diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 8e6b913e4..5feef54c1 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -225,7 +225,8 @@ class GroupCallManager final : public Actor { void sync_group_call_participants(InputGroupCallId input_group_call_id); - void on_sync_group_call_participants_failed(InputGroupCallId input_group_call_id); + void on_sync_group_call_participants(InputGroupCallId input_group_call_id, + Result> &&result); GroupCallParticipantOrder get_real_participant_order(bool can_self_unmute, const GroupCallParticipant &participant, const GroupCallParticipants *participants) const;