mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-25 15:03:03 +02:00
Respect price of messages to channels.
This commit is contained in:
parent
b91a040a32
commit
5dc50b6d96
7 changed files with 35 additions and 21 deletions
|
@ -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*> history)
|
|||
int valuesCount,
|
||||
Fn<int(int)> valueByIndex,
|
||||
int value,
|
||||
int minValue,
|
||||
int maxValue,
|
||||
Fn<void(int)> valueProgress,
|
||||
Fn<void(int)> valueFinished) {
|
||||
|
@ -473,7 +474,7 @@ auto PrivacyExceptionsBoxController::createRow(not_null<History*> history)
|
|||
const auto labels = raw->add(object_ptr<Ui::RpWidget>(raw));
|
||||
const auto min = Ui::CreateChild<Ui::FlatLabel>(
|
||||
raw,
|
||||
QString::number(kStarsMin),
|
||||
QString::number(minValue),
|
||||
*labelStyle);
|
||||
const auto max = Ui::CreateChild<Ui::FlatLabel>(
|
||||
raw,
|
||||
|
@ -1035,7 +1036,8 @@ void EditMessagesPrivacyBox(
|
|||
state->stars = SetupChargeSlider(
|
||||
chargeInner,
|
||||
session->user(),
|
||||
savedValue);
|
||||
(savedValue > 0) ? savedValue : std::optional<int>(),
|
||||
kDefaultPrivateMessagesPrice);
|
||||
|
||||
Ui::AddSkip(chargeInner);
|
||||
Ui::AddSubsectionTitle(
|
||||
|
@ -1164,14 +1166,16 @@ void EditMessagesPrivacyBox(
|
|||
rpl::producer<int> SetupChargeSlider(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<PeerData*> peer,
|
||||
int savedValue) {
|
||||
std::optional<int> savedValue,
|
||||
int defaultValue,
|
||||
bool allowZero) {
|
||||
struct State {
|
||||
rpl::variable<int> stars;
|
||||
};
|
||||
const auto broadcast = peer->isBroadcast();
|
||||
const auto group = !broadcast && !peer->isUser();
|
||||
const auto state = container->lifetime().make_state<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<int> SetupChargeSlider(
|
|||
: tr::lng_messages_privacy_price());
|
||||
|
||||
auto values = std::vector<int>();
|
||||
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<int> 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());
|
||||
|
|
|
@ -173,7 +173,9 @@ void EditMessagesPrivacyBox(
|
|||
[[nodiscard]] rpl::producer<int> SetupChargeSlider(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<PeerData*> peer,
|
||||
int savedValue);
|
||||
std::optional<int> savedValue,
|
||||
int defaultValue,
|
||||
bool allowZero = false);
|
||||
|
||||
void EditDirectMessagesPriceBox(
|
||||
not_null<Ui::GenericBox*> box,
|
||||
|
|
|
@ -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<std::pair<PowerSaving::Flag, PowerSaving::Flag>> {
|
||||
|
@ -1196,7 +1197,8 @@ void ShowEditPeerPermissionsBox(
|
|||
state->starsPerMessage = SetupChargeSlider(
|
||||
chargeInner,
|
||||
peer,
|
||||
starsPerMessage);
|
||||
(starsPerMessage > 0) ? starsPerMessage : std::optional<int>(),
|
||||
kDefaultChargeStars);
|
||||
}
|
||||
|
||||
static constexpr auto kSendRestrictions = Flag::EmbedLinks
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -166,7 +166,6 @@ private:
|
|||
Data::ChatBotCommands _botCommands;
|
||||
std::unique_ptr<Data::Forum> _forum;
|
||||
std::unique_ptr<Data::SavedMessages> _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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue