diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 48d25273a7..72b1799cfa 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -269,6 +269,7 @@ PRIVATE calls/calls_call.h calls/calls_group_call.cpp calls/calls_group_call.h + calls/calls_group_common.h calls/calls_group_members.cpp calls/calls_group_members.h calls/calls_group_panel.cpp diff --git a/Telegram/SourceFiles/calls/calls_group_call.cpp b/Telegram/SourceFiles/calls/calls_group_call.cpp index c81a371624..548dc587d9 100644 --- a/Telegram/SourceFiles/calls/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/calls_group_call.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "calls/calls_group_call.h" +#include "calls/calls_group_common.h" #include "main/main_session.h" #include "api/api_send_progress.h" #include "apiwrap.h" @@ -263,14 +264,14 @@ void GroupCall::join(const MTPInputGroupCall &inputCall) { const auto &was = update.was; const auto volumeChanged = was ? (was->volume != now.volume || was->mutedByMe != now.mutedByMe) - : (now.volume != Data::GroupCall::kDefaultVolume || now.mutedByMe); + : (now.volume != Group::kDefaultVolume || now.mutedByMe); if (volumeChanged) { _instance->setVolume( now.ssrc, (now.mutedByMe ? 0. : (now.volume - / float64(Data::GroupCall::kDefaultVolume)))); + / float64(Group::kDefaultVolume)))); } } }, _lifetime); @@ -392,7 +393,7 @@ void GroupCall::applySelfInCallLocally() { MTP_int(date), MTP_int(lastActive), MTP_int(_mySsrc), - MTP_int(10000))), // volume + MTP_int(Group::kDefaultVolume))), // volume MTP_int(0)).c_updateGroupCallParticipants()); } @@ -689,14 +690,13 @@ void GroupCall::updateInstanceVolumes() { const auto &participants = real->participants(); for (const auto &participant : participants) { const auto setVolume = participant.mutedByMe - || (participant.volume != Data::GroupCall::kDefaultVolume); + || (participant.volume != Group::kDefaultVolume); if (setVolume && participant.ssrc) { _instance->setVolume( participant.ssrc, (participant.mutedByMe ? 0. - : (participant.volume - / float64(Data::GroupCall::kDefaultVolume)))); + : (participant.volume / float64(Group::kDefaultVolume)))); } } } @@ -896,7 +896,7 @@ void GroupCall::editParticipant( MTP_flags(flags), inputCall(), user->inputUser, - MTP_int(std::clamp(volume.value_or(0), 1, 20000)) + MTP_int(std::clamp(volume.value_or(0), 1, Group::kMaxVolume)) )).done([=](const MTPUpdates &result) { _peer->session().api().applyUpdates(result); }).fail([=](const RPCError &error) { diff --git a/Telegram/SourceFiles/calls/calls_group_common.h b/Telegram/SourceFiles/calls/calls_group_common.h new file mode 100644 index 0000000000..4346d4c2f9 --- /dev/null +++ b/Telegram/SourceFiles/calls/calls_group_common.h @@ -0,0 +1,27 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +class UserData; + +namespace Calls::Group { + +constexpr auto kDefaultVolume = 10000; +constexpr auto kMaxVolume = 20000; + +struct MuteRequest { + not_null user; + bool mute = false; +}; +struct VolumeRequest { + not_null user; + int volume = kDefaultVolume; + bool finalized = true; +}; + +} // namespace Calls::Group diff --git a/Telegram/SourceFiles/calls/calls_group_members.cpp b/Telegram/SourceFiles/calls/calls_group_members.cpp index 98b31e790f..c72918487d 100644 --- a/Telegram/SourceFiles/calls/calls_group_members.cpp +++ b/Telegram/SourceFiles/calls/calls_group_members.cpp @@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "calls/calls_group_members.h" #include "calls/calls_group_call.h" +#include "calls/calls_group_common.h" #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_user.h" @@ -196,7 +197,7 @@ private: Ui::Animations::Simple _mutedAnimation; // For gray/red icon. Ui::Animations::Simple _activeAnimation; // For icon cross animation. uint32 _ssrc = 0; - int _volume = Data::GroupCall::kDefaultVolume; + int _volume = Group::kDefaultVolume; bool _sounding = false; bool _speaking = false; bool _skipLevelUpdate = false; @@ -213,8 +214,8 @@ public: not_null menuParent); ~MembersController(); - using MuteRequest = GroupMembers::MuteRequest; - using VolumeRequest = GroupMembers::VolumeRequest; + using MuteRequest = Group::MuteRequest; + using VolumeRequest = Group::VolumeRequest; Main::Session &session() const override; void prepare() override; @@ -318,7 +319,7 @@ void Row::updateState(const Data::GroupCall::Participant *participant) { setSsrc(participant ? participant->ssrc : 0); setVolume(participant ? participant->volume - : Data::GroupCall::kDefaultVolume); + : Group::kDefaultVolume); if (!participant) { setState(State::Invited); setSounding(false); @@ -1160,15 +1161,15 @@ base::unique_qptr MembersController::createRowContextMenu( ? (muteState == Row::State::Active) : (muteState != Row::State::Muted); const auto toggleMute = crl::guard(this, [=] { - _toggleMuteRequests.fire(MuteRequest{ + _toggleMuteRequests.fire(Group::MuteRequest{ .user = user, .mute = mute, }); }); const auto changeVolume = crl::guard(this, [=](int volume) { - _changeVolumeRequests.fire(VolumeRequest{ + _changeVolumeRequests.fire(Group::VolumeRequest{ .user = user, - .volume = std::clamp(volume, 1, 20000), + .volume = std::clamp(volume, 1, Group::kMaxVolume), }); }); @@ -1303,8 +1304,6 @@ std::unique_ptr MembersController::createInvitedRow( } // namespace -const int GroupMembers::kDefaultVolume = Data::GroupCall::kDefaultVolume; - GroupMembers::GroupMembers( not_null parent, not_null call) @@ -1320,13 +1319,13 @@ GroupMembers::GroupMembers( } auto GroupMembers::toggleMuteRequests() const --> rpl::producer { +-> rpl::producer { return static_cast( _listController.get())->toggleMuteRequests(); } auto GroupMembers::changeVolumeRequests() const --> rpl::producer { +-> rpl::producer { return static_cast( _listController.get())->changeVolumeRequests(); } diff --git a/Telegram/SourceFiles/calls/calls_group_members.h b/Telegram/SourceFiles/calls/calls_group_members.h index 76ed90e93a..5d5014af7e 100644 --- a/Telegram/SourceFiles/calls/calls_group_members.h +++ b/Telegram/SourceFiles/calls/calls_group_members.h @@ -20,6 +20,11 @@ class GroupCall; namespace Calls { +namespace Group { +struct VolumeRequest; +struct MuteRequest; +} // namespace Group + class GroupCall; class GroupMembers final @@ -30,23 +35,13 @@ public: not_null parent, not_null call); - static const int kDefaultVolume;/* = Data::GroupCall::kDefaultVolume*/ - - struct MuteRequest { - not_null user; - bool mute = false; - }; - struct VolumeRequest { - not_null user; - int volume = kDefaultVolume; - bool finalized = true; - }; - [[nodiscard]] int desiredHeight() const; [[nodiscard]] rpl::producer desiredHeightValue() const override; [[nodiscard]] rpl::producer fullCountValue() const; - [[nodiscard]] rpl::producer toggleMuteRequests() const; - [[nodiscard]] rpl::producer changeVolumeRequests() const; + [[nodiscard]] auto toggleMuteRequests() const + -> rpl::producer; + [[nodiscard]] auto changeVolumeRequests() const + -> rpl::producer; [[nodiscard]] auto kickMemberRequests() const -> rpl::producer>; [[nodiscard]] rpl::producer<> addMembersRequests() const { diff --git a/Telegram/SourceFiles/calls/calls_group_panel.cpp b/Telegram/SourceFiles/calls/calls_group_panel.cpp index 32826be623..2aaed107ef 100644 --- a/Telegram/SourceFiles/calls/calls_group_panel.cpp +++ b/Telegram/SourceFiles/calls/calls_group_panel.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "calls/calls_group_panel.h" +#include "calls/calls_group_common.h" #include "calls/calls_group_members.h" #include "calls/calls_group_settings.h" #include "ui/widgets/buttons.h" @@ -505,14 +506,14 @@ void GroupPanel::initWithCall(GroupCall *call) { }, _callLifetime); _members->toggleMuteRequests( - ) | rpl::start_with_next([=](GroupMembers::MuteRequest request) { + ) | rpl::start_with_next([=](Group::MuteRequest request) { if (_call) { _call->toggleMute(request.user, request.mute); } }, _callLifetime); _members->changeVolumeRequests( - ) | rpl::start_with_next([=](GroupMembers::VolumeRequest request) { + ) | rpl::start_with_next([=](Group::VolumeRequest request) { if (_call) { _call->changeVolume(request.user, request.volume); } diff --git a/Telegram/SourceFiles/data/data_group_call.cpp b/Telegram/SourceFiles/data/data_group_call.cpp index 9ca6859792..75bf646f10 100644 --- a/Telegram/SourceFiles/data/data_group_call.cpp +++ b/Telegram/SourceFiles/data/data_group_call.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "calls/calls_instance.h" #include "calls/calls_group_call.h" +#include "calls/calls_group_common.h" #include "core/application.h" #include "apiwrap.h" @@ -275,12 +276,13 @@ void GroupCall::applyParticipantsSlice( && ((was ? was->speaking : false) || (!amInCall && (lastActive + speakingAfterActive > now))); + const auto defaultVolume = Calls::Group::kDefaultVolume; const auto value = Participant{ .user = user, .date = data.vdate().v, .lastActive = lastActive, .ssrc = uint32(data.vsource().v), - .volume = data.vvolume().value_or(kDefaultVolume), + .volume = data.vvolume().value_or(defaultVolume), .speaking = canSelfUnmute && (was ? was->speaking : false), .muted = data.is_muted(), .mutedByMe = data.is_muted_by_you(), diff --git a/Telegram/SourceFiles/data/data_group_call.h b/Telegram/SourceFiles/data/data_group_call.h index 5bf7e7c40c..da039bae2e 100644 --- a/Telegram/SourceFiles/data/data_group_call.h +++ b/Telegram/SourceFiles/data/data_group_call.h @@ -32,7 +32,6 @@ public: void setPeer(not_null peer); - static constexpr auto kDefaultVolume = 10000; struct Participant { not_null user; TimeId date = 0;