From 06409d68f5b62ccbaabb0ebc76d75f34490e14de Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 6 Jun 2021 03:21:34 +0300 Subject: [PATCH] Update order of group call participants after min_order is decreased. --- td/telegram/GroupCallManager.cpp | 46 +++++++++++++++----------------- td/telegram/GroupCallManager.h | 3 +++ 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/td/telegram/GroupCallManager.cpp b/td/telegram/GroupCallManager.cpp index d2cadf583..713b971cb 100644 --- a/td/telegram/GroupCallManager.cpp +++ b/td/telegram/GroupCallManager.cpp @@ -950,16 +950,8 @@ void GroupCallManager::on_update_group_call_participant_order_timeout(GroupCallI bool can_self_unmute = get_group_call_can_self_unmute(input_group_call_id); auto *participants = add_group_call_participants(input_group_call_id); - for (auto &participant : participants->participants) { - auto new_order = get_real_participant_order(can_self_unmute, participant, participants); - if (new_order != participant.order) { - participant.order = new_order; - send_update_group_call_participant(input_group_call_id, participant, - "on_update_group_call_participant_order_timeout"); - } - } - update_group_call_participant_order_timeout_.set_timeout_in(group_call_id.get(), - UPDATE_GROUP_CALL_PARTICIPANT_ORDER_TIMEOUT); + update_group_call_participants_order(input_group_call_id, can_self_unmute, participants, + "on_update_group_call_participant_order_timeout"); } void GroupCallManager::on_check_group_call_is_joined_timeout_callback(void *group_call_manager_ptr, @@ -2047,6 +2039,8 @@ void GroupCallManager::process_group_call_participants( LOG(INFO) << "Decrease min_order from " << participants_it->second->min_order << " to " << min_order << " in " << input_group_call_id; participants_it->second->min_order = min_order; + update_group_call_participants_order(input_group_call_id, can_self_unmute, participants_it->second.get(), + "decrease min_order"); } } } @@ -2058,20 +2052,8 @@ void GroupCallManager::process_group_call_participants( LOG(INFO) << "Increase min_order from " << participants_it->second->min_order << " to " << min_order << " in " << input_group_call_id; participants_it->second->min_order = min_order; - - for (auto &participant : participants_it->second->participants) { - auto new_order = get_real_participant_order(can_self_unmute, participant, participants_it->second.get()); - if (new_order != participant.order) { - participant.order = new_order; - send_update_group_call_participant(input_group_call_id, participant, - "process_group_call_participants load"); - } - } - - auto *group_call = get_group_call(input_group_call_id); - CHECK(group_call != nullptr && group_call->is_inited); - update_group_call_participant_order_timeout_.set_timeout_in(group_call->group_call_id.get(), - UPDATE_GROUP_CALL_PARTICIPANT_ORDER_TIMEOUT); + update_group_call_participants_order(input_group_call_id, can_self_unmute, participants_it->second.get(), + "increase min_order"); } } } @@ -2098,6 +2080,22 @@ void GroupCallManager::update_group_call_participants_can_be_muted(InputGroupCal } } +void GroupCallManager::update_group_call_participants_order(InputGroupCallId input_group_call_id, bool can_self_unmute, + GroupCallParticipants *participants, const char *source) { + for (auto &participant : participants->participants) { + auto new_order = get_real_participant_order(can_self_unmute, participant, participants); + if (new_order != participant.order) { + participant.order = new_order; + send_update_group_call_participant(input_group_call_id, participant, "process_group_call_participants load"); + } + } + + auto *group_call = get_group_call(input_group_call_id); + CHECK(group_call != nullptr && group_call->is_inited); + update_group_call_participant_order_timeout_.set_timeout_in(group_call->group_call_id.get(), + UPDATE_GROUP_CALL_PARTICIPANT_ORDER_TIMEOUT); +} + void GroupCallManager::process_my_group_call_participant(InputGroupCallId input_group_call_id, GroupCallParticipant &&participant) { CHECK(participant.is_valid()); diff --git a/td/telegram/GroupCallManager.h b/td/telegram/GroupCallManager.h index 9e77e257e..5ad5aca76 100644 --- a/td/telegram/GroupCallManager.h +++ b/td/telegram/GroupCallManager.h @@ -243,6 +243,9 @@ class GroupCallManager : public Actor { void update_group_call_participants_can_be_muted(InputGroupCallId input_group_call_id, bool can_manage, GroupCallParticipants *participants); + void update_group_call_participants_order(InputGroupCallId input_group_call_id, bool can_self_unmute, + GroupCallParticipants *participants, const char *source); + int process_group_call_participant(InputGroupCallId group_call_id, GroupCallParticipant &&participant); void on_add_group_call_participant(InputGroupCallId input_group_call_id, DialogId participant_dialog_id);