Prevent voice chat data updating during join.

This commit is contained in:
levlam 2021-03-07 01:06:51 +03:00
parent c611553ece
commit 0615d1f61d
4 changed files with 26 additions and 21 deletions

View File

@ -551,7 +551,7 @@ void GroupCallManager::on_check_group_call_is_joined_timeout(GroupCallId group_c
auto *group_call = get_group_call(input_group_call_id);
CHECK(group_call != nullptr && group_call->is_inited);
auto audio_source = group_call->audio_source;
if (!group_call->is_joined || pending_join_requests_.count(input_group_call_id) != 0 ||
if (!group_call->is_joined || is_group_call_being_joined(input_group_call_id) ||
check_group_call_is_joined_timeout_.has_timeout(group_call_id.get()) || audio_source == 0) {
return;
}
@ -673,6 +673,10 @@ DialogId GroupCallManager::get_group_call_participant_id(
return DialogId();
}
bool GroupCallManager::is_group_call_being_joined(InputGroupCallId input_group_call_id) const {
return pending_join_requests_.count(input_group_call_id) != 0;
}
GroupCallId GroupCallManager::get_group_call_id(InputGroupCallId input_group_call_id, DialogId dialog_id) {
if (td_->auth_manager_->is_bot() || !input_group_call_id.is_valid()) {
return GroupCallId();
@ -913,7 +917,7 @@ void GroupCallManager::finish_check_group_call_is_joined(InputGroupCallId input_
auto *group_call = get_group_call(input_group_call_id);
CHECK(group_call != nullptr && group_call->is_inited);
CHECK(audio_source != 0);
if (!group_call->is_joined || pending_join_requests_.count(input_group_call_id) != 0 ||
if (!group_call->is_joined || is_group_call_being_joined(input_group_call_id) ||
check_group_call_is_joined_timeout_.has_timeout(group_call->group_call_id.get()) ||
group_call->audio_source != audio_source) {
return;
@ -943,7 +947,7 @@ bool GroupCallManager::need_group_call_participants(InputGroupCallId input_group
if (group_call == nullptr || !group_call->is_inited || !group_call->is_active) {
return false;
}
if (group_call->is_joined || group_call->need_rejoin || pending_join_requests_.count(input_group_call_id) != 0) {
if (group_call->is_joined || group_call->need_rejoin || is_group_call_being_joined(input_group_call_id)) {
return true;
}
return false;
@ -1650,7 +1654,7 @@ void GroupCallManager::join_group_call(GroupCallId group_call_id, DialogId as_di
CHECK(diff == 1);
group_call->participant_count++;
need_update = true;
update_group_call_dialog(group_call, "join_group_call");
update_group_call_dialog(group_call, "join_group_call", true);
}
}
@ -1847,8 +1851,8 @@ void GroupCallManager::process_group_call_after_join_requests(InputGroupCallId i
if (group_call == nullptr || !group_call->is_inited) {
return;
}
if (pending_join_requests_.count(input_group_call_id) != 0 || group_call->need_rejoin) {
LOG(ERROR) << "Failed to process after-join requests: " << pending_join_requests_.count(input_group_call_id) << " "
if (is_group_call_being_joined(input_group_call_id) || group_call->need_rejoin) {
LOG(ERROR) << "Failed to process after-join requests: " << is_group_call_being_joined(input_group_call_id) << " "
<< group_call->need_rejoin;
return;
}
@ -2039,7 +2043,7 @@ void GroupCallManager::set_group_call_participant_is_speaking(GroupCallId group_
return promise.set_value(Unit());
}
if (!group_call->is_joined) {
if (pending_join_requests_.count(input_group_call_id) || group_call->need_rejoin) {
if (is_group_call_being_joined(input_group_call_id) || group_call->need_rejoin) {
group_call->after_join.push_back(
PromiseCreator::lambda([actor_id = actor_id(this), group_call_id, audio_source, is_speaking,
promise = std::move(promise), date](Result<Unit> &&result) mutable {
@ -2121,7 +2125,7 @@ void GroupCallManager::toggle_group_call_participant_is_muted(GroupCallId group_
return promise.set_error(Status::Error(400, "GROUPCALL_JOIN_MISSING"));
}
if (!group_call->is_joined) {
if (pending_join_requests_.count(input_group_call_id) || group_call->need_rejoin) {
if (is_group_call_being_joined(input_group_call_id) || group_call->need_rejoin) {
group_call->after_join.push_back(
PromiseCreator::lambda([actor_id = actor_id(this), group_call_id, dialog_id, is_muted,
promise = std::move(promise)](Result<Unit> &&result) mutable {
@ -2216,7 +2220,7 @@ void GroupCallManager::set_group_call_participant_volume_level(GroupCallId group
return promise.set_error(Status::Error(400, "GROUPCALL_JOIN_MISSING"));
}
if (!group_call->is_joined) {
if (pending_join_requests_.count(input_group_call_id) || group_call->need_rejoin) {
if (is_group_call_being_joined(input_group_call_id) || group_call->need_rejoin) {
group_call->after_join.push_back(
PromiseCreator::lambda([actor_id = actor_id(this), group_call_id, dialog_id, volume_level,
promise = std::move(promise)](Result<Unit> &&result) mutable {
@ -2575,13 +2579,13 @@ InputGroupCallId GroupCallManager::update_group_call(const tl_object_ptr<telegra
}
}
}
update_group_call_dialog(group_call, "update_group_call");
if (!group_call->is_active && group_call_recent_speakers_.erase(group_call->group_call_id) != 0) {
need_update = true;
}
if (!join_params.empty()) {
need_update |= on_join_group_call_response(input_group_call_id, std::move(join_params));
}
update_group_call_dialog(group_call, "update_group_call"); // must be after join response is processed
if (need_update) {
send_update_group_call(group_call, "update_group_call");
}
@ -2772,13 +2776,13 @@ DialogId GroupCallManager::set_group_call_participant_is_speaking_by_source(Inpu
return DialogId();
}
void GroupCallManager::update_group_call_dialog(const GroupCall *group_call, const char *source) {
void GroupCallManager::update_group_call_dialog(const GroupCall *group_call, const char *source, bool force) {
if (!group_call->dialog_id.is_valid()) {
return;
}
td_->messages_manager_->on_update_dialog_group_call(group_call->dialog_id, group_call->is_active,
group_call->participant_count == 0, source);
group_call->participant_count == 0, source, force);
}
vector<td_api::object_ptr<td_api::groupCallRecentSpeaker>> GroupCallManager::get_recent_speakers(

View File

@ -39,6 +39,8 @@ class GroupCallManager : public Actor {
DialogId get_group_call_participant_id(const td_api::object_ptr<td_api::MessageSender> &message_sender);
bool is_group_call_being_joined(InputGroupCallId input_group_call_id) const;
GroupCallId get_group_call_id(InputGroupCallId input_group_call_id, DialogId dialog_id);
void create_voice_chat(DialogId dialog_id, Promise<GroupCallId> &&promise);
@ -226,7 +228,7 @@ class GroupCallManager : public Actor {
void try_clear_group_call_participants(InputGroupCallId input_group_call_id);
void update_group_call_dialog(const GroupCall *group_call, const char *source);
void update_group_call_dialog(const GroupCall *group_call, const char *source, bool force = false);
vector<td_api::object_ptr<td_api::groupCallRecentSpeaker>> get_recent_speakers(const GroupCall *group_call,
bool for_update);

View File

@ -11063,10 +11063,6 @@ void MessagesManager::on_dialog_deleted(DialogId dialog_id, Promise<Unit> &&prom
}
void MessagesManager::on_update_dialog_group_call_rights(DialogId dialog_id) {
if (td_->auth_manager_->is_bot()) {
return;
}
auto d = get_dialog(dialog_id);
if (d == nullptr) {
// nothing to do
@ -29712,12 +29708,11 @@ void MessagesManager::do_set_dialog_folder_id(Dialog *d, FolderId folder_id) {
}
void MessagesManager::on_update_dialog_group_call(DialogId dialog_id, bool has_active_group_call,
bool is_group_call_empty, const char *source) {
bool is_group_call_empty, const char *source, bool force) {
LOG(INFO) << "Update voice chat in " << dialog_id << " with has_active_voice_chat = " << has_active_group_call
<< " and is_voice_chat_empty = " << is_group_call_empty << " from " << source;
CHECK(dialog_id.is_valid());
Dialog *d = get_dialog(dialog_id); // must not create the Dialog, because is called from on_get_chat
Dialog *d = get_dialog(dialog_id); // must not create the Dialog, because it is called from on_get_chat
if (d == nullptr) {
LOG(INFO) << "Can't find " << dialog_id;
pending_dialog_group_call_updates_[dialog_id] = {has_active_group_call, is_group_call_empty};
@ -29730,6 +29725,10 @@ void MessagesManager::on_update_dialog_group_call(DialogId dialog_id, bool has_a
if (d->has_active_group_call == has_active_group_call && d->is_group_call_empty == is_group_call_empty) {
return;
}
if (!force && d->active_group_call_id.is_valid() &&
td_->group_call_manager_->is_group_call_being_joined(d->active_group_call_id)) {
return;
}
if (d->has_active_group_call && !has_active_group_call && d->active_group_call_id.is_valid()) {
d->active_group_call_id = InputGroupCallId();

View File

@ -286,7 +286,7 @@ class MessagesManager : public Actor {
void on_update_dialog_folder_id(DialogId dialog_id, FolderId folder_id);
void on_update_dialog_group_call(DialogId dialog_id, bool has_active_group_call, bool is_group_call_empty,
const char *source);
const char *source, bool force = false);
void on_update_dialog_group_call_id(DialogId dialog_id, InputGroupCallId input_group_call_id);