Add some more frozen restrictions.

This commit is contained in:
John Preston 2025-03-21 12:02:12 +04:00
parent a0764190f2
commit f51320d1bc
15 changed files with 171 additions and 109 deletions

View file

@ -111,6 +111,9 @@ void AddBotToGroupBoxController::Start(
Scope scope, Scope scope,
const QString &token, const QString &token,
ChatAdminRights requestedRights) { ChatAdminRights requestedRights) {
if (controller->showFrozenError()) {
return;
}
auto initBox = [=](not_null<PeerListBox*> box) { auto initBox = [=](not_null<PeerListBox*> box) {
box->addButton(tr::lng_cancel(), [box] { box->closeBox(); }); box->addButton(tr::lng_cancel(), [box] { box->closeBox(); });
}; };

View file

@ -2308,6 +2308,10 @@ void ChooseStarGiftRecipient(
void ShowStarGiftBox( void ShowStarGiftBox(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<PeerData*> peer) { not_null<PeerData*> peer) {
if (controller->showFrozenError()) {
return;
}
struct Session { struct Session {
PeerData *peer = nullptr; PeerData *peer = nullptr;
MyGiftsDescriptor my; MyGiftsDescriptor my;

View file

@ -1354,8 +1354,64 @@ std::unique_ptr<Ui::AbstractButton> FrozenWriteRestriction(
} }
}, title->lifetime()); }, title->lifetime());
const auto info = show->session().frozen(); raw->setClickedCallback([=] {
const auto detailsBox = [=](not_null<GenericBox*> box) { show->show(Box(FrozenInfoBox, &show->session(), st));
});
return result;
}
void SelectTextInFieldWithMargins(
not_null<Ui::InputField*> field,
const TextSelection &selection) {
if (selection.empty()) {
return;
}
auto textCursor = field->textCursor();
// Try to set equal margins for top and bottom sides.
const auto charsCountInLine = field->width()
/ field->st().style.font->width('W');
const auto linesCount = field->height() / field->st().style.font->height;
const auto selectedLines = (selection.to - selection.from)
/ charsCountInLine;
constexpr auto kMinDiff = ushort(3);
if ((linesCount - selectedLines) > kMinDiff) {
textCursor.setPosition(selection.from
- charsCountInLine * ((linesCount - 1) / 2));
field->setTextCursor(textCursor);
}
textCursor.setPosition(selection.from);
field->setTextCursor(textCursor);
textCursor.setPosition(selection.to, QTextCursor::KeepAnchor);
field->setTextCursor(textCursor);
}
TextWithEntities PaidSendButtonText(tr::now_t, int stars) {
return Ui::Text::IconEmoji(&st::starIconEmoji).append(
Lang::FormatCountToShort(stars).string);
}
rpl::producer<TextWithEntities> PaidSendButtonText(
rpl::producer<int> stars,
rpl::producer<QString> fallback) {
if (fallback) {
return rpl::combine(
std::move(fallback),
std::move(stars)
) | rpl::map([=](QString zero, int count) {
return count
? PaidSendButtonText(tr::now, count)
: TextWithEntities{ zero };
});
}
return std::move(stars) | rpl::map([=](int count) {
return PaidSendButtonText(tr::now, count);
});
}
void FrozenInfoBox(
not_null<Ui::GenericBox*> box,
not_null<Main::Session*> session,
FreezeInfoStyleOverride st) {
box->setWidth(st::boxWideWidth); box->setWidth(st::boxWideWidth);
box->setStyle(st::frozenInfoBox); box->setStyle(st::frozenInfoBox);
box->setNoContentMargin(true); box->setNoContentMargin(true);
@ -1363,6 +1419,7 @@ std::unique_ptr<Ui::AbstractButton> FrozenWriteRestriction(
box->closeBox(); box->closeBox();
}); });
const auto info = session->frozen();
const auto content = box->verticalLayout(); const auto content = box->verticalLayout();
auto icon = Settings::CreateLottieIcon( auto icon = Settings::CreateLottieIcon(
content, content,
@ -1416,23 +1473,23 @@ std::unique_ptr<Ui::AbstractButton> FrozenWriteRestriction(
infoRow( infoRow(
tr::lng_frozen_subtitle1(), tr::lng_frozen_subtitle1(),
tr::lng_frozen_text1(Text::WithEntities), tr::lng_frozen_text1(Ui::Text::WithEntities),
st.violationIcon ? st.violationIcon : &st::menuIconBlock); st.violationIcon ? st.violationIcon : &st::menuIconBlock);
infoRow( infoRow(
tr::lng_frozen_subtitle2(), tr::lng_frozen_subtitle2(),
tr::lng_frozen_text2(Text::WithEntities), tr::lng_frozen_text2(Ui::Text::WithEntities),
st.readOnlyIcon ? st.readOnlyIcon : &st::menuIconLock); st.readOnlyIcon ? st.readOnlyIcon : &st::menuIconLock);
infoRow( infoRow(
tr::lng_frozen_subtitle3(), tr::lng_frozen_subtitle3(),
tr::lng_frozen_text3( tr::lng_frozen_text3(
lt_link, lt_link,
rpl::single(Text::Link(u"@SpamBot"_q, info.appealUrl)), rpl::single(Ui::Text::Link(u"@SpamBot"_q, info.appealUrl)),
lt_date, lt_date,
rpl::single(TextWithEntities{ rpl::single(TextWithEntities{
langDayOfMonthFull( langDayOfMonthFull(
base::unixtime::parse(info.until).date()), base::unixtime::parse(info.until).date()),
}), }),
Text::WithEntities), Ui::Text::WithEntities),
st.appealIcon ? st.appealIcon : &st::menuIconHourglass); st.appealIcon ? st.appealIcon : &st::menuIconHourglass);
const auto button = box->addButton( const auto button = box->addButton(
@ -1447,57 +1504,4 @@ std::unique_ptr<Ui::AbstractButton> FrozenWriteRestriction(
}) | rpl::start_with_next([=] { }) | rpl::start_with_next([=] {
button->resizeToWidth(buttonWidth); button->resizeToWidth(buttonWidth);
}, button->lifetime()); }, button->lifetime());
};
raw->setClickedCallback([=] {
show->show(Box(detailsBox));
});
return result;
}
void SelectTextInFieldWithMargins(
not_null<Ui::InputField*> field,
const TextSelection &selection) {
if (selection.empty()) {
return;
}
auto textCursor = field->textCursor();
// Try to set equal margins for top and bottom sides.
const auto charsCountInLine = field->width()
/ field->st().style.font->width('W');
const auto linesCount = field->height() / field->st().style.font->height;
const auto selectedLines = (selection.to - selection.from)
/ charsCountInLine;
constexpr auto kMinDiff = ushort(3);
if ((linesCount - selectedLines) > kMinDiff) {
textCursor.setPosition(selection.from
- charsCountInLine * ((linesCount - 1) / 2));
field->setTextCursor(textCursor);
}
textCursor.setPosition(selection.from);
field->setTextCursor(textCursor);
textCursor.setPosition(selection.to, QTextCursor::KeepAnchor);
field->setTextCursor(textCursor);
}
TextWithEntities PaidSendButtonText(tr::now_t, int stars) {
return Ui::Text::IconEmoji(&st::starIconEmoji).append(
Lang::FormatCountToShort(stars).string);
}
rpl::producer<TextWithEntities> PaidSendButtonText(
rpl::producer<int> stars,
rpl::producer<QString> fallback) {
if (fallback) {
return rpl::combine(
std::move(fallback),
std::move(stars)
) | rpl::map([=](QString zero, int count) {
return count
? PaidSendButtonText(tr::now, count)
: TextWithEntities{ zero };
});
}
return std::move(stars) | rpl::map([=](int count) {
return PaidSendButtonText(tr::now, count);
});
} }

View file

@ -42,6 +42,7 @@ struct WriteRestriction;
} // namespace HistoryView::Controls } // namespace HistoryView::Controls
namespace Ui { namespace Ui {
class GenericBox;
class PopupMenu; class PopupMenu;
class Show; class Show;
} // namespace Ui } // namespace Ui
@ -210,3 +211,8 @@ void SelectTextInFieldWithMargins(
[[nodiscard]] rpl::producer<TextWithEntities> PaidSendButtonText( [[nodiscard]] rpl::producer<TextWithEntities> PaidSendButtonText(
rpl::producer<int> stars, rpl::producer<int> stars,
rpl::producer<QString> fallback = nullptr); rpl::producer<QString> fallback = nullptr);
void FrozenInfoBox(
not_null<Ui::GenericBox*> box,
not_null<Main::Session*> session,
FreezeInfoStyleOverride st);

View file

@ -621,7 +621,9 @@ void HistoryInner::setupSwipeReplyAndBack() {
} }
bool HistoryInner::hasSelectRestriction() const { bool HistoryInner::hasSelectRestriction() const {
if (!_sharingDisallowed.current()) { if (session().frozen()) {
return true;
} else if (!_sharingDisallowed.current()) {
return false; return false;
} else if (const auto chat = _peer->asChat()) { } else if (const auto chat = _peer->asChat()) {
return !chat->canDeleteMessages(); return !chat->canDeleteMessages();

View file

@ -1646,8 +1646,9 @@ bool ListWidget::showCopyRestrictionForSelected() {
} }
bool ListWidget::hasSelectRestriction() const { bool ListWidget::hasSelectRestriction() const {
return _delegate->listSelectRestrictionType() return session().frozen()
!= CopyRestrictionType::None; || (_delegate->listSelectRestrictionType()
!= CopyRestrictionType::None);
} }
Element *ListWidget::lookupItemByY(int y) const { Element *ListWidget::lookupItemByY(int y) const {

View file

@ -294,6 +294,9 @@ not_null<Ui::SettingsButton*> AddPeerGiftsButton(
}, },
tracker)->entity(); tracker)->entity();
result->addClickHandler([=] { result->addClickHandler([=] {
if (navigation->showFrozenError()) {
return;
}
navigation->showSection( navigation->showSection(
std::make_shared<Info::Memento>( std::make_shared<Info::Memento>(
peer, peer,

View file

@ -62,7 +62,9 @@ Type Provider::type() {
} }
bool Provider::hasSelectRestriction() { bool Provider::hasSelectRestriction() {
if (_peer->allowsForwarding()) { if (_peer->session().frozen()) {
return true;
} else if (_peer->allowsForwarding()) {
return false; return false;
} else if (const auto chat = _peer->asChat()) { } else if (const auto chat = _peer->asChat()) {
return !chat->canDeleteMessages(); return !chat->canDeleteMessages();

View file

@ -2335,11 +2335,17 @@ void ActionsFiller::addShareContactAction(not_null<UserData*> user) {
void ActionsFiller::addEditContactAction(not_null<UserData*> user) { void ActionsFiller::addEditContactAction(not_null<UserData*> user) {
const auto controller = _controller->parentController(); const auto controller = _controller->parentController();
const auto edit = [=] {
if (controller->showFrozenError()) {
return;
}
controller->window().show(Box(EditContactBox, controller, user));
};
AddActionButton( AddActionButton(
_wrap, _wrap,
tr::lng_info_edit_contact(), tr::lng_info_edit_contact(),
IsContactValue(user), IsContactValue(user),
[=] { controller->window().show(Box(EditContactBox, controller, user)); }, edit,
&st::infoIconEdit); &st::infoIconEdit);
} }

View file

@ -75,7 +75,9 @@ Type Provider::type() {
} }
bool Provider::hasSelectRestriction() { 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 !channel->canEditStories() && !channel->canDeleteStories();
} }
return !_peer->isSelf(); return !_peer->isSelf();

View file

@ -7,8 +7,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#include "main/session/session_show.h" #include "main/session/session_show.h"
#include "chat_helpers/message_field.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "ui/layers/generic_box.h"
namespace Main { namespace Main {
namespace { namespace {
@ -77,7 +79,7 @@ bool SessionShow::showFrozenError() {
if (!session().frozen()) { if (!session().frozen()) {
return false; return false;
} }
showToast(tr::lng_frozen_bar_title(tr::now)); showBox(Box(FrozenInfoBox, &session(), FreezeInfoStyleOverride()));
return true; return true;
} }

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_peer.h" #include "data/data_peer.h"
#include "data/data_user.h" #include "data/data_user.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "main/session/session_show.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "menu/menu_ttl.h" #include "menu/menu_ttl.h"
#include "ui/layers/generic_box.h" #include "ui/layers/generic_box.h"
@ -133,6 +134,9 @@ const style::icon *TTLValidator::icon() const {
} }
void TTLValidator::showBox() const { void TTLValidator::showBox() const {
if (Main::MakeSessionShow(_show, &_peer->session())->showFrozenError()) {
return;
}
_show->showBox(Box(TTLBox, createArgs())); _show->showBox(Box(TTLBox, createArgs()));
} }

View file

@ -781,7 +781,7 @@ void Filler::addBlockUser() {
|| user->isVerifyCodes()) { || user->isVerifyCodes()) {
return; return;
} }
const auto window = &_controller->window(); const auto window = _controller;
const auto blockText = [](not_null<UserData*> user) { const auto blockText = [](not_null<UserData*> user) {
return user->isBlocked() return user->isBlocked()
? ((user->isBot() && !user->isSupport()) ? ((user->isBot() && !user->isSupport())
@ -793,14 +793,16 @@ void Filler::addBlockUser() {
}; };
const auto blockAction = _addAction(blockText(user), [=] { const auto blockAction = _addAction(blockText(user), [=] {
const auto show = window->uiShow(); const auto show = window->uiShow();
if (user->isBlocked()) { if (show->showFrozenError()) {
return;
} else if (user->isBlocked()) {
PeerMenuUnblockUserWithBotRestart(show, user); PeerMenuUnblockUserWithBotRestart(show, user);
} else if (user->isBot()) { } else if (user->isBot()) {
user->session().api().blockedPeers().block(user); user->session().api().blockedPeers().block(user);
} else { } else {
window->show(Box( window->show(Box(
PeerMenuBlockUserBox, PeerMenuBlockUserBox,
window, &window->window(),
user, user,
v::null, v::null,
v::null)); v::null));
@ -897,9 +899,15 @@ void Filler::addNewContact() {
return; return;
} }
const auto controller = _controller; const auto controller = _controller;
const auto edit = [=] {
if (controller->showFrozenError()) {
return;
}
controller->show(Box(EditContactBox, controller, user));
};
_addAction( _addAction(
tr::lng_info_add_as_contact(tr::now), tr::lng_info_add_as_contact(tr::now),
[=] { controller->show(Box(EditContactBox, controller, user)); }, edit,
&st::menuIconInvite); &st::menuIconInvite);
} }
@ -921,9 +929,15 @@ void Filler::addEditContact() {
return; return;
} }
const auto controller = _controller; const auto controller = _controller;
const auto edit = [=] {
if (controller->showFrozenError()) {
return;
}
controller->show(Box(EditContactBox, controller, user));
};
_addAction( _addAction(
tr::lng_info_edit_contact(tr::now), tr::lng_info_edit_contact(tr::now),
[=] { controller->show(Box(EditContactBox, controller, user)); }, edit,
&st::menuIconEdit); &st::menuIconEdit);
} }
@ -1528,6 +1542,9 @@ void PeerMenuExportChat(
void PeerMenuDeleteContact( void PeerMenuDeleteContact(
not_null<Window::SessionController*> controller, not_null<Window::SessionController*> controller,
not_null<UserData*> user) { not_null<UserData*> user) {
if (controller->showFrozenError()) {
return;
}
const auto text = tr::lng_sure_delete_contact( const auto text = tr::lng_sure_delete_contact(
tr::now, tr::now,
lt_contact, lt_contact,
@ -1624,6 +1641,9 @@ void PeerMenuDeleteTopic(
void PeerMenuShareContactBox( void PeerMenuShareContactBox(
not_null<Window::SessionNavigation*> navigation, not_null<Window::SessionNavigation*> navigation,
not_null<UserData*> user) { not_null<UserData*> user) {
if (navigation->showFrozenError()) {
return;
}
// There is no async to make weak from controller. // There is no async to make weak from controller.
const auto weak = std::make_shared<QPointer<Ui::BoxContent>>(); const auto weak = std::make_shared<QPointer<Ui::BoxContent>>();
auto callback = [=](not_null<Data::Thread*> thread) { auto callback = [=](not_null<Data::Thread*> thread) {

View file

@ -2541,7 +2541,10 @@ void SessionController::showInNewWindow(
void SessionController::toggleChooseChatTheme( void SessionController::toggleChooseChatTheme(
not_null<PeerData*> peer, not_null<PeerData*> peer,
std::optional<bool> show) const { std::optional<bool> show) {
if (showFrozenError()) {
return;
}
content()->toggleChooseChatTheme(peer, show); content()->toggleChooseChatTheme(peer, show);
} }

View file

@ -527,7 +527,7 @@ public:
void toggleChooseChatTheme( void toggleChooseChatTheme(
not_null<PeerData*> peer, not_null<PeerData*> peer,
std::optional<bool> show = std::nullopt) const; std::optional<bool> show = std::nullopt);
void finishChatThemeEdit(not_null<PeerData*> peer); void finishChatThemeEdit(not_null<PeerData*> peer);
[[nodiscard]] bool mainSectionShown() const { [[nodiscard]] bool mainSectionShown() const {