From 5e81c65ea6410b442e19aa758fca3a53c826f9dd Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 30 Aug 2022 13:21:58 +0400 Subject: [PATCH] Implement improved allowed reactions editing. --- Telegram/Resources/langs/lang.strings | 14 +- .../boxes/peers/edit_peer_info_box.cpp | 34 +-- .../boxes/peers/edit_peer_reactions.cpp | 195 +++++++++++------- .../boxes/peers/edit_peer_reactions.h | 10 +- .../boxes/reactions_settings_box.cpp | 171 ++++++++++----- .../boxes/reactions_settings_box.h | 8 + .../data/data_message_reactions.cpp | 3 + .../info/profile/info_profile_values.cpp | 17 -- .../info/profile/info_profile_values.h | 2 - 9 files changed, 291 insertions(+), 163 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 84b73dc86..740456819 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -1195,13 +1195,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_manage_peer_permissions" = "Permissions"; "lng_manage_peer_invite_links" = "Invite links"; "lng_manage_peer_reactions" = "Reactions"; +"lng_manage_peer_reactions_on" = "All"; "lng_manage_peer_reactions_off" = "Off"; "lng_manage_peer_requests" = "Member Requests"; "lng_manage_peer_requests_channel" = "Subscriber Requests"; -"lng_manage_peer_reactions_enable" = "Enable Reactions"; -"lng_manage_peer_reactions_about" = "Allow members to react to group messages."; -"lng_manage_peer_reactions_about_channel" = "Allow subscribers to react to channel posts."; +"lng_manage_peer_reactions_all" = "All reactions"; +"lng_manage_peer_reactions_all_about" = "Members of the group can use any emoji as reactions to messages."; +"lng_manage_peer_reactions_all_about_channel" = "Subscribers of this channel can use any emoji as reactions to messages."; +"lng_manage_peer_reactions_some" = "Some reactions"; +"lng_manage_peer_reactions_some_about" = "You can select emoji that will allow members of your group to react to messages."; +"lng_manage_peer_reactions_some_about_channel" = "You can select emoji that will allow subscribers of this channel to react to messages."; +"lng_manage_peer_reactions_none" = "No reactions"; +"lng_manage_peer_reactions_none_about" = "Members of the group can't add any reactions to messages."; +"lng_manage_peer_reactions_none_about_channel" = "Subscribers of this channel can't add any reactions to messages."; +"lng_manage_peer_reactions_some_title" = "Only allow these reactions"; "lng_manage_peer_reactions_available" = "Available reactions"; "lng_manage_peer_group_type" = "Group type"; diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index 606e50524..0b2bb79b4 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -988,22 +988,31 @@ void Controller::fillManageSection() { if (canEditReactions()) { const auto session = &_peer->session(); - auto reactionsCount = Info::Profile::MigratedOrMeValue( + auto allowedReactions = Info::Profile::MigratedOrMeValue( _peer - ) | rpl::map( - Info::Profile::AllowedReactionsCountValue - ) | rpl::flatten_latest(); - auto fullCount = Info::Profile::FullReactionsCountValue(session); + ) | rpl::map([=](not_null peer) { + return peer->session().changes().peerFlagsValue( + peer, + Data::PeerUpdate::Flag::Reactions + ) | rpl::map([=] { + return Data::PeerAllowedReactions(peer); + }); + }) | rpl::flatten_latest(); auto label = rpl::combine( - std::move(reactionsCount), - std::move(fullCount) - ) | rpl::map([=](int allowed, int total) { - return allowed - ? QString::number(allowed) + " / " + QString::number(total) + std::move(allowedReactions), + Info::Profile::FullReactionsCountValue(session) + ) | rpl::map([=](const Data::AllowedReactions &allowed, int total) { + const auto some = int(allowed.some.size()); + return (allowed.type != Data::AllowedReactionsType::Some) + ? tr::lng_manage_peer_reactions_on(tr::now) + : some + ? (QString::number(some) + + " / " + + QString::number(std::max(some, total))) : tr::lng_manage_peer_reactions_off(tr::now); }); - const auto done = [=](const std::vector &chosen, bool all) { - SaveAllowedReactions(_peer, chosen, all); + const auto done = [=](const Data::AllowedReactions &chosen) { + SaveAllowedReactions(_peer, chosen); }; AddButtonWithCount( _controls.buttonsLayout, @@ -1012,6 +1021,7 @@ void Controller::fillManageSection() { [=] { _navigation->parentController()->show(Box( EditAllowedReactionsBox, + _navigation, !_peer->isBroadcast(), session->data().reactions().list( Data::Reactions::Type::Active), diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp index a780acea8..a72aeed77 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_reactions.cpp @@ -18,34 +18,57 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "ui/layers/generic_box.h" #include "ui/widgets/buttons.h" +#include "ui/widgets/checkbox.h" +#include "ui/wrap/slide_wrap.h" #include "settings/settings_common.h" +#include "window/window_session_controller.h" #include "styles/style_settings.h" #include "styles/style_info.h" void EditAllowedReactionsBox( not_null box, + not_null navigation, bool isGroup, const std::vector &list, const Data::AllowedReactions &allowed, - Fn &, bool all)> callback) { + Fn callback) { + using namespace Data; + using namespace rpl::mappers; + const auto iconHeight = st::editPeerReactionsPreview; box->setTitle(tr::lng_manage_peer_reactions()); + enum class Option { + All, + Some, + None, + }; struct State { - base::flat_map> toggles; - rpl::variable anyToggled; - rpl::event_stream forceToggleAll; + base::flat_map> toggles; + rpl::variable