Support muting group call participants for self.

This commit is contained in:
levlam 2020-12-31 02:48:45 +03:00
parent 91e5b9e677
commit 7bf916f4f5
5 changed files with 41 additions and 26 deletions

View File

@ -2102,12 +2102,14 @@ groupCallJoinResponse payload:groupCallPayload candidates:vector<groupCallJoinRe
//@user_id Identifier of the user
//@source User's synchronization source
//@is_speaking True, if the participant is speaking as set by setGroupCallParticipantIsSpeaking
//@can_be_muted True, if the current user can mute the participant
//@can_be_unmuted True, if the current user can allow the participant to unmute themself or unmute the participant (only for self)
//@can_be_muted_for_all_users True, if the current user can mute the participant for all other group call participants
//@can_be_unmuted_for_all_users True, if the current user can allow the participant to unmute themself or unmute the participant (if the participant is the current user)
//@can_be_muted_only_for_self True, if the current user can mute the participant only for self
//@can_be_unmuted_only_for_self True, if the current user can unmute the participant for self
//@is_muted True, if the participant is muted
//@can_unmute_self True, if the participant can unmute themself
//@order User's order in the group call participant list. The bigger is order, the higher is user in the list. If order is 0, the user must be removed from the participant list
groupCallParticipant user_id:int32 source:int32 is_speaking:Bool can_be_muted:Bool can_be_unmuted:Bool is_muted:Bool can_unmute_self:Bool order:int64 = GroupCallParticipant;
groupCallParticipant user_id:int32 source:int32 is_speaking:Bool can_be_muted_for_all_users:Bool can_be_unmuted_for_all_users:Bool can_be_muted_only_for_self:Bool can_be_unmuted_only_for_self:Bool is_muted:Bool can_unmute_self:Bool order:int64 = GroupCallParticipant;
//@class CallProblem @description Describes the exact type of a problem with a call

Binary file not shown.

View File

@ -1768,12 +1768,8 @@ void GroupCallManager::toggle_group_call_participant_is_muted(GroupCallId group_
return promise.set_error(Status::Error(400, "Have no access to the user"));
}
if (user_id != td_->contacts_manager_->get_my_id()) {
TRY_STATUS_PROMISE(promise, can_manage_group_calls(group_call->dialog_id));
} else {
if (!is_muted && !group_call->can_self_unmute) {
return promise.set_error(Status::Error(400, "Can't unmute self"));
}
if (user_id == td_->contacts_manager_->get_my_id() && !is_muted && !group_call->can_self_unmute) {
return promise.set_error(Status::Error(400, "Can't unmute self"));
}
td_->create_handler<EditGroupCallMemberQuery>(std::move(promise))->send(input_group_call_id, user_id, is_muted);

View File

@ -18,6 +18,7 @@ GroupCallParticipant::GroupCallParticipant(const tl_object_ptr<telegram_api::gro
source = participant->source_;
is_muted = participant->muted_;
can_self_unmute = participant->can_self_unmute_;
is_muted_only_for_self = participant->muted_by_you_;
if (!participant->left_) {
joined_date = participant->date_;
if ((participant->flags_ & telegram_api::groupCallParticipant::ACTIVE_DATE_MASK) != 0) {
@ -37,26 +38,35 @@ bool GroupCallParticipant::is_versioned_update(const tl_object_ptr<telegram_api:
}
bool GroupCallParticipant::update_can_be_muted(bool can_manage, bool is_self, bool is_admin) {
bool new_can_be_muted = false;
bool new_can_be_unmuted = false;
bool new_can_be_muted_for_all_users = false;
bool new_can_be_unmuted_for_all_users = false;
bool new_can_be_muted_only_for_self = !can_manage && !is_muted_only_for_self;
bool new_can_be_unmuted_only_for_self = !can_manage && is_muted_only_for_self;
if (is_self) {
// current user can be muted if !is_muted; after that is_muted && can_self_unmute
// current user can be unmuted if is_muted && can_self_unmute; after that !is_muted
new_can_be_muted = !is_muted;
new_can_be_unmuted = is_muted && can_self_unmute;
new_can_be_muted_for_all_users = !is_muted;
new_can_be_unmuted_for_all_users = is_muted && can_self_unmute;
new_can_be_muted_only_for_self = false;
new_can_be_unmuted_only_for_self = false;
} else if (is_admin) {
// admin user can be muted if can_manage && !is_muted; after that is_muted && can_self_unmute
// admin user can't be unmuted
new_can_be_muted = can_manage && !is_muted;
new_can_be_muted_for_all_users = can_manage && !is_muted;
} else {
// other user can be muted if can_manage; after that is_muted && !can_self_unmute
// other user can be unmuted if can_manage && is_muted && !can_self_unmute; after that is_muted && can_self_unmute
new_can_be_muted = can_manage && (!is_muted || can_self_unmute);
new_can_be_unmuted = can_manage && is_muted && !can_self_unmute;
// other users can be muted if can_manage; after that is_muted && !can_self_unmute
// other users can be unmuted if can_manage && is_muted && !can_self_unmute; after that is_muted && can_self_unmute
new_can_be_muted_for_all_users = can_manage && (!is_muted || can_self_unmute);
new_can_be_unmuted_for_all_users = can_manage && is_muted && !can_self_unmute;
}
if (new_can_be_muted != can_be_muted || new_can_be_unmuted != can_be_unmuted) {
can_be_muted = new_can_be_muted;
can_be_unmuted = new_can_be_unmuted;
if (new_can_be_muted_for_all_users != can_be_muted_for_all_users ||
new_can_be_unmuted_for_all_users != can_be_unmuted_for_all_users ||
new_can_be_muted_only_for_self != can_be_muted_only_for_self ||
new_can_be_unmuted_only_for_self != can_be_unmuted_only_for_self) {
can_be_muted_for_all_users = new_can_be_muted_for_all_users;
can_be_unmuted_for_all_users = new_can_be_unmuted_for_all_users;
can_be_muted_only_for_self = new_can_be_muted_only_for_self;
can_be_unmuted_only_for_self = new_can_be_unmuted_only_for_self;
return true;
}
return false;
@ -70,12 +80,16 @@ td_api::object_ptr<td_api::groupCallParticipant> GroupCallParticipant::get_group
return td_api::make_object<td_api::groupCallParticipant>(
contacts_manager->get_user_id_object(user_id, "get_group_call_participant_object"), source, is_speaking,
can_be_muted, can_be_unmuted, is_muted, can_self_unmute, order);
can_be_muted_for_all_users, can_be_unmuted_for_all_users, can_be_muted_only_for_self,
can_be_unmuted_only_for_self, is_muted, can_self_unmute, order);
}
bool operator==(const GroupCallParticipant &lhs, const GroupCallParticipant &rhs) {
return lhs.user_id == rhs.user_id && lhs.source == rhs.source && lhs.can_be_muted == rhs.can_be_muted &&
lhs.can_be_unmuted == rhs.can_be_unmuted && lhs.is_muted == rhs.is_muted &&
return lhs.user_id == rhs.user_id && lhs.source == rhs.source &&
lhs.can_be_muted_for_all_users == rhs.can_be_muted_for_all_users &&
lhs.can_be_unmuted_for_all_users == rhs.can_be_unmuted_for_all_users &&
lhs.can_be_muted_only_for_self == rhs.can_be_muted_only_for_self &&
lhs.can_be_unmuted_only_for_self == rhs.can_be_unmuted_only_for_self && lhs.is_muted == rhs.is_muted &&
lhs.can_self_unmute == rhs.can_self_unmute && lhs.is_speaking == rhs.is_speaking && lhs.order == rhs.order;
}

View File

@ -24,9 +24,12 @@ struct GroupCallParticipant {
int32 active_date = 0;
bool is_muted = false;
bool can_self_unmute = false;
bool is_muted_only_for_self = false;
bool can_be_muted = false;
bool can_be_unmuted = false;
bool can_be_muted_for_all_users = false;
bool can_be_unmuted_for_all_users = false;
bool can_be_muted_only_for_self = false;
bool can_be_unmuted_only_for_self = false;
bool is_just_joined = false;
bool is_speaking = false;