Apply volume_by_admin flag in voice chats.

This commit is contained in:
John Preston 2021-02-09 12:58:19 +04:00
parent d60a89f354
commit 39742d22d9
4 changed files with 18 additions and 2 deletions

View file

@ -377,10 +377,15 @@ void GroupCall::applySelfInCallLocally() {
const auto lastActive = (i != end(participants)) const auto lastActive = (i != end(participants))
? i->lastActive ? i->lastActive
: TimeId(0); : TimeId(0);
const auto volume = (i != end(participants))
? i->volume
: Group::kDefaultVolume;
const auto canSelfUnmute = (muted() != MuteState::ForceMuted); const auto canSelfUnmute = (muted() != MuteState::ForceMuted);
const auto flags = (canSelfUnmute ? Flag::f_can_self_unmute : Flag(0)) const auto flags = (canSelfUnmute ? Flag::f_can_self_unmute : Flag(0))
| (lastActive ? Flag::f_active_date : Flag(0)) | (lastActive ? Flag::f_active_date : Flag(0))
| (_mySsrc ? Flag(0) : Flag::f_left) | (_mySsrc ? Flag(0) : Flag::f_left)
| Flag::f_volume // Without flag the volume is reset to 100%.
| Flag::f_volume_by_admin // Self volume can only be set by admin.
| ((muted() != MuteState::Active) ? Flag::f_muted : Flag(0)); | ((muted() != MuteState::Active) ? Flag::f_muted : Flag(0));
call->applyUpdateChecked( call->applyUpdateChecked(
MTP_updateGroupCallParticipants( MTP_updateGroupCallParticipants(
@ -393,7 +398,7 @@ void GroupCall::applySelfInCallLocally() {
MTP_int(date), MTP_int(date),
MTP_int(lastActive), MTP_int(lastActive),
MTP_int(_mySsrc), MTP_int(_mySsrc),
MTP_int(Group::kDefaultVolume))), // volume MTP_int(volume))),
MTP_int(0)).c_updateGroupCallParticipants()); MTP_int(0)).c_updateGroupCallParticipants());
} }
@ -410,6 +415,9 @@ void GroupCall::applyParticipantLocally(
using Flag = MTPDgroupCallParticipant::Flag; using Flag = MTPDgroupCallParticipant::Flag;
const auto flags = (canSelfUnmute ? Flag::f_can_self_unmute : Flag(0)) const auto flags = (canSelfUnmute ? Flag::f_can_self_unmute : Flag(0))
| Flag::f_volume // Without flag the volume is reset to 100%. | Flag::f_volume // Without flag the volume is reset to 100%.
| ((participant->applyVolumeFromMin && !volume)
? Flag::f_volume_by_admin
: Flag(0))
| (participant->lastActive ? Flag::f_active_date : Flag(0)) | (participant->lastActive ? Flag::f_active_date : Flag(0))
| (!mute | (!mute
? Flag(0) ? Flag(0)

View file

@ -19,6 +19,7 @@ struct MuteRequest {
bool mute = false; bool mute = false;
bool locallyOnly = false; bool locallyOnly = false;
}; };
struct VolumeRequest { struct VolumeRequest {
not_null<UserData*> user; not_null<UserData*> user;
int volume = kDefaultVolume; int volume = kDefaultVolume;

View file

@ -276,9 +276,14 @@ void GroupCall::applyParticipantsSlice(
&& ((was ? was->speaking : false) && ((was ? was->speaking : false)
|| (!amInCall || (!amInCall
&& (lastActive + speakingAfterActive > now))); && (lastActive + speakingAfterActive > now)));
const auto volume = (was && data.is_min()) const auto volume = (was
&& !was->applyVolumeFromMin
&& data.is_min())
? was->volume ? was->volume
: data.vvolume().value_or(Calls::Group::kDefaultVolume); : data.vvolume().value_or(Calls::Group::kDefaultVolume);
const auto applyVolumeFromMin = (was && data.is_min())
? was->applyVolumeFromMin
: (data.is_min() || data.is_volume_by_admin());
const auto mutedByMe = (was && data.is_min()) const auto mutedByMe = (was && data.is_min())
? was->mutedByMe ? was->mutedByMe
: data.is_muted_by_you(); : data.is_muted_by_you();
@ -290,6 +295,7 @@ void GroupCall::applyParticipantsSlice(
.lastActive = lastActive, .lastActive = lastActive,
.ssrc = uint32(data.vsource().v), .ssrc = uint32(data.vsource().v),
.volume = volume, .volume = volume,
.applyVolumeFromMin = applyVolumeFromMin,
.speaking = canSelfUnmute && (was ? was->speaking : false), .speaking = canSelfUnmute && (was ? was->speaking : false),
.muted = data.is_muted(), .muted = data.is_muted(),
.mutedByMe = mutedByMe, .mutedByMe = mutedByMe,

View file

@ -38,6 +38,7 @@ public:
TimeId lastActive = 0; TimeId lastActive = 0;
uint32 ssrc = 0; uint32 ssrc = 0;
int volume = 0; int volume = 0;
bool applyVolumeFromMin = true;
bool sounding = false; bool sounding = false;
bool speaking = false; bool speaking = false;
bool muted = false; bool muted = false;