Use add_group_call_participants if possible.

This commit is contained in:
levlam 2021-07-12 21:17:37 +03:00
parent b83b3a45cb
commit 5b3ddfcfc1

View File

@ -1333,13 +1333,10 @@ void GroupCallManager::on_update_group_call_rights(InputGroupCallId input_group_
CHECK(group_call != nullptr && group_call->is_inited); CHECK(group_call != nullptr && group_call->is_inited);
try_load_group_call_administrators(input_group_call_id, group_call->dialog_id); try_load_group_call_administrators(input_group_call_id, group_call->dialog_id);
auto participants_it = group_call_participants_.find(input_group_call_id); auto *group_call_participants = add_group_call_participants(input_group_call_id);
if (participants_it != group_call_participants_.end()) { if (group_call_participants->are_administrators_loaded) {
CHECK(participants_it->second != nullptr);
if (participants_it->second->are_administrators_loaded) {
update_group_call_participants_can_be_muted( update_group_call_participants_can_be_muted(
input_group_call_id, can_manage_group_calls(group_call->dialog_id).is_ok(), participants_it->second.get()); input_group_call_id, can_manage_group_calls(group_call->dialog_id).is_ok(), group_call_participants);
}
} }
} }
@ -1407,12 +1404,9 @@ void GroupCallManager::finish_get_group_call(InputGroupCallId input_group_call_i
} }
process_group_call_participants(input_group_call_id, std::move(call->participants_), version, string(), true, false); process_group_call_participants(input_group_call_id, std::move(call->participants_), version, string(), true, false);
if (need_group_call_participants(input_group_call_id)) { if (need_group_call_participants(input_group_call_id)) {
auto participants_it = group_call_participants_.find(input_group_call_id); auto *group_call_participants = add_group_call_participants(input_group_call_id);
if (participants_it != group_call_participants_.end()) { if (group_call_participants->next_offset.empty()) {
CHECK(participants_it->second != nullptr); group_call_participants->next_offset = std::move(call->participants_next_offset_);
if (participants_it->second->next_offset.empty()) {
participants_it->second->next_offset = std::move(call->participants_next_offset_);
}
} }
} }
@ -1564,12 +1558,9 @@ void GroupCallManager::on_get_group_call_participants(
} }
if (is_load) { if (is_load) {
auto participants_it = group_call_participants_.find(input_group_call_id); auto *group_call_participants = add_group_call_participants(input_group_call_id);
if (participants_it != group_call_participants_.end()) { if (group_call_participants->next_offset == offset) {
CHECK(participants_it->second != nullptr); group_call_participants->next_offset = std::move(participants->next_offset_);
if (participants_it->second->next_offset == offset) {
participants_it->second->next_offset = std::move(participants->next_offset_);
}
} }
if (is_empty || is_sync) { if (is_empty || is_sync) {
@ -1586,9 +1577,7 @@ void GroupCallManager::on_get_group_call_participants(
real_participant_count++; real_participant_count++;
} }
if (is_empty) { if (is_empty) {
auto known_participant_count = participants_it != group_call_participants_.end() auto known_participant_count = static_cast<int32>(group_call_participants->participants.size());
? static_cast<int32>(participants_it->second->participants.size())
: 0;
if (real_participant_count != known_participant_count) { if (real_participant_count != known_participant_count) {
LOG(ERROR) << "Receive participant count " << real_participant_count << ", but know " LOG(ERROR) << "Receive participant count " << real_participant_count << ", but know "
<< known_participant_count << " participants in " << input_group_call_id << " from " << known_participant_count << " participants in " << input_group_call_id << " from "
@ -1995,14 +1984,11 @@ void GroupCallManager::process_group_call_participants(
std::unordered_set<DialogId, DialogIdHash> old_participant_dialog_ids; std::unordered_set<DialogId, DialogIdHash> old_participant_dialog_ids;
if (is_sync) { if (is_sync) {
auto participants_it = group_call_participants_.find(input_group_call_id); auto *group_call_participants = add_group_call_participants(input_group_call_id);
if (participants_it != group_call_participants_.end()) { for (auto &participant : group_call_participants->participants) {
CHECK(participants_it->second != nullptr);
for (auto &participant : participants_it->second->participants) {
old_participant_dialog_ids.insert(participant.dialog_id); old_participant_dialog_ids.insert(participant.dialog_id);
} }
} }
}
auto min_order = GroupCallParticipantOrder::max(); auto min_order = GroupCallParticipantOrder::max();
DialogId debug_min_order_dialog_id; DialogId debug_min_order_dialog_id;
@ -2045,10 +2031,8 @@ void GroupCallManager::process_group_call_participants(
min_order = GroupCallParticipantOrder::min(); min_order = GroupCallParticipantOrder::min();
} }
if (is_sync) { if (is_sync) {
auto participants_it = group_call_participants_.find(input_group_call_id); auto *group_call_participants = add_group_call_participants(input_group_call_id);
if (participants_it != group_call_participants_.end()) { auto &group_participants = group_call_participants->participants;
CHECK(participants_it->second != nullptr);
auto &group_participants = participants_it->second->participants;
for (auto participant_it = group_participants.begin(); participant_it != group_participants.end();) { for (auto participant_it = group_participants.begin(); participant_it != group_participants.end();) {
auto &participant = *participant_it; auto &participant = *participant_it;
if (old_participant_dialog_ids.count(participant.dialog_id) == 0) { if (old_participant_dialog_ids.count(participant.dialog_id) == 0) {
@ -2060,8 +2044,7 @@ void GroupCallManager::process_group_call_participants(
if (participant.is_self) { if (participant.is_self) {
if (participant.order != min_order) { if (participant.order != min_order) {
participant.order = min_order; participant.order = min_order;
send_update_group_call_participant(input_group_call_id, participant, send_update_group_call_participant(input_group_call_id, participant, "process_group_call_participants self");
"process_group_call_participants self");
} }
++participant_it; ++participant_it;
continue; continue;
@ -2069,36 +2052,32 @@ void GroupCallManager::process_group_call_participants(
// not synced user and not self, needs to be deleted // not synced user and not self, needs to be deleted
if (participant.order.is_valid()) { if (participant.order.is_valid()) {
CHECK(participant.order >= participants_it->second->min_order); CHECK(participant.order >= group_call_participants->min_order);
participant.order = GroupCallParticipantOrder(); participant.order = GroupCallParticipantOrder();
send_update_group_call_participant(input_group_call_id, participant, "process_group_call_participants sync"); send_update_group_call_participant(input_group_call_id, participant, "process_group_call_participants sync");
} }
on_remove_group_call_participant(input_group_call_id, participant.dialog_id); on_remove_group_call_participant(input_group_call_id, participant.dialog_id);
participant_it = group_participants.erase(participant_it); participant_it = group_participants.erase(participant_it);
} }
if (participants_it->second->min_order < min_order) { if (group_call_participants->min_order < min_order) {
// if previously known more users, adjust min_order // if previously known more users, adjust min_order
LOG(INFO) << "Decrease min_order from " << participants_it->second->min_order << " to " << min_order << " in " LOG(INFO) << "Decrease min_order from " << group_call_participants->min_order << " to " << min_order << " in "
<< input_group_call_id; << input_group_call_id;
participants_it->second->min_order = min_order; group_call_participants->min_order = min_order;
update_group_call_participants_order(input_group_call_id, can_self_unmute, participants_it->second.get(), update_group_call_participants_order(input_group_call_id, can_self_unmute, group_call_participants,
"decrease min_order"); "decrease min_order");
} }
} }
}
if (is_load) { if (is_load) {
auto participants_it = group_call_participants_.find(input_group_call_id); auto *group_call_participants = add_group_call_participants(input_group_call_id);
if (participants_it != group_call_participants_.end()) { if (group_call_participants->min_order > min_order) {
CHECK(participants_it->second != nullptr); LOG(INFO) << "Increase min_order from " << group_call_participants->min_order << " to " << min_order << " in "
if (participants_it->second->min_order > min_order) {
LOG(INFO) << "Increase min_order from " << participants_it->second->min_order << " to " << min_order << " in "
<< input_group_call_id; << input_group_call_id;
participants_it->second->min_order = min_order; group_call_participants->min_order = min_order;
update_group_call_participants_order(input_group_call_id, can_self_unmute, participants_it->second.get(), update_group_call_participants_order(input_group_call_id, can_self_unmute, group_call_participants,
"increase min_order"); "increase min_order");
} }
} }
}
} }
bool GroupCallManager::update_group_call_participant_can_be_muted(bool can_manage, bool GroupCallManager::update_group_call_participant_can_be_muted(bool can_manage,