From b85bbadd74c2f1177cbe5fbcfb5049baaf0cec6a Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 18 Dec 2020 21:02:19 +0300 Subject: [PATCH] Added Connecting state to Calls::TopBar. --- .../SourceFiles/calls/calls_group_call.cpp | 9 ++ Telegram/SourceFiles/calls/calls_group_call.h | 1 + .../SourceFiles/calls/calls_group_panel.cpp | 7 +- Telegram/SourceFiles/calls/calls_top_bar.cpp | 97 +++++++++++++------ Telegram/SourceFiles/calls/calls_top_bar.h | 5 +- 5 files changed, 81 insertions(+), 38 deletions(-) diff --git a/Telegram/SourceFiles/calls/calls_group_call.cpp b/Telegram/SourceFiles/calls/calls_group_call.cpp index cbeedcd57..2a68b411e 100644 --- a/Telegram/SourceFiles/calls/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/calls_group_call.cpp @@ -766,6 +766,15 @@ void GroupCall::sendMutedUpdate() { }).send(); } +rpl::producer GroupCall::connectingValue() const { + using namespace rpl::mappers; + return _state.value() | rpl::map( + _1 == State::Creating + || _1 == State::Joining + || _1 == State::Connecting + ) | rpl::distinct_until_changed(); +} + void GroupCall::setCurrentAudioDevice(bool input, const QString &deviceId) { if (input) { _mediaDevices->switchToAudioInput(deviceId); diff --git a/Telegram/SourceFiles/calls/calls_group_call.h b/Telegram/SourceFiles/calls/calls_group_call.h index 78a7f41bb..8b6907d2c 100644 --- a/Telegram/SourceFiles/calls/calls_group_call.h +++ b/Telegram/SourceFiles/calls/calls_group_call.h @@ -120,6 +120,7 @@ public: [[nodiscard]] rpl::producer stateValue() const { return _state.value(); } + [[nodiscard]] rpl::producer connectingValue() const; [[nodiscard]] rpl::producer levelUpdates() const { return _levelUpdates.events(); diff --git a/Telegram/SourceFiles/calls/calls_group_panel.cpp b/Telegram/SourceFiles/calls/calls_group_panel.cpp index 3823f0c2d..92f1f6bc6 100644 --- a/Telegram/SourceFiles/calls/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_group_panel.cpp @@ -417,14 +417,9 @@ void GroupPanel::initWithCall(GroupCall *call) { } }, _callLifetime); - using namespace rpl::mappers; rpl::combine( _call->mutedValue() | MapPushToTalkToActive(), - _call->stateValue() | rpl::map( - _1 == State::Creating - || _1 == State::Joining - || _1 == State::Connecting - ) + _call->connectingValue() ) | rpl::distinct_until_changed( ) | rpl::start_with_next([=](MuteState mute, bool connecting) { _mute->setState(Ui::CallMuteButtonState{ diff --git a/Telegram/SourceFiles/calls/calls_top_bar.cpp b/Telegram/SourceFiles/calls/calls_top_bar.cpp index 91cd44af9..550408083 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.cpp +++ b/Telegram/SourceFiles/calls/calls_top_bar.cpp @@ -35,6 +35,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_layers.h" namespace Calls { + +enum class BarState { + Connecting, + Active, + Muted, + ForceMuted, +}; + namespace { constexpr auto kMaxUsersInBar = 3; @@ -47,6 +55,16 @@ constexpr auto kHideBlobsDuration = crl::time(500); constexpr auto kBlobLevelDuration = crl::time(250); constexpr auto kBlobUpdateInterval = crl::time(100); +auto BarStateFromMuteState(MuteState state, bool connecting) { + return (connecting + ? BarState::Connecting + : state == MuteState::ForceMuted + ? BarState::ForceMuted + : state == MuteState::Muted + ? BarState::Muted + : BarState::Active); +}; + auto LinearBlobs() { return std::vector{ { @@ -79,22 +97,26 @@ auto LinearBlobs() { auto Colors() { using Vector = std::vector; using Colors = anim::gradient_colors; - return base::flat_map{ + return base::flat_map{ { - MuteState::ForceMuted, + BarState::ForceMuted, Colors(QGradientStops{ { 0.0, st::groupCallForceMutedBar1->c }, { .35, st::groupCallForceMutedBar2->c }, { 1.0, st::groupCallForceMutedBar3->c } }) }, { - MuteState::Active, + BarState::Active, Colors(Vector{ st::groupCallLive1->c, st::groupCallLive2->c }) }, { - MuteState::Muted, + BarState::Muted, Colors(Vector{ st::groupCallMuted1->c, st::groupCallMuted2->c }) }, + { + BarState::Connecting, + Colors(st::callBarBgMuted->c) + }, }; } @@ -257,21 +279,32 @@ void TopBar::initControls() { const auto mapToState = [](bool muted) { return muted ? MuteState::Muted : MuteState::Active; }; - const auto fromState = _mute->lifetime().make_state( - _call ? mapToState(_call->muted()) : _groupCall->muted()); + const auto fromState = _mute->lifetime().make_state( + BarStateFromMuteState( + _call + ? mapToState(_call->muted()) + : _groupCall->muted(), + false)); auto muted = _call - ? _call->mutedValue() | rpl::map(mapToState) - : (_groupCall->mutedValue() - | MapPushToTalkToActive() - | rpl::distinct_until_changed() - | rpl::type_erased()); + ? rpl::combine( + _call->mutedValue() | rpl::map(mapToState), + rpl::single(false)) + : rpl::combine( + (_groupCall->mutedValue() + | MapPushToTalkToActive() + | rpl::distinct_until_changed() + | rpl::type_erased()), + _groupCall->connectingValue()); std::move( muted - ) | rpl::start_with_next([=](MuteState state) { - setMuted(state != MuteState::Active); + ) | rpl::map( + BarStateFromMuteState + ) | rpl::start_with_next([=](BarState state) { + _isGroupConnecting = (state == BarState::Connecting); + setMuted(state != BarState::Active); update(); - const auto isForceMuted = (state == MuteState::ForceMuted); + const auto isForceMuted = (state == BarState::ForceMuted); if (isForceMuted) { _mute->clearState(); } @@ -285,8 +318,8 @@ void TopBar::initControls() { const auto toMuted = state; *fromState = state; - const auto crossFrom = (fromMuted != MuteState::Active) ? 1. : 0.; - const auto crossTo = (toMuted != MuteState::Active) ? 1. : 0.; + const auto crossFrom = (fromMuted != BarState::Active) ? 1. : 0.; + const auto crossTo = (toMuted != BarState::Active) ? 1. : 0.; auto animationCallback = [=](float64 value) { if (_groupCall) { @@ -312,6 +345,14 @@ void TopBar::initControls() { if (const auto group = _groupCall.get()) { subscribeToMembersChanges(group); + + _isGroupConnecting.value( + ) | rpl::start_with_next([=](bool isConnecting) { + _mute->setAttribute( + Qt::WA_TransparentForMouseEvents, + isConnecting); + updateInfoLabels(); + }, lifetime()); } if (const auto call = _call.get()) { @@ -415,23 +456,14 @@ void TopBar::initBlobsUnder( auto hideBlobs = rpl::combine( rpl::single(anim::Disabled()) | rpl::then(anim::Disables()), Core::App().appDeactivatedValue(), - group->stateValue( - ) | rpl::map([](Calls::GroupCall::State state) { - using State = Calls::GroupCall::State; - if (state != State::Creating - && state != State::Joining - && state != State::Joined - && state != State::Connecting) { - return true; - } - return false; - }) | rpl::distinct_until_changed() - ) | rpl::map([](bool animDisabled, bool hide, bool isBadState) { - return isBadState || animDisabled || hide; + group->connectingValue() + ) | rpl::map([](bool animDisabled, bool hide, bool connecting) { + return connecting || animDisabled || hide; }); std::move( hideBlobs + ) | rpl::distinct_until_changed( ) | rpl::start_with_next([=](bool hide) { if (hide) { state->paint.setLevel(0.); @@ -611,8 +643,11 @@ void TopBar::setInfoLabels() { } else if (const auto group = _groupCall.get()) { const auto peer = group->peer(); const auto name = peer->name; - _fullInfoLabel->setText(name.toUpper()); - _shortInfoLabel->setText(name.toUpper()); + const auto text = _isGroupConnecting.current() + ? tr::lng_group_call_connecting(tr::now) + : name.toUpper(); + _fullInfoLabel->setText(text); + _shortInfoLabel->setText(text); } } diff --git a/Telegram/SourceFiles/calls/calls_top_bar.h b/Telegram/SourceFiles/calls/calls_top_bar.h index 6ea44da8f..2f89032de 100644 --- a/Telegram/SourceFiles/calls/calls_top_bar.h +++ b/Telegram/SourceFiles/calls/calls_top_bar.h @@ -33,6 +33,7 @@ class GroupCall; class SignalBars; class Mute; enum class MuteState; +enum class BarState; class TopBar : public Ui::RpWidget { public: @@ -83,8 +84,10 @@ private: object_ptr _hangup; base::unique_qptr _blobs; + rpl::variable _isGroupConnecting = false; + QBrush _groupBrush; - anim::linear_gradients _gradients; + anim::linear_gradients _gradients; Ui::Animations::Simple _switchStateAnimation; base::Timer _updateDurationTimer;