Warn admins about commission and stars.

This commit is contained in:
John Preston 2025-06-30 22:23:55 +04:00
parent cc6649667c
commit 3fea28f8b0
4 changed files with 87 additions and 37 deletions

View file

@ -4451,8 +4451,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_suggest_options_date_any" = "Anytime";
"lng_suggest_options_date_publish" = "Publish";
"lng_suggest_options_date_now" = "Publish Now";
"lng_suggest_options_date_about" = "Select the date and time you want the message to be published.";
"lng_suggest_options_date_about" = "Select the date and time you want the message to be published. The post will remain available for at least 24 hours from this date.";
"lng_suggest_options_you_get" = "You will receive {amount} ({percent}) for publishing this post.";
"lng_suggest_options_stars_warning" = "Transactions in **Stars** may be reversed by the payment provider within **21** days. Only accept Stars from people you trust.";
"lng_suggest_options_offer" = "Offer {amount}";
"lng_suggest_options_offer_free" = "Offer for Free";
"lng_suggest_options_update" = "Update Terms";
@ -4494,14 +4495,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_suggest_decline_text" = "Do you want to decline publishing this post from {from}?";
"lng_suggest_decline_text_to" = "Do you want to decline publishing this post to {channel}?";
"lng_suggest_decline_reason" = "Add a reason (optional)";
"lng_suggest_accept_title" = "Accept";
"lng_suggest_accept_title" = "Accept Terms";
"lng_suggest_accept_text" = "Do you want to publish this post from {from}?";
"lng_suggest_accept_text_to" = "Do you want to publish this post to {channel}?";
"lng_suggest_accept_receive" = "{channel} will receive {amount} for publishing {date}.";
"lng_suggest_accept_receive_now" = "{channel} will receive {amount} for publishing right now.";
"lng_suggest_accept_receive" = "{channel} will receive {amount} ({percent}) for publishing {date}.";
"lng_suggest_accept_receive_now" = "{channel} will receive {amount} ({percent}) for publishing right now.";
"lng_suggest_accept_receive_if" = "It must remain visible for at least **24** hours after publication.";
"lng_suggest_accept_pay" = "You will pay {amount} for publishing {date}.";
"lng_suggest_accept_pay_now" = "You will pay {amount} for publishing right now.";
"lng_suggest_accept_send" = "Send";
"lng_suggest_accept_send" = "Publish";
"lng_suggest_ton_amount#one" = "{count} TON";
"lng_suggest_ton_amount#other" = "{count} TON";
"lng_suggest_warn_title_stars" = "Stars will be lost";

View file

@ -137,9 +137,15 @@ void ConfirmApproval(
}
}
const auto peer = item->history()->peer;
const auto session = &peer->session();
const auto broadcast = peer->monoforumBroadcast();
const auto channelName = (broadcast ? broadcast : peer)->name();
const auto amount = Lang::FormatCreditsAmountWithCurrency(price);
const auto amount = admin
? HistoryView::FormatPriceAfterCommission(session, price)
: Lang::FormatCreditsAmountWithCurrency(price);
const auto commission = HistoryView::FormatAfterCommissionPercent(
session,
price);
const auto date = langDateTime(base::unixtime::parse(scheduleDate));
show->show(Box([=](not_null<Ui::GenericBox*> box) {
const auto callback = std::make_shared<Fn<void()>>();
@ -163,16 +169,20 @@ void ConfirmApproval(
Ui::Text::Bold(channelName),
lt_amount,
Ui::Text::Bold(amount),
lt_percent,
TextWithEntities{ commission },
lt_date,
Ui::Text::Bold(date),
Ui::Text::WithEntities)
Ui::Text::RichLangValue)
: tr::lng_suggest_accept_receive_now(
tr::now,
lt_channel,
Ui::Text::Bold(channelName),
lt_amount,
Ui::Text::Bold(amount),
Ui::Text::WithEntities))
lt_percent,
TextWithEntities{ commission },
Ui::Text::RichLangValue))
: (scheduleDate
? tr::lng_suggest_accept_pay(
tr::now,
@ -180,12 +190,24 @@ void ConfirmApproval(
Ui::Text::Bold(amount),
lt_date,
Ui::Text::Bold(date),
Ui::Text::WithEntities)
Ui::Text::RichLangValue)
: tr::lng_suggest_accept_pay_now(
tr::now,
lt_amount,
Ui::Text::Bold(amount),
Ui::Text::WithEntities)));
Ui::Text::RichLangValue)));
if (admin) {
text.append(' ').append(
tr::lng_suggest_accept_receive_if(
tr::now,
Ui::Text::RichLangValue));
if (price.stars()) {
text.append("\n\n").append(
tr::lng_suggest_options_stars_warning(
tr::now,
Ui::Text::RichLangValue));
}
}
}
Ui::ConfirmBox(box, {
.text = text,

View file

@ -109,10 +109,6 @@ void ChooseSuggestPriceBox(
}
};
const auto appConfig = &args.peer->session().appConfig();
const auto starsMul = appConfig->suggestedPostCommissionStars();
const auto tonMul = appConfig->suggestedPostCommissionTon();
const auto starsPrice = [=] {
return rpl::single(
CreditsAmount()
@ -129,17 +125,6 @@ void ChooseSuggestPriceBox(
return amount.ton();
}));
};
const auto formatPrice = [=](int mul) {
return [=](CreditsAmount amount) {
const auto value = (amount.value() * mul / 1000.);
const auto whole = int(std::floor(value));
//const auto nano = int(base::SafeRound(
// (value - whole) * Ui::kNanosInOne));
const auto nano = 0;
return Lang::FormatCreditsAmountWithCurrency(
CreditsAmount(whole, nano, amount.type()));
};
};
const auto peer = args.peer;
const auto admin = peer->amMonoforumAdmin();
@ -331,20 +316,26 @@ void ChooseSuggestPriceBox(
starsFieldWrap->resize(width, starsField->height());
}, starsFieldWrap->lifetime());
const auto starsCommission = QString::number(starsMul / 10.) + '%';
const auto tonCommission = QString::number(tonMul / 10.) + '%';
Ui::AddSkip(starsInner);
Ui::AddSkip(starsInner);
Ui::AddDividerText(
starsInner,
(admin
? tr::lng_suggest_options_you_get(
const auto formatPrice = [peer = args.peer](CreditsAmount amount) {
return FormatPriceAfterCommission(&peer->session(), amount);
};
const auto formatCommission = [peer = args.peer](CreditsAmount amount) {
return FormatAfterCommissionPercent(&peer->session(), amount);
};
Ui::AddDividerText(starsInner, admin
? rpl::combine(
tr::lng_suggest_options_you_get(
lt_amount,
starsPrice() | rpl::map(formatPrice(starsMul)),
starsPrice() | rpl::map(formatPrice),
lt_percent,
rpl::single(starsCommission))
: tr::lng_suggest_options_stars_price_about()));
starsPrice() | rpl::map(formatCommission)),
tr::lng_suggest_options_stars_warning(Ui::Text::RichLangValue)
) | rpl::map([=](const QString &t1, const TextWithEntities &t2) {
return TextWithEntities{ t1 }.append("\n\n").append(t2);
})
: tr::lng_suggest_options_stars_price_about(Ui::Text::WithEntities));
const auto tonWrap = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
@ -396,9 +387,9 @@ void ChooseSuggestPriceBox(
(admin
? tr::lng_suggest_options_you_get(
lt_amount,
tonPrice() | rpl::map(formatPrice(tonMul)),
tonPrice() | rpl::map(formatPrice),
lt_percent,
rpl::single(tonCommission))
tonPrice() | rpl::map(formatCommission))
: tr::lng_suggest_options_ton_price_about()));
tonWrap->toggleOn(state->ton.value(), anim::type::instant);
@ -642,6 +633,33 @@ bool CanAddOfferToMessage(not_null<HistoryItem*> item) {
history->owner().history(broadcast)).has_value();
}
QString FormatPriceAfterCommission(
not_null<Main::Session*> session,
CreditsAmount price) {
const auto appConfig = &session->appConfig();
const auto mul = price.stars()
? appConfig->suggestedPostCommissionStars()
: appConfig->suggestedPostCommissionTon();
const auto value = (price.value() * mul / 1000.);
const auto whole = int(std::floor(value));
//const auto nano = int(base::SafeRound(
// (value - whole) * Ui::kNanosInOne));
const auto nano = 0;
return Lang::FormatCreditsAmountWithCurrency(
CreditsAmount(whole, nano, price.type()));
}
QString FormatAfterCommissionPercent(
not_null<Main::Session*> session,
CreditsAmount price) {
const auto appConfig = &session->appConfig();
const auto mul = price.stars()
? appConfig->suggestedPostCommissionStars()
: appConfig->suggestedPostCommissionTon();
return QString::number(mul / 10.) + '%';
}
void InsufficientTonBox(
not_null<Ui::GenericBox*> box,
not_null<PeerData*> peer,
@ -755,6 +773,7 @@ void SuggestOptions::edit() {
.peer = _peer,
.done = apply,
.value = _values,
.mode = _mode,
}));
}

View file

@ -58,6 +58,13 @@ void ChooseSuggestPriceBox(
[[nodiscard]] bool CanAddOfferToMessage(not_null<HistoryItem*> item);
[[nodiscard]] QString FormatPriceAfterCommission(
not_null<Main::Session*> session,
CreditsAmount price);
[[nodiscard]] QString FormatAfterCommissionPercent(
not_null<Main::Session*> session,
CreditsAmount price);
void InsufficientTonBox(
not_null<Ui::GenericBox*> box,
not_null<PeerData*> peer,