mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-08 08:04:08 +02:00
Use paid messages values from appConfig.
This commit is contained in:
parent
9032489786
commit
827040f487
7 changed files with 142 additions and 102 deletions
|
@ -45,9 +45,7 @@ namespace {
|
|||
|
||||
constexpr auto kPremiumsRowId = PeerId(FakeChatId(BareId(1))).value;
|
||||
constexpr auto kMiniAppsRowId = PeerId(FakeChatId(BareId(2))).value;
|
||||
constexpr auto kGetPercent = 85;
|
||||
constexpr auto kStarsMin = 1;
|
||||
constexpr auto kStarsMax = 10000;
|
||||
constexpr auto kDefaultChargeStars = 10;
|
||||
|
||||
using Exceptions = Api::UserPrivacy::Exceptions;
|
||||
|
@ -466,6 +464,7 @@ auto PrivacyExceptionsBoxController::createRow(not_null<History*> history)
|
|||
int valuesCount,
|
||||
Fn<int(int)> valueByIndex,
|
||||
int value,
|
||||
int maxValue,
|
||||
Fn<void(int)> valueProgress,
|
||||
Fn<void(int)> valueFinished) {
|
||||
auto result = object_ptr<Ui::VerticalLayout>(parent);
|
||||
|
@ -478,7 +477,7 @@ auto PrivacyExceptionsBoxController::createRow(not_null<History*> history)
|
|||
*labelStyle);
|
||||
const auto max = Ui::CreateChild<Ui::FlatLabel>(
|
||||
raw,
|
||||
QString::number(kStarsMax),
|
||||
QString::number(maxValue),
|
||||
*labelStyle);
|
||||
const auto current = Ui::CreateChild<Ui::FlatLabel>(
|
||||
raw,
|
||||
|
@ -999,7 +998,10 @@ void EditMessagesPrivacyBox(
|
|||
|
||||
Ui::AddDividerText(inner, tr::lng_messages_privacy_about());
|
||||
|
||||
const auto charged = inner->add(
|
||||
const auto available = session->appConfig().paidMessagesAvailable();
|
||||
|
||||
const auto charged = available
|
||||
? inner->add(
|
||||
object_ptr<Ui::Radiobutton>(
|
||||
inner,
|
||||
group,
|
||||
|
@ -1010,8 +1012,16 @@ void EditMessagesPrivacyBox(
|
|||
0,
|
||||
st::messagePrivacyBottomSkip,
|
||||
0,
|
||||
st::messagePrivacyBottomSkip));
|
||||
st::messagePrivacyBottomSkip))
|
||||
: nullptr;
|
||||
|
||||
struct State {
|
||||
rpl::variable<int> stars;
|
||||
};
|
||||
const auto state = std::make_shared<State>();
|
||||
const auto savedValue = privacy->newChargeStarsCurrent();
|
||||
|
||||
if (available) {
|
||||
Ui::AddDividerText(inner, tr::lng_messages_privacy_charge_about());
|
||||
|
||||
const auto chargeWrap = inner->add(
|
||||
|
@ -1022,12 +1032,6 @@ void EditMessagesPrivacyBox(
|
|||
|
||||
Ui::AddSkip(chargeInner);
|
||||
|
||||
struct State {
|
||||
rpl::variable<int> stars;
|
||||
};
|
||||
const auto state = std::make_shared<State>();
|
||||
const auto savedValue = privacy->newChargeStarsCurrent();
|
||||
|
||||
state->stars = SetupChargeSlider(
|
||||
chargeInner,
|
||||
session->user(),
|
||||
|
@ -1070,12 +1074,14 @@ void EditMessagesPrivacyBox(
|
|||
});
|
||||
});
|
||||
Ui::AddSkip(chargeInner);
|
||||
Ui::AddDividerText(chargeInner, tr::lng_messages_privacy_remove_about());
|
||||
Ui::AddDividerText(
|
||||
chargeInner,
|
||||
tr::lng_messages_privacy_remove_about());
|
||||
|
||||
using namespace rpl::mappers;
|
||||
chargeWrap->toggleOn(group->value() | rpl::map(_1 == kOptionCharge));
|
||||
chargeWrap->finishAnimating();
|
||||
|
||||
}
|
||||
using WeakToast = base::weak_ptr<Ui::Toast::Instance>;
|
||||
const auto toast = std::make_shared<WeakToast>();
|
||||
const auto showToast = [=] {
|
||||
|
@ -1108,7 +1114,9 @@ void EditMessagesPrivacyBox(
|
|||
|
||||
if (!allowed()) {
|
||||
CreateRadiobuttonLock(restricted, st::messagePrivacyCheck);
|
||||
if (charged) {
|
||||
CreateRadiobuttonLock(charged, st::messagePrivacyCheck);
|
||||
}
|
||||
|
||||
group->setChangedCallback([=](int value) {
|
||||
if (value == kOptionPremium || value == kOptionCharge) {
|
||||
|
@ -1170,19 +1178,20 @@ rpl::producer<int> SetupChargeSlider(
|
|||
: tr::lng_messages_privacy_price());
|
||||
|
||||
auto values = std::vector<int>();
|
||||
const auto maxStars = peer->session().appConfig().paidMessageStarsMax();
|
||||
if (chargeStars < kStarsMin) {
|
||||
values.push_back(chargeStars);
|
||||
}
|
||||
for (auto i = kStarsMin; i < 100; ++i) {
|
||||
for (auto i = kStarsMin; i < std::min(100, maxStars); ++i) {
|
||||
values.push_back(i);
|
||||
}
|
||||
for (auto i = 100; i < 1000; i += 10) {
|
||||
for (auto i = 100; i < std::min(1000, maxStars); i += 10) {
|
||||
if (i < chargeStars + 10 && chargeStars < i) {
|
||||
values.push_back(chargeStars);
|
||||
}
|
||||
values.push_back(i);
|
||||
}
|
||||
for (auto i = 1000; i < kStarsMax + 1; i += 100) {
|
||||
for (auto i = 1000; i < maxStars + 1; i += 100) {
|
||||
if (i < chargeStars + 100 && chargeStars < i) {
|
||||
values.push_back(chargeStars);
|
||||
}
|
||||
|
@ -1200,6 +1209,7 @@ rpl::producer<int> SetupChargeSlider(
|
|||
valuesCount,
|
||||
[=](int index) { return values[index]; },
|
||||
chargeStars,
|
||||
maxStars,
|
||||
setStars,
|
||||
setStars),
|
||||
st::boxRowPadding);
|
||||
|
@ -1208,19 +1218,18 @@ rpl::producer<int> SetupChargeSlider(
|
|||
Ui::AddSkip(container, skip);
|
||||
|
||||
auto dollars = state->stars.value() | rpl::map([=](int stars) {
|
||||
const auto ratio = peer->session().appConfig().get<float64>(
|
||||
u"stars_usd_withdraw_rate_x1000"_q,
|
||||
1200);
|
||||
const auto dollars = int(base::SafeRound(stars * (ratio / 1000.)));
|
||||
const auto ratio = peer->session().appConfig().starsWithdrawRate();
|
||||
const auto dollars = int(base::SafeRound(stars * ratio));
|
||||
return '~' + Ui::FillAmountAndCurrency(dollars, u"USD"_q);
|
||||
});
|
||||
const auto percent = peer->session().appConfig().paidMessageCommission();
|
||||
Ui::AddDividerText(
|
||||
container,
|
||||
(group
|
||||
? tr::lng_rights_charge_price_about
|
||||
: tr::lng_messages_privacy_price_about)(
|
||||
lt_percent,
|
||||
rpl::single(QString::number(kGetPercent) + '%'),
|
||||
rpl::single(QString::number(percent / 10.) + '%'),
|
||||
lt_amount,
|
||||
std::move(dollars)));
|
||||
|
||||
|
|
|
@ -1160,14 +1160,18 @@ void ShowEditPeerPermissionsBox(
|
|||
rpl::variable<int> starsPerMessage;
|
||||
};
|
||||
const auto state = inner->lifetime().make_state<State>();
|
||||
const auto channel = peer->asChannel();
|
||||
const auto available = channel && channel->paidMessagesAvailable();
|
||||
|
||||
Ui::AddSkip(inner);
|
||||
Ui::AddDivider(inner);
|
||||
auto charging = (Ui::SettingsButton*)nullptr;
|
||||
if (available) {
|
||||
Ui::AddSkip(inner);
|
||||
const auto starsPerMessage = peer->isChannel()
|
||||
? peer->asChannel()->starsPerMessage()
|
||||
: 0;
|
||||
const auto charging = inner->add(object_ptr<Ui::SettingsButton>(
|
||||
charging = inner->add(object_ptr<Ui::SettingsButton>(
|
||||
inner,
|
||||
tr::lng_rights_charge_stars(),
|
||||
st::settingsButtonNoIcon));
|
||||
|
@ -1188,6 +1192,7 @@ void ShowEditPeerPermissionsBox(
|
|||
chargeInner,
|
||||
peer,
|
||||
starsPerMessage);
|
||||
}
|
||||
|
||||
static constexpr auto kSendRestrictions = Flag::EmbedLinks
|
||||
| Flag::SendGames
|
||||
|
@ -1242,7 +1247,7 @@ void ShowEditPeerPermissionsBox(
|
|||
const auto boostsUnrestrict = hasRestrictions
|
||||
? state->boostsUnrestrict.current()
|
||||
: 0;
|
||||
const auto starsPerMessage = charging->toggled()
|
||||
const auto starsPerMessage = (charging && charging->toggled())
|
||||
? state->starsPerMessage.current()
|
||||
: 0;
|
||||
done({
|
||||
|
|
|
@ -37,10 +37,7 @@ void Credits::apply(const MTPDupdateStarsBalance &data) {
|
|||
|
||||
rpl::producer<float64> Credits::rateValue(
|
||||
not_null<PeerData*> ownedBotOrChannel) {
|
||||
return rpl::single(
|
||||
_session->appConfig().get<float64>(
|
||||
u"stars_usd_withdraw_rate_x1000"_q,
|
||||
1200) / 1000.);
|
||||
return rpl::single(_session->appConfig().starsWithdrawRate());
|
||||
}
|
||||
|
||||
void Credits::load(bool force) {
|
||||
|
|
|
@ -1167,7 +1167,8 @@ void ApplyChannelUpdate(
|
|||
| Flag::CanViewRevenue
|
||||
| Flag::PaidMediaAllowed
|
||||
| Flag::CanViewCreditsRevenue
|
||||
| Flag::StargiftsAvailable;
|
||||
| Flag::StargiftsAvailable
|
||||
| Flag::PaidMessagesAvailable;
|
||||
channel->setFlags((channel->flags() & ~mask)
|
||||
| (update.is_can_set_username() ? Flag::CanSetUsername : Flag())
|
||||
| (update.is_can_view_participants()
|
||||
|
@ -1191,6 +1192,9 @@ void ApplyChannelUpdate(
|
|||
: Flag())
|
||||
| (update.is_stargifts_available()
|
||||
? Flag::StargiftsAvailable
|
||||
: Flag())
|
||||
| (update.is_paid_messages_available()
|
||||
? Flag::PaidMessagesAvailable
|
||||
: Flag()));
|
||||
channel->setUserpicPhoto(update.vchat_photo());
|
||||
if (const auto migratedFrom = update.vmigrated_from_chat_id()) {
|
||||
|
|
|
@ -72,6 +72,7 @@ enum class ChannelDataFlag : uint64 {
|
|||
CanViewCreditsRevenue = (1ULL << 34),
|
||||
SignatureProfiles = (1ULL << 35),
|
||||
StargiftsAvailable = (1ULL << 36),
|
||||
PaidMessagesAvailable = (1ULL << 37),
|
||||
};
|
||||
inline constexpr bool is_flag_type(ChannelDataFlag) { return true; };
|
||||
using ChannelDataFlags = base::flags<ChannelDataFlag>;
|
||||
|
@ -262,6 +263,9 @@ public:
|
|||
[[nodiscard]] bool stargiftsAvailable() const {
|
||||
return flags() & Flag::StargiftsAvailable;
|
||||
}
|
||||
[[nodiscard]] bool paidMessagesAvailable() const {
|
||||
return flags() & Flag::PaidMessagesAvailable;
|
||||
}
|
||||
|
||||
[[nodiscard]] static ChatRestrictionsInfo KickedRestrictedRights(
|
||||
not_null<PeerData*> participant);
|
||||
|
|
|
@ -73,6 +73,22 @@ int AppConfig::starrefCommissionMax() const {
|
|||
return get<int>(u"starref_max_commission_permille"_q, 900);
|
||||
}
|
||||
|
||||
float64 AppConfig::starsWithdrawRate() const {
|
||||
return get<float64>(u"stars_usd_withdraw_rate_x1000"_q, 1300) / 1000.;
|
||||
}
|
||||
|
||||
bool AppConfig::paidMessagesAvailable() const {
|
||||
return get<bool>(u"stars_paid_messages_available"_q, false);
|
||||
}
|
||||
|
||||
int AppConfig::paidMessageStarsMax() const {
|
||||
return get<int>(u"stars_paid_message_amount_max"_q, 10'000);
|
||||
}
|
||||
|
||||
int AppConfig::paidMessageCommission() const {
|
||||
return get<int>(u"stars_paid_message_commission_permille"_q, 850);
|
||||
}
|
||||
|
||||
void AppConfig::refresh(bool force) {
|
||||
if (_requestId || !_api) {
|
||||
if (force) {
|
||||
|
|
|
@ -72,6 +72,11 @@ public:
|
|||
[[nodiscard]] int starrefCommissionMin() const;
|
||||
[[nodiscard]] int starrefCommissionMax() const;
|
||||
|
||||
[[nodiscard]] float64 starsWithdrawRate() const;
|
||||
[[nodiscard]] bool paidMessagesAvailable() const;
|
||||
[[nodiscard]] int paidMessageStarsMax() const;
|
||||
[[nodiscard]] int paidMessageCommission() const;
|
||||
|
||||
void refresh(bool force = false);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Reference in a new issue