From f51320d1bc1a7e20e5ab863eaef5031c3afb8dc5 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 21 Mar 2025 12:02:12 +0400 Subject: [PATCH] Add some more frozen restrictions. --- .../boxes/peers/add_bot_to_chat_box.cpp | 3 + Telegram/SourceFiles/boxes/star_gift_box.cpp | 4 + .../chat_helpers/message_field.cpp | 194 +++++++++--------- .../SourceFiles/chat_helpers/message_field.h | 6 + .../history/history_inner_widget.cpp | 4 +- .../history/view/history_view_list_widget.cpp | 5 +- .../info/media/info_media_buttons.cpp | 3 + .../info/media/info_media_provider.cpp | 4 +- .../info/profile/info_profile_actions.cpp | 8 +- .../info/stories/info_stories_provider.cpp | 4 +- .../SourceFiles/main/session/session_show.cpp | 4 +- .../SourceFiles/menu/menu_ttl_validator.cpp | 4 + .../SourceFiles/window/window_peer_menu.cpp | 30 ++- .../window/window_session_controller.cpp | 5 +- .../window/window_session_controller.h | 2 +- 15 files changed, 171 insertions(+), 109 deletions(-) diff --git a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp index 14e00151b4..e3cf2a2dd5 100644 --- a/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/add_bot_to_chat_box.cpp @@ -111,6 +111,9 @@ void AddBotToGroupBoxController::Start( Scope scope, const QString &token, ChatAdminRights requestedRights) { + if (controller->showFrozenError()) { + return; + } auto initBox = [=](not_null box) { box->addButton(tr::lng_cancel(), [box] { box->closeBox(); }); }; diff --git a/Telegram/SourceFiles/boxes/star_gift_box.cpp b/Telegram/SourceFiles/boxes/star_gift_box.cpp index 312208b4d6..a149fc3979 100644 --- a/Telegram/SourceFiles/boxes/star_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/star_gift_box.cpp @@ -2308,6 +2308,10 @@ void ChooseStarGiftRecipient( void ShowStarGiftBox( not_null controller, not_null peer) { + if (controller->showFrozenError()) { + return; + } + struct Session { PeerData *peer = nullptr; MyGiftsDescriptor my; diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index 4288d0c794..b9e26419e0 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -1354,102 +1354,8 @@ std::unique_ptr FrozenWriteRestriction( } }, title->lifetime()); - const auto info = show->session().frozen(); - const auto detailsBox = [=](not_null box) { - box->setWidth(st::boxWideWidth); - box->setStyle(st::frozenInfoBox); - box->setNoContentMargin(true); - box->addTopButton(st::boxTitleClose, [=] { - box->closeBox(); - }); - - const auto content = box->verticalLayout(); - auto icon = Settings::CreateLottieIcon( - content, - { - .name = u"media_forbidden"_q, - .sizeOverride = { - st::changePhoneIconSize, - st::changePhoneIconSize, - }, - }, - st::settingLocalPasscodeIconPadding); - content->add(std::move(icon.widget)); - box->setShowFinishedCallback([animate = std::move(icon.animate)] { - animate(anim::repeat::once); - }); - - Ui::AddSkip(content); - - const auto infoRow = [&]( - rpl::producer title, - rpl::producer text, - not_null icon) { - auto raw = content->add( - object_ptr(content)); - raw->add( - object_ptr( - raw, - std::move(title) | Ui::Text::ToBold(), - st.infoTitle ? *st.infoTitle : st::defaultFlatLabel), - st::settingsPremiumRowTitlePadding); - raw->add( - object_ptr( - raw, - std::move(text), - st.infoAbout ? *st.infoAbout : st::upgradeGiftSubtext), - st::settingsPremiumRowAboutPadding); - object_ptr( - raw, - *icon, - st::starrefInfoIconPosition); - }; - - content->add( - object_ptr( - content, - tr::lng_frozen_title(), - st.title ? *st.title : st::uniqueGiftTitle), - st::settingsPremiumRowTitlePadding); - - Ui::AddSkip(content, st::defaultVerticalListSkip * 3); - - infoRow( - tr::lng_frozen_subtitle1(), - tr::lng_frozen_text1(Text::WithEntities), - st.violationIcon ? st.violationIcon : &st::menuIconBlock); - infoRow( - tr::lng_frozen_subtitle2(), - tr::lng_frozen_text2(Text::WithEntities), - st.readOnlyIcon ? st.readOnlyIcon : &st::menuIconLock); - infoRow( - tr::lng_frozen_subtitle3(), - tr::lng_frozen_text3( - lt_link, - rpl::single(Text::Link(u"@SpamBot"_q, info.appealUrl)), - lt_date, - rpl::single(TextWithEntities{ - langDayOfMonthFull( - base::unixtime::parse(info.until).date()), - }), - Text::WithEntities), - st.appealIcon ? st.appealIcon : &st::menuIconHourglass); - - const auto button = box->addButton( - tr::lng_frozen_appeal_button(), - [url = info.appealUrl] { UrlClickHandler::Open(url); }); - const auto buttonPadding = st::frozenInfoBox.buttonPadding; - const auto buttonWidth = st::boxWideWidth - - buttonPadding.left() - - buttonPadding.right(); - button->widthValue() | rpl::filter([=] { - return (button->widthNoMargins() != buttonWidth); - }) | rpl::start_with_next([=] { - button->resizeToWidth(buttonWidth); - }, button->lifetime()); - }; raw->setClickedCallback([=] { - show->show(Box(detailsBox)); + show->show(Box(FrozenInfoBox, &show->session(), st)); }); return result; } @@ -1501,3 +1407,101 @@ rpl::producer PaidSendButtonText( return PaidSendButtonText(tr::now, count); }); } + +void FrozenInfoBox( + not_null box, + not_null session, + FreezeInfoStyleOverride st) { + box->setWidth(st::boxWideWidth); + box->setStyle(st::frozenInfoBox); + box->setNoContentMargin(true); + box->addTopButton(st::boxTitleClose, [=] { + box->closeBox(); + }); + + const auto info = session->frozen(); + const auto content = box->verticalLayout(); + auto icon = Settings::CreateLottieIcon( + content, + { + .name = u"media_forbidden"_q, + .sizeOverride = { + st::changePhoneIconSize, + st::changePhoneIconSize, + }, + }, + st::settingLocalPasscodeIconPadding); + content->add(std::move(icon.widget)); + box->setShowFinishedCallback([animate = std::move(icon.animate)] { + animate(anim::repeat::once); + }); + + Ui::AddSkip(content); + + const auto infoRow = [&]( + rpl::producer title, + rpl::producer text, + not_null icon) { + auto raw = content->add( + object_ptr(content)); + raw->add( + object_ptr( + raw, + std::move(title) | Ui::Text::ToBold(), + st.infoTitle ? *st.infoTitle : st::defaultFlatLabel), + st::settingsPremiumRowTitlePadding); + raw->add( + object_ptr( + raw, + std::move(text), + st.infoAbout ? *st.infoAbout : st::upgradeGiftSubtext), + st::settingsPremiumRowAboutPadding); + object_ptr( + raw, + *icon, + st::starrefInfoIconPosition); + }; + + content->add( + object_ptr( + content, + tr::lng_frozen_title(), + st.title ? *st.title : st::uniqueGiftTitle), + st::settingsPremiumRowTitlePadding); + + Ui::AddSkip(content, st::defaultVerticalListSkip * 3); + + infoRow( + tr::lng_frozen_subtitle1(), + tr::lng_frozen_text1(Ui::Text::WithEntities), + st.violationIcon ? st.violationIcon : &st::menuIconBlock); + infoRow( + tr::lng_frozen_subtitle2(), + tr::lng_frozen_text2(Ui::Text::WithEntities), + st.readOnlyIcon ? st.readOnlyIcon : &st::menuIconLock); + infoRow( + tr::lng_frozen_subtitle3(), + tr::lng_frozen_text3( + lt_link, + rpl::single(Ui::Text::Link(u"@SpamBot"_q, info.appealUrl)), + lt_date, + rpl::single(TextWithEntities{ + langDayOfMonthFull( + base::unixtime::parse(info.until).date()), + }), + Ui::Text::WithEntities), + st.appealIcon ? st.appealIcon : &st::menuIconHourglass); + + const auto button = box->addButton( + tr::lng_frozen_appeal_button(), + [url = info.appealUrl] { UrlClickHandler::Open(url); }); + const auto buttonPadding = st::frozenInfoBox.buttonPadding; + const auto buttonWidth = st::boxWideWidth + - buttonPadding.left() + - buttonPadding.right(); + button->widthValue() | rpl::filter([=] { + return (button->widthNoMargins() != buttonWidth); + }) | rpl::start_with_next([=] { + button->resizeToWidth(buttonWidth); + }, button->lifetime()); +} diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index a00b4564bc..4d7ef52b48 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -42,6 +42,7 @@ struct WriteRestriction; } // namespace HistoryView::Controls namespace Ui { +class GenericBox; class PopupMenu; class Show; } // namespace Ui @@ -210,3 +211,8 @@ void SelectTextInFieldWithMargins( [[nodiscard]] rpl::producer PaidSendButtonText( rpl::producer stars, rpl::producer fallback = nullptr); + +void FrozenInfoBox( + not_null box, + not_null session, + FreezeInfoStyleOverride st); diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index ebb1c906fc..227c1a5fc9 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -621,7 +621,9 @@ void HistoryInner::setupSwipeReplyAndBack() { } bool HistoryInner::hasSelectRestriction() const { - if (!_sharingDisallowed.current()) { + if (session().frozen()) { + return true; + } else if (!_sharingDisallowed.current()) { return false; } else if (const auto chat = _peer->asChat()) { return !chat->canDeleteMessages(); diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 21df444337..1daf0a1133 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -1646,8 +1646,9 @@ bool ListWidget::showCopyRestrictionForSelected() { } bool ListWidget::hasSelectRestriction() const { - return _delegate->listSelectRestrictionType() - != CopyRestrictionType::None; + return session().frozen() + || (_delegate->listSelectRestrictionType() + != CopyRestrictionType::None); } Element *ListWidget::lookupItemByY(int y) const { diff --git a/Telegram/SourceFiles/info/media/info_media_buttons.cpp b/Telegram/SourceFiles/info/media/info_media_buttons.cpp index 12d7827f4b..1531602855 100644 --- a/Telegram/SourceFiles/info/media/info_media_buttons.cpp +++ b/Telegram/SourceFiles/info/media/info_media_buttons.cpp @@ -294,6 +294,9 @@ not_null AddPeerGiftsButton( }, tracker)->entity(); result->addClickHandler([=] { + if (navigation->showFrozenError()) { + return; + } navigation->showSection( std::make_shared( peer, diff --git a/Telegram/SourceFiles/info/media/info_media_provider.cpp b/Telegram/SourceFiles/info/media/info_media_provider.cpp index 3732568375..62f7fdfc4a 100644 --- a/Telegram/SourceFiles/info/media/info_media_provider.cpp +++ b/Telegram/SourceFiles/info/media/info_media_provider.cpp @@ -62,7 +62,9 @@ Type Provider::type() { } bool Provider::hasSelectRestriction() { - if (_peer->allowsForwarding()) { + if (_peer->session().frozen()) { + return true; + } else if (_peer->allowsForwarding()) { return false; } else if (const auto chat = _peer->asChat()) { return !chat->canDeleteMessages(); diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 318260d5b1..a9f12e7883 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -2335,11 +2335,17 @@ void ActionsFiller::addShareContactAction(not_null user) { void ActionsFiller::addEditContactAction(not_null user) { const auto controller = _controller->parentController(); + const auto edit = [=] { + if (controller->showFrozenError()) { + return; + } + controller->window().show(Box(EditContactBox, controller, user)); + }; AddActionButton( _wrap, tr::lng_info_edit_contact(), IsContactValue(user), - [=] { controller->window().show(Box(EditContactBox, controller, user)); }, + edit, &st::infoIconEdit); } diff --git a/Telegram/SourceFiles/info/stories/info_stories_provider.cpp b/Telegram/SourceFiles/info/stories/info_stories_provider.cpp index 6c9a7dabb3..f6863bee8a 100644 --- a/Telegram/SourceFiles/info/stories/info_stories_provider.cpp +++ b/Telegram/SourceFiles/info/stories/info_stories_provider.cpp @@ -75,7 +75,9 @@ Type Provider::type() { } bool Provider::hasSelectRestriction() { - if (const auto channel = _peer->asChannel()) { + if (_peer->session().frozen()) { + return true; + } else if (const auto channel = _peer->asChannel()) { return !channel->canEditStories() && !channel->canDeleteStories(); } return !_peer->isSelf(); diff --git a/Telegram/SourceFiles/main/session/session_show.cpp b/Telegram/SourceFiles/main/session/session_show.cpp index 5dcebcdedc..1f740d4413 100644 --- a/Telegram/SourceFiles/main/session/session_show.cpp +++ b/Telegram/SourceFiles/main/session/session_show.cpp @@ -7,8 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "main/session/session_show.h" +#include "chat_helpers/message_field.h" #include "lang/lang_keys.h" #include "main/main_session.h" +#include "ui/layers/generic_box.h" namespace Main { namespace { @@ -77,7 +79,7 @@ bool SessionShow::showFrozenError() { if (!session().frozen()) { return false; } - showToast(tr::lng_frozen_bar_title(tr::now)); + showBox(Box(FrozenInfoBox, &session(), FreezeInfoStyleOverride())); return true; } diff --git a/Telegram/SourceFiles/menu/menu_ttl_validator.cpp b/Telegram/SourceFiles/menu/menu_ttl_validator.cpp index 9221e79074..4c1031ad63 100644 --- a/Telegram/SourceFiles/menu/menu_ttl_validator.cpp +++ b/Telegram/SourceFiles/menu/menu_ttl_validator.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_peer.h" #include "data/data_user.h" #include "lang/lang_keys.h" +#include "main/session/session_show.h" #include "main/main_session.h" #include "menu/menu_ttl.h" #include "ui/layers/generic_box.h" @@ -133,6 +134,9 @@ const style::icon *TTLValidator::icon() const { } void TTLValidator::showBox() const { + if (Main::MakeSessionShow(_show, &_peer->session())->showFrozenError()) { + return; + } _show->showBox(Box(TTLBox, createArgs())); } diff --git a/Telegram/SourceFiles/window/window_peer_menu.cpp b/Telegram/SourceFiles/window/window_peer_menu.cpp index 08102a6bde..996096e276 100644 --- a/Telegram/SourceFiles/window/window_peer_menu.cpp +++ b/Telegram/SourceFiles/window/window_peer_menu.cpp @@ -781,7 +781,7 @@ void Filler::addBlockUser() { || user->isVerifyCodes()) { return; } - const auto window = &_controller->window(); + const auto window = _controller; const auto blockText = [](not_null user) { return user->isBlocked() ? ((user->isBot() && !user->isSupport()) @@ -793,14 +793,16 @@ void Filler::addBlockUser() { }; const auto blockAction = _addAction(blockText(user), [=] { const auto show = window->uiShow(); - if (user->isBlocked()) { + if (show->showFrozenError()) { + return; + } else if (user->isBlocked()) { PeerMenuUnblockUserWithBotRestart(show, user); } else if (user->isBot()) { user->session().api().blockedPeers().block(user); } else { window->show(Box( PeerMenuBlockUserBox, - window, + &window->window(), user, v::null, v::null)); @@ -897,9 +899,15 @@ void Filler::addNewContact() { return; } const auto controller = _controller; + const auto edit = [=] { + if (controller->showFrozenError()) { + return; + } + controller->show(Box(EditContactBox, controller, user)); + }; _addAction( tr::lng_info_add_as_contact(tr::now), - [=] { controller->show(Box(EditContactBox, controller, user)); }, + edit, &st::menuIconInvite); } @@ -921,9 +929,15 @@ void Filler::addEditContact() { return; } const auto controller = _controller; + const auto edit = [=] { + if (controller->showFrozenError()) { + return; + } + controller->show(Box(EditContactBox, controller, user)); + }; _addAction( tr::lng_info_edit_contact(tr::now), - [=] { controller->show(Box(EditContactBox, controller, user)); }, + edit, &st::menuIconEdit); } @@ -1528,6 +1542,9 @@ void PeerMenuExportChat( void PeerMenuDeleteContact( not_null controller, not_null user) { + if (controller->showFrozenError()) { + return; + } const auto text = tr::lng_sure_delete_contact( tr::now, lt_contact, @@ -1624,6 +1641,9 @@ void PeerMenuDeleteTopic( void PeerMenuShareContactBox( not_null navigation, not_null user) { + if (navigation->showFrozenError()) { + return; + } // There is no async to make weak from controller. const auto weak = std::make_shared>(); auto callback = [=](not_null thread) { diff --git a/Telegram/SourceFiles/window/window_session_controller.cpp b/Telegram/SourceFiles/window/window_session_controller.cpp index 607077828c..ccdeaaa073 100644 --- a/Telegram/SourceFiles/window/window_session_controller.cpp +++ b/Telegram/SourceFiles/window/window_session_controller.cpp @@ -2541,7 +2541,10 @@ void SessionController::showInNewWindow( void SessionController::toggleChooseChatTheme( not_null peer, - std::optional show) const { + std::optional show) { + if (showFrozenError()) { + return; + } content()->toggleChooseChatTheme(peer, show); } diff --git a/Telegram/SourceFiles/window/window_session_controller.h b/Telegram/SourceFiles/window/window_session_controller.h index c69dc06e9a..1fc2f0fe77 100644 --- a/Telegram/SourceFiles/window/window_session_controller.h +++ b/Telegram/SourceFiles/window/window_session_controller.h @@ -527,7 +527,7 @@ public: void toggleChooseChatTheme( not_null peer, - std::optional show = std::nullopt) const; + std::optional show = std::nullopt); void finishChatThemeEdit(not_null peer); [[nodiscard]] bool mainSectionShown() const {