Synchronize group call participant_count with known number of participants.

This commit is contained in:
levlam 2021-03-19 04:02:53 +03:00
parent cebcdbd88b
commit 78f5b24f35
2 changed files with 45 additions and 29 deletions

View File

@ -1308,17 +1308,17 @@ void GroupCallManager::on_get_group_call_participants(
real_participant_count = known_participant_count;
}
}
if (!is_empty && is_sync && group_call->loaded_all_participants && real_participant_count > 50) {
group_call->loaded_all_participants = false;
need_update = true;
}
if (real_participant_count != group_call->participant_count) {
if (!is_sync) {
LOG(ERROR) << "Have participant count " << group_call->participant_count << " instead of "
<< real_participant_count << " in " << input_group_call_id << " from " << group_call->dialog_id;
}
set_group_call_participant_count(group_call, real_participant_count, "on_get_group_call_participants");
need_update = true;
}
if (!is_empty && is_sync && group_call->loaded_all_participants && group_call->participant_count > 50) {
group_call->loaded_all_participants = false;
need_update = true;
need_update |=
set_group_call_participant_count(group_call, real_participant_count, "on_get_group_call_participants");
}
if (process_pending_group_call_participant_updates(input_group_call_id)) {
need_update = false;
@ -1399,11 +1399,8 @@ void GroupCallManager::on_update_group_call_participants(
}
if (group_call != nullptr && group_call->is_inited && group_call->is_active && group_call->version == -1) {
if (diff != 0 && (group_call->participant_count != 0 || diff > 0)) {
set_group_call_participant_count(group_call, group_call->participant_count + diff,
"on_update_group_call_participants");
need_update = true;
}
need_update |= set_group_call_participant_count(group_call, group_call->participant_count + diff,
"on_update_group_call_participants");
}
if (need_update) {
send_update_group_call(group_call, "on_update_group_call_participants");
@ -1572,12 +1569,8 @@ bool GroupCallManager::process_pending_group_call_participant_updates(InputGroup
sync_participants_timeout_.cancel_timeout(group_call->group_call_id.get());
}
bool need_update = false;
if (diff != 0 && (group_call->participant_count != 0 || diff > 0)) {
set_group_call_participant_count(group_call, group_call->participant_count + diff,
"process_pending_group_call_participant_updates");
need_update = true;
}
bool need_update = set_group_call_participant_count(group_call, group_call->participant_count + diff,
"process_pending_group_call_participant_updates");
if (is_left && group_call->is_joined) {
on_group_call_left_impl(group_call, need_rejoin);
need_update = true;
@ -2164,8 +2157,8 @@ void GroupCallManager::join_group_call(GroupCallId group_call_id, DialogId as_di
int diff = process_group_call_participant(input_group_call_id, std::move(participant));
if (diff != 0) {
CHECK(diff == 1);
set_group_call_participant_count(group_call, group_call->participant_count + diff, "join_group_call", true);
need_update = true;
need_update |=
set_group_call_participant_count(group_call, group_call->participant_count + diff, "join_group_call", true);
}
}
@ -3422,10 +3415,7 @@ InputGroupCallId GroupCallManager::update_group_call(const tl_object_ptr<telegra
// if we know group call version, then update participants only by corresponding updates
on_receive_group_call_version(input_group_call_id, call.version);
} else {
if (call.participant_count != group_call->participant_count) {
set_group_call_participant_count(group_call, call.participant_count, "update_group_call");
need_update = true;
}
need_update |= set_group_call_participant_count(group_call, call.participant_count, "update_group_call");
if (need_group_call_participants(input_group_call_id, group_call) && !join_params.empty() &&
group_call->version == -1) {
LOG(INFO) << "Init " << call.group_call_id << " version to " << call.version;
@ -3435,7 +3425,7 @@ InputGroupCallId GroupCallManager::update_group_call(const tl_object_ptr<telegra
}
}
}
} else if (call.version == group_call->version && call.participant_count != group_call->participant_count) {
} else if (call.version == group_call->version) {
set_group_call_participant_count(group_call, call.participant_count, "update_group_call fix");
need_update = true;
}
@ -3643,18 +3633,44 @@ DialogId GroupCallManager::set_group_call_participant_is_speaking_by_source(Inpu
return DialogId();
}
void GroupCallManager::set_group_call_participant_count(GroupCall *group_call, int32 count, const char *source,
bool GroupCallManager::set_group_call_participant_count(GroupCall *group_call, int32 count, const char *source,
bool force_update) {
CHECK(group_call != nullptr);
CHECK(group_call->is_inited);
if (group_call->participant_count == count) {
return false;
}
LOG(DEBUG) << "Set " << group_call->group_call_id << " participant count to " << count << " from " << source;
if (count < 0) {
LOG(ERROR) << "Participant count became negative in " << group_call->group_call_id << " in "
<< group_call->dialog_id << " from " << source;
group_call->participant_count = 0;
} else {
group_call->participant_count = count;
count = 0;
}
auto input_group_call_id = get_input_group_call_id(group_call->group_call_id).ok();
if (need_group_call_participants(input_group_call_id, group_call)) {
auto known_participant_count =
static_cast<int32>(add_group_call_participants(input_group_call_id)->participants.size());
if (count < known_participant_count) {
if (group_call->is_joined) {
LOG(ERROR) << "Participant count became " << count << " from " << source << ", which is less than known "
<< known_participant_count << " number of participants in " << input_group_call_id << " from "
<< group_call->dialog_id;
}
count = known_participant_count;
} else if (group_call->loaded_all_participants && count > known_participant_count) {
count = known_participant_count;
}
}
if (group_call->participant_count == count) {
return false;
}
group_call->participant_count = count;
update_group_call_dialog(group_call, source, force_update);
return true;
}
void GroupCallManager::update_group_call_dialog(const GroupCall *group_call, const char *source, bool force) {

View File

@ -277,7 +277,7 @@ class GroupCallManager : public Actor {
void try_clear_group_call_participants(InputGroupCallId input_group_call_id);
void set_group_call_participant_count(GroupCall *group_call, int32 count, const char *source,
bool set_group_call_participant_count(GroupCall *group_call, int32 count, const char *source,
bool force_update = false);
void update_group_call_dialog(const GroupCall *group_call, const char *source, bool force);