From 7430fbacfdbee0ac096bce9efa8857ec690db4bb Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 12 Mar 2021 20:20:03 +0400 Subject: [PATCH] Allow remove raised hand from context menu. --- Telegram/Resources/langs/lang.strings | 1 + .../SourceFiles/calls/calls_group_call.cpp | 15 +++++++++-- .../SourceFiles/calls/calls_group_members.cpp | 26 ++++++++++++++----- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index ce2879d69..b74b24256 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1974,6 +1974,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_group_call_too_many" = "Sorry, there are too many members in this voice chat. Please try again later."; "lng_group_call_context_mute" = "Mute"; "lng_group_call_context_unmute" = "Allow to speak"; +"lng_group_call_context_remove_hand" = "Cancel request to speak"; "lng_group_call_context_mute_for_me" = "Mute for me"; "lng_group_call_context_unmute_for_me" = "Unmute for me"; "lng_group_call_duration_days#one" = "{count} day"; diff --git a/Telegram/SourceFiles/calls/calls_group_call.cpp b/Telegram/SourceFiles/calls/calls_group_call.cpp index 7f4093c39..af42fbc5b 100644 --- a/Telegram/SourceFiles/calls/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/calls_group_call.cpp @@ -492,6 +492,15 @@ void GroupCall::rejoin(not_null as) { }); } +[[nodiscard]] uint64 FindLocalRaisedHandRating( + const std::vector &list) { + const auto i = ranges::max_element( + list, + ranges::less(), + &Data::GroupCallParticipant::raisedHandRating); + return (i == end(list)) ? 1 : (i->raisedHandRating + 1); +} + void GroupCall::applyMeInCallLocally() { const auto call = _peer->groupCall(); if (!call || call->id() != _id) { @@ -514,9 +523,11 @@ void GroupCall::applyMeInCallLocally() { : Group::kDefaultVolume; const auto canSelfUnmute = (muted() != MuteState::ForceMuted) && (muted() != MuteState::RaisedHand); - const auto raisedHandRating = (i != end(participants)) + const auto raisedHandRating = (muted() != MuteState::RaisedHand) + ? uint64(0) + : (i != end(participants)) ? i->raisedHandRating - : uint64(0); + : FindLocalRaisedHandRating(participants); const auto flags = (canSelfUnmute ? Flag::f_can_self_unmute : Flag(0)) | (lastActive ? Flag::f_active_date : Flag(0)) | (_mySsrc ? Flag(0) : Flag::f_left) diff --git a/Telegram/SourceFiles/calls/calls_group_members.cpp b/Telegram/SourceFiles/calls/calls_group_members.cpp index a211be803..64cbd9abe 100644 --- a/Telegram/SourceFiles/calls/calls_group_members.cpp +++ b/Telegram/SourceFiles/calls/calls_group_members.cpp @@ -1479,10 +1479,7 @@ base::unique_qptr MembersController::createRowContextMenu( not_null row) { const auto participantPeer = row->peer(); const auto real = static_cast(row.get()); - if (isMe(participantPeer) - && (!_peer->canManageGroupCall() || !real->ssrc())) { - return nullptr; - } + auto result = base::make_unique_q( parent, st::groupCallPopupMenu); @@ -1538,11 +1535,25 @@ base::unique_qptr MembersController::createRowContextMenu( _kickParticipantRequests.fire_copy(participantPeer); }); - if (real->ssrc() != 0) { + if (real->ssrc() != 0 + && (!isMe(participantPeer) || _peer->canManageGroupCall())) { addMuteActionsToContextMenu(result, participantPeer, admin, real); } - if (!isMe(participantPeer)) { + if (isMe(participantPeer)) { + if (const auto strong = _call.get() + ; strong && strong->muted() == MuteState::RaisedHand) { + const auto removeHand = [=] { + if (const auto strong = _call.get() + ; strong && strong->muted() == MuteState::RaisedHand) { + strong->setMutedAndUpdate(MuteState::ForceMuted); + } + }; + result->addAction( + tr::lng_group_call_context_remove_hand(tr::now), + removeHand); + } + } else { result->addAction( tr::lng_context_view_profile(tr::now), showProfile); @@ -1575,6 +1586,9 @@ base::unique_qptr MembersController::createRowContextMenu( removeFromGroup); } } + if (result->empty()) { + return nullptr; + } return result; }