From 8188ab3033f87b7f6a12aa239a63fda2858fa856 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 12 Feb 2021 19:07:41 +0400 Subject: [PATCH] Adapt UI for gigagroups. --- .../boxes/peers/edit_peer_info_box.cpp | 34 ++++++++++++++----- .../boxes/peers/edit_peer_permissions_box.cpp | 21 ++++++------ Telegram/SourceFiles/data/data_channel.cpp | 1 + Telegram/SourceFiles/data/data_channel.h | 4 +++ Telegram/SourceFiles/data/data_peer.cpp | 8 +++-- Telegram/SourceFiles/data/data_peer.h | 1 + Telegram/SourceFiles/info/info.style | 4 +++ 7 files changed, 52 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp index d5924277fe..9abba406c6 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_info_box.cpp @@ -328,7 +328,7 @@ private: object_ptr createStickersEdit(); bool canEditInformation() const; - void refreshHistoryVisibility(anim::type animated = anim::type::normal); + void refreshHistoryVisibility(); void showEditPeerTypeBox( std::optional> error = {}); void showEditLinkedChatBox(); @@ -631,7 +631,7 @@ bool Controller::canEditInformation() const { return false; } -void Controller::refreshHistoryVisibility(anim::type animated) { +void Controller::refreshHistoryVisibility() { if (!_controls.historyVisibilityWrap) { return; } @@ -639,7 +639,7 @@ void Controller::refreshHistoryVisibility(anim::type animated) { (_privacySavedValue != Privacy::HasUsername && !_channelHasLocationOriginalValue && (!_linkedChatSavedValue || !*_linkedChatSavedValue)), - animated); + anim::type::instant); } void Controller::showEditPeerTypeBox( @@ -880,7 +880,7 @@ void Controller::fillHistoryVisibilityButton() { updateHistoryVisibility->fire_copy(*_historyVisibilitySavedValue); - refreshHistoryVisibility(anim::type::instant); + refreshHistoryVisibility(); } void Controller::fillSetMessagesTTLButton() { @@ -965,7 +965,7 @@ void Controller::fillManageSection() { }(); const auto canViewKicked = [&] { return isChannel - ? (!channel->isMegagroup()) + ? (channel->isBroadcast() || channel->isGigagroup()) : false; }(); const auto hasRecentActions = [&] { @@ -1015,7 +1015,7 @@ void Controller::fillManageSection() { } if (canEditPreHistoryHidden || canEditSignatures - || canEditInviteLinks + //|| canEditInviteLinks || canViewOrEditLinkedChat || canEditUsername || canSetMessagesTTL) { @@ -1038,7 +1038,10 @@ void Controller::fillManageSection() { [=] { ShowEditPermissions(_navigation, _peer); }, st::infoIconPermissions); } - if (canEditInviteLinks) { + if (canEditInviteLinks + && (canEditUsername + || !_peer->isChannel() + || !_peer->asChannel()->hasUsername())) { auto count = Info::Profile::MigratedOrMeValue( _peer ) | rpl::map([=](not_null peer) { @@ -1053,8 +1056,13 @@ void Controller::fillManageSection() { }) | rpl::flatten_latest( ) | rpl::start_spawning(_controls.buttonsLayout->lifetime()); + const auto wrap = _controls.buttonsLayout->add( + object_ptr>( + _controls.buttonsLayout, + object_ptr( + _controls.buttonsLayout))); AddButtonWithCount( - _controls.buttonsLayout, + wrap->entity(), tr::lng_manage_peer_invite_links(), rpl::duplicate(count) | ToPositiveNumberString(), [=] { Ui::show( @@ -1062,6 +1070,16 @@ void Controller::fillManageSection() { Ui::LayerOption::KeepOther); }, st::infoIconInviteLinks); + + if (_privacySavedValue) { + _privacyTypeUpdates.events_starting_with_copy( + *_privacySavedValue + ) | rpl::start_with_next([=](Privacy flag) { + wrap->toggle( + flag != Privacy::HasUsername, + anim::type::instant); + }, wrap->lifetime()); + } } if (canViewAdmins) { AddButtonWithCount( diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index 5a4bbacdc0..76bb802dca 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/continuous_sliders.h" #include "ui/widgets/box_content_divider.h" +#include "ui/text/text_utilities.h" #include "ui/toast/toast.h" #include "info/profile/info_profile_icon.h" #include "info/profile/info_profile_values.h" @@ -34,7 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { constexpr auto kSlowmodeValues = 7; -constexpr auto kSuggestGigagroupThreshold = 199000; +constexpr auto kSuggestGigagroupThreshold = 1; AssertIsDebug(199000); int SlowmodeDelayByIndex(int index) { Expects(index >= 0 && index < kSlowmodeValues); @@ -551,7 +552,7 @@ void EditPeerPermissionsBox::addSuggestGigagroup( channel->inputChannel )).done([=](const MTPUpdates &result) { channel->session().api().applyUpdates(result); - Ui::hideLayer(); + Ui::hideSettingsAndLayer(); }).fail([=](const RPCError &error) { *converting = false; }).send(); @@ -565,13 +566,9 @@ void EditPeerPermissionsBox::addSuggestGigagroup( box->addRow( object_ptr( box, - tr::lng_gigagroup_warning(), - st::defaultFlatLabel), - style::margins( - st::boxRowPadding.left(), - st::boxLittleSkip, - st::boxRowPadding.right(), - st::boxLittleSkip)); + tr::lng_gigagroup_warning( + ) | Ui::Text::ToRichLangValue(), + st::infoAboutGigagroup)); box->addButton(tr::lng_gigagroup_convert_sure(), convertSure); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); })); @@ -583,11 +580,13 @@ void EditPeerPermissionsBox::addSuggestGigagroup( getDelegate()->show(Box([=](not_null box) { box->setTitle(tr::lng_gigagroup_convert_title()); const auto addFeature = [&](rpl::producer text) { + using namespace rpl::mappers; + const auto prefix = QString::fromUtf8("\xE2\x80\xA2 "); box->addRow( object_ptr( box, - std::move(text), - st::defaultFlatLabel), + std::move(text) | rpl::map(prefix + _1), + st::infoAboutGigagroup), style::margins( st::boxRowPadding.left(), st::boxLittleSkip, diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index 051e78c9c2..9ea1086d86 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -454,6 +454,7 @@ bool ChannelData::canEditInformation() const { bool ChannelData::canEditPermissions() const { return isMegagroup() + && !isGigagroup() && ((adminRights() & AdminRight::f_ban_users) || amCreator()); } diff --git a/Telegram/SourceFiles/data/data_channel.h b/Telegram/SourceFiles/data/data_channel.h index 5c248072b6..cf0c98dc7f 100644 --- a/Telegram/SourceFiles/data/data_channel.h +++ b/Telegram/SourceFiles/data/data_channel.h @@ -96,6 +96,7 @@ public: | MTPDchannel::Flag::f_scam | MTPDchannel::Flag::f_fake | MTPDchannel::Flag::f_megagroup + | MTPDchannel::Flag::f_gigagroup | MTPDchannel::Flag::f_restricted | MTPDchannel::Flag::f_signatures | MTPDchannel::Flag::f_username @@ -233,6 +234,9 @@ public: [[nodiscard]] bool isBroadcast() const { return flags() & MTPDchannel::Flag::f_broadcast; } + [[nodiscard]] bool isGigagroup() const { + return flags() & MTPDchannel::Flag::f_gigagroup; + } [[nodiscard]] bool hasUsername() const { return flags() & MTPDchannel::Flag::f_username; } diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 0f43b11000..bad21450bb 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -757,11 +757,15 @@ bool PeerData::isFake() const { } bool PeerData::isMegagroup() const { - return isChannel() ? asChannel()->isMegagroup() : false; + return isChannel() && asChannel()->isMegagroup(); } bool PeerData::isBroadcast() const { - return isChannel() ? asChannel()->isBroadcast() : false; + return isChannel() && asChannel()->isBroadcast(); +} + +bool PeerData::isGigagroup() const { + return isChannel() && asChannel()->isGigagroup(); } bool PeerData::isRepliesChat() const { diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h index 26025bc11d..2df51e6ff9 100644 --- a/Telegram/SourceFiles/data/data_peer.h +++ b/Telegram/SourceFiles/data/data_peer.h @@ -156,6 +156,7 @@ public: [[nodiscard]] bool isFake() const; [[nodiscard]] bool isMegagroup() const; [[nodiscard]] bool isBroadcast() const; + [[nodiscard]] bool isGigagroup() const; [[nodiscard]] bool isRepliesChat() const; [[nodiscard]] bool sharedMediaInfo() const { return isSelf() || isRepliesChat(); diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index ec076f378a..6a24cf9c40 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -937,3 +937,7 @@ inviteLinkRevokedIcon: icon {{ "info/edit/links_revoked", mediaviewFileExtFg }}; inviteLinkThreeDotsSkip: 12px; inviteLinkRevokedTitlePadding: margins(22px, 16px, 10px, 4px); inviteLinkLimitMargin: margins(22px, 8px, 22px, 8px); + +infoAboutGigagroup: FlatLabel(defaultFlatLabel) { + minWidth: 274px; +}