From 5dc50b6d96d7137ca8c2b4de20e3d0f462aeb0db Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 16 May 2025 13:45:00 +0400 Subject: [PATCH] Respect price of messages to channels. --- .../SourceFiles/boxes/edit_privacy_box.cpp | 26 ++++++++++++------- Telegram/SourceFiles/boxes/edit_privacy_box.h | 4 ++- .../boxes/peers/edit_peer_permissions_box.cpp | 4 ++- Telegram/SourceFiles/data/data_channel.cpp | 12 +++++---- Telegram/SourceFiles/data/data_channel.h | 2 +- Telegram/SourceFiles/data/data_peer.cpp | 6 ++--- .../SourceFiles/history/history_widget.cpp | 2 +- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp index 1f83b004cb..2047539943 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.cpp @@ -45,8 +45,8 @@ namespace { constexpr auto kPremiumsRowId = PeerId(FakeChatId(BareId(1))).value; constexpr auto kMiniAppsRowId = PeerId(FakeChatId(BareId(2))).value; -constexpr auto kStarsMin = 1; -constexpr auto kDefaultChargeStars = 10; +constexpr auto kDefaultDirectMessagesPrice = 10; +constexpr auto kDefaultPrivateMessagesPrice = 10; using Exceptions = Api::UserPrivacy::Exceptions; @@ -464,6 +464,7 @@ auto PrivacyExceptionsBoxController::createRow(not_null history) int valuesCount, Fn valueByIndex, int value, + int minValue, int maxValue, Fn valueProgress, Fn valueFinished) { @@ -473,7 +474,7 @@ auto PrivacyExceptionsBoxController::createRow(not_null history) const auto labels = raw->add(object_ptr(raw)); const auto min = Ui::CreateChild( raw, - QString::number(kStarsMin), + QString::number(minValue), *labelStyle); const auto max = Ui::CreateChild( raw, @@ -1035,7 +1036,8 @@ void EditMessagesPrivacyBox( state->stars = SetupChargeSlider( chargeInner, session->user(), - savedValue); + (savedValue > 0) ? savedValue : std::optional(), + kDefaultPrivateMessagesPrice); Ui::AddSkip(chargeInner); Ui::AddSubsectionTitle( @@ -1164,14 +1166,16 @@ void EditMessagesPrivacyBox( rpl::producer SetupChargeSlider( not_null container, not_null peer, - int savedValue) { + std::optional savedValue, + int defaultValue, + bool allowZero) { struct State { rpl::variable stars; }; const auto broadcast = peer->isBroadcast(); const auto group = !broadcast && !peer->isUser(); const auto state = container->lifetime().make_state(); - const auto chargeStars = savedValue ? savedValue : kDefaultChargeStars; + const auto chargeStars = savedValue.value_or(defaultValue); state->stars = chargeStars; Ui::AddSubsectionTitle(container, (group || broadcast) @@ -1179,11 +1183,12 @@ rpl::producer SetupChargeSlider( : tr::lng_messages_privacy_price()); auto values = std::vector(); + const auto minStars = allowZero ? 0 : 1; const auto maxStars = peer->session().appConfig().paidMessageStarsMax(); - if (chargeStars < kStarsMin) { + if (chargeStars < minStars) { values.push_back(chargeStars); } - for (auto i = kStarsMin; i < std::min(100, maxStars); ++i) { + for (auto i = minStars; i < std::min(100, maxStars); ++i) { values.push_back(i); } for (auto i = 100; i < std::min(1000, maxStars); i += 10) { @@ -1210,6 +1215,7 @@ rpl::producer SetupChargeSlider( valuesCount, [=](int index) { return values[index]; }, chargeStars, + minStars, maxStars, setStars, setStars), @@ -1273,7 +1279,9 @@ void EditDirectMessagesPriceBox( SetupChargeSlider( inner, channel, - savedValue.value_or(0) + savedValue, + kDefaultDirectMessagesPrice, + true ) | rpl::start_with_next([=](int stars) { *result = stars; }, box->lifetime()); diff --git a/Telegram/SourceFiles/boxes/edit_privacy_box.h b/Telegram/SourceFiles/boxes/edit_privacy_box.h index d194572dc3..d46cbbfa8e 100644 --- a/Telegram/SourceFiles/boxes/edit_privacy_box.h +++ b/Telegram/SourceFiles/boxes/edit_privacy_box.h @@ -173,7 +173,9 @@ void EditMessagesPrivacyBox( [[nodiscard]] rpl::producer SetupChargeSlider( not_null container, not_null peer, - int savedValue); + std::optional savedValue, + int defaultValue, + bool allowZero = false); void EditDirectMessagesPriceBox( not_null box, diff --git a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp index 58cfd01fcf..d171501b95 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_peer_permissions_box.cpp @@ -53,6 +53,7 @@ namespace { constexpr auto kSlowmodeValues = 7; constexpr auto kBoostsUnrestrictValues = 5; constexpr auto kForceDisableTooltipDuration = 3 * crl::time(1000); +constexpr auto kDefaultChargeStars = 10; [[nodiscard]] auto Dependencies(PowerSaving::Flags) -> std::vector> { @@ -1196,7 +1197,8 @@ void ShowEditPeerPermissionsBox( state->starsPerMessage = SetupChargeSlider( chargeInner, peer, - starsPerMessage); + (starsPerMessage > 0) ? starsPerMessage : std::optional(), + kDefaultChargeStars); } static constexpr auto kSendRestrictions = Flag::EmbedLinks diff --git a/Telegram/SourceFiles/data/data_channel.cpp b/Telegram/SourceFiles/data/data_channel.cpp index b207e62857..213737dd45 100644 --- a/Telegram/SourceFiles/data/data_channel.cpp +++ b/Telegram/SourceFiles/data/data_channel.cpp @@ -934,15 +934,17 @@ void ChannelData::growSlowmodeLastMessage(TimeId when) { } int ChannelData::starsPerMessage() const { - if (const auto info = mgInfo.get()) { - return info->_starsPerMessage; + if (const auto broadcast = monoforumBroadcast()) { + if (!amMonoforumAdmin()) { + return broadcast->starsPerMessage(); + } } - return 0; + return _starsPerMessage; } void ChannelData::setStarsPerMessage(int stars) { - if (mgInfo && starsPerMessage() != stars) { - mgInfo->_starsPerMessage = stars; + if (_starsPerMessage != stars) { + _starsPerMessage = stars; session().changes().peerUpdated(this, UpdateFlag::StarsPerMessage); } checkTrustedPayForMessage(); diff --git a/Telegram/SourceFiles/data/data_channel.h b/Telegram/SourceFiles/data/data_channel.h index 1a502f5290..5b8c637120 100644 --- a/Telegram/SourceFiles/data/data_channel.h +++ b/Telegram/SourceFiles/data/data_channel.h @@ -166,7 +166,6 @@ private: Data::ChatBotCommands _botCommands; std::unique_ptr _forum; std::unique_ptr _monoforum; - int _starsPerMessage = 0; friend class ChannelData; @@ -596,6 +595,7 @@ private: int _kickedCount = 0; int _pendingRequestsCount = 0; int _levelHint = 0; + int _starsPerMessage = 0; Data::AllowedReactions _allowedReactions; diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp index 2799c278c3..80d81c74bb 100644 --- a/Telegram/SourceFiles/data/data_peer.cpp +++ b/Telegram/SourceFiles/data/data_peer.cpp @@ -1621,9 +1621,9 @@ int PeerData::starsPerMessage() const { int PeerData::starsPerMessageChecked() const { if (const auto channel = asChannel()) { - return (channel->adminRights() || channel->amCreator()) - ? 0 - : channel->starsPerMessage(); + if (channel->adminRights() || channel->amCreator()) { + return 0; + } } return starsPerMessage(); } diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 0ce8c1becd..c66d5cbb86 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -2114,7 +2114,7 @@ void HistoryWidget::setupDirectMessageButton() { _muteUnmute.data(), st::historyDirectMessage); widthValue() | rpl::start_with_next([=](int width) { - _directMessage->moveToRight(0, 0, width); + _directMessage->moveToLeft(0, 0, width); }, _directMessage->lifetime()); _directMessage->setClickedCallback([=] { if (const auto channel = _peer ? _peer->asChannel() : nullptr) {