From f3e6f5e7728013365606b40a4df673e60d29a4cf Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 26 May 2021 15:12:00 +0400 Subject: [PATCH] Cancel outgoing video when muted by admin. --- Telegram/SourceFiles/calls/calls_top_bar.cpp | 3 +- .../calls/group/calls_group_call.cpp | 34 +++++++++++++------ .../calls/group/calls_group_call.h | 1 + .../calls/group/calls_group_panel.cpp | 13 +++++-- .../calls/group/calls_group_panel.h | 1 + 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/Telegram/SourceFiles/calls/calls_top_bar.cpp b/Telegram/SourceFiles/calls/calls_top_bar.cpp index 8675e3b92..99c3ea21b 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.cpp +++ b/Telegram/SourceFiles/calls/calls_top_bar.cpp @@ -280,8 +280,7 @@ void TopBar::initControls() { if (const auto call = _call.get()) { call->setMuted(!call->muted()); } else if (const auto group = _groupCall.get()) { - if (group->muted() == MuteState::ForceMuted - || group->muted() == MuteState::RaisedHand) { + if (group->mutedByAdmin()) { Ui::Toast::Show(tr::lng_group_call_force_muted_sub(tr::now)); } else { group->setMuted((group->muted() == MuteState::Muted) diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index 50ca9d3a7..069819272 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -467,8 +467,16 @@ QString GroupCall::screenSharingDeviceId() const { return isSharingScreen() ? _screenDeviceId : QString(); } +bool GroupCall::mutedByAdmin() const { + const auto mute = muted(); + return mute == MuteState::ForceMuted || mute == MuteState::RaisedHand; +} + void GroupCall::toggleVideo(bool active) { - if (!_instance || !_id) { + if (!_instance + || !_id + || (active && mutedByAdmin()) + || (!active && !_cameraOutgoing)) { return; } ensureOutgoingVideo(); @@ -481,6 +489,12 @@ void GroupCall::toggleVideo(bool active) { } void GroupCall::toggleScreenSharing(std::optional uniqueId) { + if (!_instance + || !_id + || (uniqueId && mutedByAdmin()) + || (!uniqueId && !_screenOutgoing)) { + return; + } ensureOutgoingVideo(); if (!uniqueId) { _screenOutgoing->setState(Webrtc::VideoState::Inactive); @@ -853,9 +867,7 @@ void GroupCall::rejoin() { } void GroupCall::rejoinWithHash(const QString &hash) { - if (!hash.isEmpty() - && (muted() == MuteState::ForceMuted - || muted() == MuteState::RaisedHand)) { + if (!hash.isEmpty() && mutedByAdmin()) { _joinHash = hash; rejoin(); } @@ -1060,8 +1072,7 @@ void GroupCall::applyMeInCallLocally() { const auto volume = participant ? participant->volume : Group::kDefaultVolume; - const auto canSelfUnmute = (muted() != MuteState::ForceMuted) - && (muted() != MuteState::RaisedHand); + const auto canSelfUnmute = !mutedByAdmin(); const auto raisedHandRating = (muted() != MuteState::RaisedHand) ? uint64(0) : participant @@ -1282,6 +1293,10 @@ void GroupCall::setMuted(MuteState mute) { if (wasMuted != nowMuted || wasRaiseHand != nowRaiseHand) { applyMeInCallLocally(); } + if (mutedByAdmin()) { + toggleVideo(false); + toggleScreenSharing(std::nullopt); + } }; if (mute == MuteState::Active || mute == MuteState::PushToTalk) { _delegate->groupCallRequestPermissionsOrFail(crl::guard(this, set)); @@ -1484,8 +1499,7 @@ void GroupCall::applySelfUpdate(const MTPDgroupCallParticipant &data) { LOG(("Call Info: Rejoin after unforcemute in stream mode.")); setState(State::Joining); rejoin(); - } else if (muted() == MuteState::ForceMuted - || muted() == MuteState::RaisedHand) { + } else if (mutedByAdmin()) { setMuted(MuteState::Muted); if (!_instanceTransitioning) { notifyAboutAllowedToSpeak(); @@ -2508,9 +2522,7 @@ void GroupCall::applyGlobalShortcutChanges() { } void GroupCall::pushToTalk(bool pressed, crl::time delay) { - if (muted() == MuteState::ForceMuted - || muted() == MuteState::RaisedHand - || muted() == MuteState::Active) { + if (mutedByAdmin() || muted() == MuteState::Active) { return; } else if (pressed) { _pushToTalkCancelTimer.cancel(); diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.h b/Telegram/SourceFiles/calls/group/calls_group_call.h index 8c99c087f..78f212009 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.h +++ b/Telegram/SourceFiles/calls/group/calls_group_call.h @@ -327,6 +327,7 @@ public: } static constexpr auto kSpeakLevelThreshold = 0.2; + [[nodiscard]] bool mutedByAdmin() const; void setCurrentAudioDevice(bool input, const QString &deviceId); void setCurrentVideoDevice(const QString &deviceId); [[nodiscard]] bool isSharingScreen() const; diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp index a5ab0e7f8..39d61f007 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.cpp @@ -774,6 +774,10 @@ void Panel::refreshVideoButtons(std::optional overrideWideMode) { ) | rpl::start_with_next([=](bool sharing) { _video->setProgress(sharing ? 1. : 0.); }, _video->lifetime()); + _call->mutedValue( + ) | rpl::start_with_next([=] { + updateButtonsGeometry(); + }, _video->lifetime()); } if (!_screenShare) { _screenShare.create(widget(), st::groupCallScreenShareSmall); @@ -2040,13 +2044,14 @@ void Panel::updateButtonsGeometry() { if (_callShare) { _callShare->moveToLeft(leftButtonLeft, buttonsTop); } + const auto showVideoButton = videoButtonInNarrowMode(); if (_video) { - _video->setVisible(!_callShare); + _video->setVisible(!_callShare && showVideoButton); _video->setStyle(st::groupCallVideo, &st::groupCallVideoActive); _video->moveToLeft(leftButtonLeft, buttonsTop); } if (_settings) { - _settings->setVisible(!_callShare && !_video); + _settings->setVisible(!_callShare && !showVideoButton); _settings->moveToLeft(leftButtonLeft, buttonsTop); } _hangup->moveToRight(leftButtonLeft, buttonsTop); @@ -2073,6 +2078,10 @@ void Panel::updateButtonsGeometry() { } } +bool Panel::videoButtonInNarrowMode() const { + return (_video != nullptr) && !_call->mutedByAdmin(); +} + void Panel::updateMembersGeometry() { if (!_members) { return; diff --git a/Telegram/SourceFiles/calls/group/calls_group_panel.h b/Telegram/SourceFiles/calls/group/calls_group_panel.h index fd2231a09..1c91e623a 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_panel.h +++ b/Telegram/SourceFiles/calls/group/calls_group_panel.h @@ -113,6 +113,7 @@ private: std::optional overrideWideMode = std::nullopt); void refreshTilesGeometry(); void toggleWideControls(bool shown); + [[nodiscard]] bool videoButtonInNarrowMode() const; void endCall();