mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-26 07:23:02 +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 kPremiumsRowId = PeerId(FakeChatId(BareId(1))).value;
|
||||||
constexpr auto kMiniAppsRowId = PeerId(FakeChatId(BareId(2))).value;
|
constexpr auto kMiniAppsRowId = PeerId(FakeChatId(BareId(2))).value;
|
||||||
constexpr auto kStarsMin = 1;
|
constexpr auto kDefaultDirectMessagesPrice = 10;
|
||||||
constexpr auto kDefaultChargeStars = 10;
|
constexpr auto kDefaultPrivateMessagesPrice = 10;
|
||||||
|
|
||||||
using Exceptions = Api::UserPrivacy::Exceptions;
|
using Exceptions = Api::UserPrivacy::Exceptions;
|
||||||
|
|
||||||
|
@ -464,6 +464,7 @@ auto PrivacyExceptionsBoxController::createRow(not_null<History*> history)
|
||||||
int valuesCount,
|
int valuesCount,
|
||||||
Fn<int(int)> valueByIndex,
|
Fn<int(int)> valueByIndex,
|
||||||
int value,
|
int value,
|
||||||
|
int minValue,
|
||||||
int maxValue,
|
int maxValue,
|
||||||
Fn<void(int)> valueProgress,
|
Fn<void(int)> valueProgress,
|
||||||
Fn<void(int)> valueFinished) {
|
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 labels = raw->add(object_ptr<Ui::RpWidget>(raw));
|
||||||
const auto min = Ui::CreateChild<Ui::FlatLabel>(
|
const auto min = Ui::CreateChild<Ui::FlatLabel>(
|
||||||
raw,
|
raw,
|
||||||
QString::number(kStarsMin),
|
QString::number(minValue),
|
||||||
*labelStyle);
|
*labelStyle);
|
||||||
const auto max = Ui::CreateChild<Ui::FlatLabel>(
|
const auto max = Ui::CreateChild<Ui::FlatLabel>(
|
||||||
raw,
|
raw,
|
||||||
|
@ -1035,7 +1036,8 @@ void EditMessagesPrivacyBox(
|
||||||
state->stars = SetupChargeSlider(
|
state->stars = SetupChargeSlider(
|
||||||
chargeInner,
|
chargeInner,
|
||||||
session->user(),
|
session->user(),
|
||||||
savedValue);
|
(savedValue > 0) ? savedValue : std::optional<int>(),
|
||||||
|
kDefaultPrivateMessagesPrice);
|
||||||
|
|
||||||
Ui::AddSkip(chargeInner);
|
Ui::AddSkip(chargeInner);
|
||||||
Ui::AddSubsectionTitle(
|
Ui::AddSubsectionTitle(
|
||||||
|
@ -1164,14 +1166,16 @@ void EditMessagesPrivacyBox(
|
||||||
rpl::producer<int> SetupChargeSlider(
|
rpl::producer<int> SetupChargeSlider(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
int savedValue) {
|
std::optional<int> savedValue,
|
||||||
|
int defaultValue,
|
||||||
|
bool allowZero) {
|
||||||
struct State {
|
struct State {
|
||||||
rpl::variable<int> stars;
|
rpl::variable<int> stars;
|
||||||
};
|
};
|
||||||
const auto broadcast = peer->isBroadcast();
|
const auto broadcast = peer->isBroadcast();
|
||||||
const auto group = !broadcast && !peer->isUser();
|
const auto group = !broadcast && !peer->isUser();
|
||||||
const auto state = container->lifetime().make_state<State>();
|
const auto state = container->lifetime().make_state<State>();
|
||||||
const auto chargeStars = savedValue ? savedValue : kDefaultChargeStars;
|
const auto chargeStars = savedValue.value_or(defaultValue);
|
||||||
state->stars = chargeStars;
|
state->stars = chargeStars;
|
||||||
|
|
||||||
Ui::AddSubsectionTitle(container, (group || broadcast)
|
Ui::AddSubsectionTitle(container, (group || broadcast)
|
||||||
|
@ -1179,11 +1183,12 @@ rpl::producer<int> SetupChargeSlider(
|
||||||
: tr::lng_messages_privacy_price());
|
: tr::lng_messages_privacy_price());
|
||||||
|
|
||||||
auto values = std::vector<int>();
|
auto values = std::vector<int>();
|
||||||
|
const auto minStars = allowZero ? 0 : 1;
|
||||||
const auto maxStars = peer->session().appConfig().paidMessageStarsMax();
|
const auto maxStars = peer->session().appConfig().paidMessageStarsMax();
|
||||||
if (chargeStars < kStarsMin) {
|
if (chargeStars < minStars) {
|
||||||
values.push_back(chargeStars);
|
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);
|
values.push_back(i);
|
||||||
}
|
}
|
||||||
for (auto i = 100; i < std::min(1000, maxStars); i += 10) {
|
for (auto i = 100; i < std::min(1000, maxStars); i += 10) {
|
||||||
|
@ -1210,6 +1215,7 @@ rpl::producer<int> SetupChargeSlider(
|
||||||
valuesCount,
|
valuesCount,
|
||||||
[=](int index) { return values[index]; },
|
[=](int index) { return values[index]; },
|
||||||
chargeStars,
|
chargeStars,
|
||||||
|
minStars,
|
||||||
maxStars,
|
maxStars,
|
||||||
setStars,
|
setStars,
|
||||||
setStars),
|
setStars),
|
||||||
|
@ -1273,7 +1279,9 @@ void EditDirectMessagesPriceBox(
|
||||||
SetupChargeSlider(
|
SetupChargeSlider(
|
||||||
inner,
|
inner,
|
||||||
channel,
|
channel,
|
||||||
savedValue.value_or(0)
|
savedValue,
|
||||||
|
kDefaultDirectMessagesPrice,
|
||||||
|
true
|
||||||
) | rpl::start_with_next([=](int stars) {
|
) | rpl::start_with_next([=](int stars) {
|
||||||
*result = stars;
|
*result = stars;
|
||||||
}, box->lifetime());
|
}, box->lifetime());
|
||||||
|
|
|
@ -173,7 +173,9 @@ void EditMessagesPrivacyBox(
|
||||||
[[nodiscard]] rpl::producer<int> SetupChargeSlider(
|
[[nodiscard]] rpl::producer<int> SetupChargeSlider(
|
||||||
not_null<Ui::VerticalLayout*> container,
|
not_null<Ui::VerticalLayout*> container,
|
||||||
not_null<PeerData*> peer,
|
not_null<PeerData*> peer,
|
||||||
int savedValue);
|
std::optional<int> savedValue,
|
||||||
|
int defaultValue,
|
||||||
|
bool allowZero = false);
|
||||||
|
|
||||||
void EditDirectMessagesPriceBox(
|
void EditDirectMessagesPriceBox(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
|
|
|
@ -53,6 +53,7 @@ namespace {
|
||||||
constexpr auto kSlowmodeValues = 7;
|
constexpr auto kSlowmodeValues = 7;
|
||||||
constexpr auto kBoostsUnrestrictValues = 5;
|
constexpr auto kBoostsUnrestrictValues = 5;
|
||||||
constexpr auto kForceDisableTooltipDuration = 3 * crl::time(1000);
|
constexpr auto kForceDisableTooltipDuration = 3 * crl::time(1000);
|
||||||
|
constexpr auto kDefaultChargeStars = 10;
|
||||||
|
|
||||||
[[nodiscard]] auto Dependencies(PowerSaving::Flags)
|
[[nodiscard]] auto Dependencies(PowerSaving::Flags)
|
||||||
-> std::vector<std::pair<PowerSaving::Flag, PowerSaving::Flag>> {
|
-> std::vector<std::pair<PowerSaving::Flag, PowerSaving::Flag>> {
|
||||||
|
@ -1196,7 +1197,8 @@ void ShowEditPeerPermissionsBox(
|
||||||
state->starsPerMessage = SetupChargeSlider(
|
state->starsPerMessage = SetupChargeSlider(
|
||||||
chargeInner,
|
chargeInner,
|
||||||
peer,
|
peer,
|
||||||
starsPerMessage);
|
(starsPerMessage > 0) ? starsPerMessage : std::optional<int>(),
|
||||||
|
kDefaultChargeStars);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr auto kSendRestrictions = Flag::EmbedLinks
|
static constexpr auto kSendRestrictions = Flag::EmbedLinks
|
||||||
|
|
|
@ -934,15 +934,17 @@ void ChannelData::growSlowmodeLastMessage(TimeId when) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int ChannelData::starsPerMessage() const {
|
int ChannelData::starsPerMessage() const {
|
||||||
if (const auto info = mgInfo.get()) {
|
if (const auto broadcast = monoforumBroadcast()) {
|
||||||
return info->_starsPerMessage;
|
if (!amMonoforumAdmin()) {
|
||||||
|
return broadcast->starsPerMessage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return _starsPerMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelData::setStarsPerMessage(int stars) {
|
void ChannelData::setStarsPerMessage(int stars) {
|
||||||
if (mgInfo && starsPerMessage() != stars) {
|
if (_starsPerMessage != stars) {
|
||||||
mgInfo->_starsPerMessage = stars;
|
_starsPerMessage = stars;
|
||||||
session().changes().peerUpdated(this, UpdateFlag::StarsPerMessage);
|
session().changes().peerUpdated(this, UpdateFlag::StarsPerMessage);
|
||||||
}
|
}
|
||||||
checkTrustedPayForMessage();
|
checkTrustedPayForMessage();
|
||||||
|
|
|
@ -166,7 +166,6 @@ private:
|
||||||
Data::ChatBotCommands _botCommands;
|
Data::ChatBotCommands _botCommands;
|
||||||
std::unique_ptr<Data::Forum> _forum;
|
std::unique_ptr<Data::Forum> _forum;
|
||||||
std::unique_ptr<Data::SavedMessages> _monoforum;
|
std::unique_ptr<Data::SavedMessages> _monoforum;
|
||||||
int _starsPerMessage = 0;
|
|
||||||
|
|
||||||
friend class ChannelData;
|
friend class ChannelData;
|
||||||
|
|
||||||
|
@ -596,6 +595,7 @@ private:
|
||||||
int _kickedCount = 0;
|
int _kickedCount = 0;
|
||||||
int _pendingRequestsCount = 0;
|
int _pendingRequestsCount = 0;
|
||||||
int _levelHint = 0;
|
int _levelHint = 0;
|
||||||
|
int _starsPerMessage = 0;
|
||||||
|
|
||||||
Data::AllowedReactions _allowedReactions;
|
Data::AllowedReactions _allowedReactions;
|
||||||
|
|
||||||
|
|
|
@ -1621,9 +1621,9 @@ int PeerData::starsPerMessage() const {
|
||||||
|
|
||||||
int PeerData::starsPerMessageChecked() const {
|
int PeerData::starsPerMessageChecked() const {
|
||||||
if (const auto channel = asChannel()) {
|
if (const auto channel = asChannel()) {
|
||||||
return (channel->adminRights() || channel->amCreator())
|
if (channel->adminRights() || channel->amCreator()) {
|
||||||
? 0
|
return 0;
|
||||||
: channel->starsPerMessage();
|
}
|
||||||
}
|
}
|
||||||
return starsPerMessage();
|
return starsPerMessage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2114,7 +2114,7 @@ void HistoryWidget::setupDirectMessageButton() {
|
||||||
_muteUnmute.data(),
|
_muteUnmute.data(),
|
||||||
st::historyDirectMessage);
|
st::historyDirectMessage);
|
||||||
widthValue() | rpl::start_with_next([=](int width) {
|
widthValue() | rpl::start_with_next([=](int width) {
|
||||||
_directMessage->moveToRight(0, 0, width);
|
_directMessage->moveToLeft(0, 0, width);
|
||||||
}, _directMessage->lifetime());
|
}, _directMessage->lifetime());
|
||||||
_directMessage->setClickedCallback([=] {
|
_directMessage->setClickedCallback([=] {
|
||||||
if (const auto channel = _peer ? _peer->asChannel() : nullptr) {
|
if (const auto channel = _peer ? _peer->asChannel() : nullptr) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue