Improve mute/raise_hand saving.

This commit is contained in:
John Preston 2021-03-09 14:05:02 +04:00
parent 22aa57ad6f
commit 4d8ac05d28
2 changed files with 25 additions and 15 deletions

View file

@ -188,7 +188,8 @@ GroupCall::GroupCall(
if (_instance) { if (_instance) {
updateInstanceMuteState(); updateInstanceMuteState();
} }
if (_mySsrc && !_initialMuteStateSent) { if (_mySsrc
&& (!_initialMuteStateSent || state == MuteState::Active)) {
_initialMuteStateSent = true; _initialMuteStateSent = true;
maybeSendMutedUpdate(previous); maybeSendMutedUpdate(previous);
} }
@ -648,7 +649,10 @@ void GroupCall::setMuted(MuteState mute) {
void GroupCall::setMutedAndUpdate(MuteState mute) { void GroupCall::setMutedAndUpdate(MuteState mute) {
const auto was = muted(); const auto was = muted();
const auto send = _initialMuteStateSent;
// Active state is sent from _muted changes,
// because it may be set delayed, after permissions request, not now.
const auto send = _initialMuteStateSent && (mute != MuteState::Active);
setMuted(mute); setMuted(mute);
if (send) { if (send) {
maybeSendMutedUpdate(was); maybeSendMutedUpdate(was);
@ -1238,28 +1242,30 @@ void GroupCall::setInstanceMode(InstanceMode mode) {
} }
void GroupCall::maybeSendMutedUpdate(MuteState previous) { void GroupCall::maybeSendMutedUpdate(MuteState previous) {
// Send only Active <-> !Active changes. // Send Active <-> !Active or ForceMuted <-> RaisedHand changes.
const auto now = muted(); const auto now = muted();
const auto wasActive = (previous == MuteState::Active); if ((previous == MuteState::Active && now == MuteState::Muted)
const auto nowActive = (now == MuteState::Active); || (now == MuteState::Active
if ((wasActive && now == MuteState::Muted)
|| (nowActive
&& (previous == MuteState::Muted && (previous == MuteState::Muted
|| previous == MuteState::PushToTalk)) || previous == MuteState::PushToTalk))) {
|| (now == MuteState::ForceMuted sendSelfUpdate(SendUpdateType::Mute);
} else if ((now == MuteState::ForceMuted
&& previous == MuteState::RaisedHand) && previous == MuteState::RaisedHand)
|| (now == MuteState::RaisedHand || (now == MuteState::RaisedHand
&& previous == MuteState::ForceMuted)) { && previous == MuteState::ForceMuted)) {
sendMutedUpdate(); sendSelfUpdate(SendUpdateType::RaiseHand);
} }
} }
void GroupCall::sendMutedUpdate() { void GroupCall::sendSelfUpdate(SendUpdateType type) {
_api.request(_updateMuteRequestId).cancel(); _api.request(_updateMuteRequestId).cancel();
using Flag = MTPphone_EditGroupCallParticipant::Flag; using Flag = MTPphone_EditGroupCallParticipant::Flag;
_updateMuteRequestId = _api.request(MTPphone_EditGroupCallParticipant( _updateMuteRequestId = _api.request(MTPphone_EditGroupCallParticipant(
MTP_flags(((muted() != MuteState::Active) ? Flag::f_muted : Flag(0)) MTP_flags((type == SendUpdateType::RaiseHand)
| Flag::f_raise_hand), ? Flag::f_raise_hand
: (muted() != MuteState::Active)
? Flag::f_muted
: Flag(0)),
inputCall(), inputCall(),
_joinAs->input, _joinAs->input,
MTP_int(100000), // volume MTP_int(100000), // volume

View file

@ -202,6 +202,10 @@ private:
Rtc, Rtc,
Stream, Stream,
}; };
enum class SendUpdateType {
Mute,
RaiseHand,
};
void handleRequestError(const RPCError &error); void handleRequestError(const RPCError &error);
void handleControllerError(const QString &error); void handleControllerError(const QString &error);
@ -211,7 +215,7 @@ private:
void setState(State state); void setState(State state);
void finish(FinishType type); void finish(FinishType type);
void maybeSendMutedUpdate(MuteState previous); void maybeSendMutedUpdate(MuteState previous);
void sendMutedUpdate(); void sendSelfUpdate(SendUpdateType type);
void updateInstanceMuteState(); void updateInstanceMuteState();
void updateInstanceVolumes(); void updateInstanceVolumes();
void applyMeInCallLocally(); void applyMeInCallLocally();