Correctly show commission in stars stats.

This commit is contained in:
John Preston 2024-11-29 22:13:16 +04:00
parent 552dd318cd
commit b401c37c39
11 changed files with 75 additions and 11 deletions

View file

@ -75,6 +75,14 @@ constexpr auto kTransactionsLimit = 100;
const auto stargift = tl.data().vstargift();
const auto reaction = tl.data().is_reaction();
const auto amount = Data::FromTL(tl.data().vstars());
const auto starrefAmount = tl.data().vstarref_amount()
? Data::FromTL(*tl.data().vstarref_amount())
: StarsAmount();
const auto starrefCommission
= tl.data().vstarref_commission_permille().value_or_empty();
const auto starrefBarePeerId = tl.data().vstarref_peer()
? peerFromMTP(*tl.data().vstarref_peer()).value
: 0;
const auto incoming = (amount >= StarsAmount());
const auto saveActorId = (reaction || !extended.empty()) && incoming;
return Data::CreditsHistoryEntry{
@ -93,6 +101,9 @@ constexpr auto kTransactionsLimit = 100;
? owner->processDocument(stargift->data().vsticker())->id
: 0),
.bareActorId = saveActorId ? barePeerId : uint64(0),
.starrefAmount = starrefAmount,
.starrefCommission = starrefCommission,
.starrefRecipientId = starrefBarePeerId,
.peerType = tl.data().vpeer().match([](const HistoryPeerTL &) {
return Data::CreditsHistoryEntry::PeerType::Peer;
}, [](const MTPDstarsTransactionPeerPlayMarket &) {

View file

@ -1146,9 +1146,43 @@ void AddCreditsHistoryEntryTable(
st::giveawayGiftCodeTableMargin);
const auto peerId = PeerId(entry.barePeerId);
const auto actorId = PeerId(entry.bareActorId);
const auto starrefRecipientId = PeerId(entry.starrefRecipientId);
const auto session = &controller->session();
if (actorId || peerId) {
auto text = entry.in
if (entry.starrefCommission) {
if (entry.starrefAmount) {
AddTableRow(
table,
tr::lng_star_ref_commission_title(),
rpl::single(TextWithEntities{
QString::number(entry.starrefCommission / 10.) + '%' }));
} else {
AddTableRow(
table,
tr::lng_gift_link_label_reason(),
tr::lng_credits_box_history_entry_reason_star_ref(
Ui::Text::WithEntities));
}
}
if (starrefRecipientId && entry.starrefAmount) {
AddTableRow(
table,
tr::lng_credits_box_history_entry_affiliate(),
controller,
starrefRecipientId);
}
if (peerId && entry.starrefCommission) {
AddTableRow(
table,
(entry.starrefAmount
? tr::lng_credits_box_history_entry_referred
: tr::lng_credits_box_history_entry_miniapp)(),
controller,
peerId);
}
if (actorId || (!entry.starrefCommission && peerId)) {
auto text = entry.starrefCommission
? tr::lng_credits_box_history_entry_referred()
: entry.in
? tr::lng_credits_box_history_entry_peer_in()
: tr::lng_credits_box_history_entry_peer();
AddTableRow(

View file

@ -1745,7 +1745,7 @@ void Controller::fillBotAffiliateProgram() {
? user->botInfo->starRefProgram.commission
: 0;
return commission
? u"%1%"_q.arg(commission / 10.)
? Info::BotStarRef::FormatCommission(commission)
: tr::lng_manage_peer_bot_star_ref_off(tr::now);
});
AddButtonWithCount(

View file

@ -63,6 +63,9 @@ struct CreditsHistoryEntry final {
uint64 bareGiveawayMsgId = 0;
uint64 bareGiftStickerId = 0;
uint64 bareActorId = 0;
StarsAmount starrefAmount;
int starrefCommission = 0;
uint64 starrefRecipientId = 0;
PeerType peerType;
QDateTime subscriptionUntil;
QDateTime successDate;

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "core/stars_amount.h"
#include "data/data_statistics_chart.h"
#include <QtCore/QDateTime>

View file

@ -53,7 +53,7 @@ void ConnectStarRef(
} // namespace
QString FormatStarRefCommission(ushort commission) {
QString FormatCommission(ushort commission) {
return QString::number(commission / 10.) + '%';
}
@ -248,7 +248,7 @@ object_ptr<Ui::BoxContent> StarRefLinkBox(
: tr::lng_star_ref_link_about_channel)(
lt_amount,
rpl::single(Ui::Text::Bold(
FormatStarRefCommission(program.commission))),
FormatCommission(program.commission))),
lt_app,
rpl::single(Ui::Text::Bold(bot->name())),
lt_duration,
@ -341,7 +341,7 @@ object_ptr<Ui::BoxContent> StarRefLinkBox(
rpl::single(Ui::Text::Bold(bot->name())),
lt_amount,
rpl::single(Ui::Text::Bold(
FormatStarRefCommission(program.commission))),
FormatCommission(program.commission))),
lt_duration,
FormatProgramDuration(program),
Ui::Text::WithEntities),

View file

@ -38,7 +38,7 @@ struct ConnectedBot {
};
using ConnectedBots = std::vector<ConnectedBot>;
[[nodiscard]] QString FormatStarRefCommission(ushort commission);
[[nodiscard]] QString FormatCommission(ushort commission);
[[nodiscard]] rpl::producer<TextWithEntities> FormatProgramDuration(
StarRefProgram program);

View file

@ -156,8 +156,8 @@ std::unique_ptr<PeerListRow> ListController::createRow(ConnectedBot bot) {
if (bot.state.revoked) {
result->setCustomStatus(u"Revoked"_q);
} else {
result->setCustomStatus(u"+%1%, %2"_q.arg(
QString::number(program.commission / 10.),
result->setCustomStatus(u"+%1, %2"_q.arg(
FormatCommission(program.commission),
duration));
}
return result;

View file

@ -645,7 +645,7 @@ void InnerWidget::setupCommission() {
commission,
setCommission,
setCommission,
[=](int value) { return FormatStarRefCommission(value); },
[=](int value) { return FormatCommission(value); },
_state.exists),
st::boxRowPadding);
_state.program.commission = commission;

View file

@ -35,6 +35,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h"
#include "history/history_item.h"
#include "history/history_item_components.h" // HistoryServicePaymentRefund.
#include "info/bot/starref/info_bot_starref_common.h"
#include "info/channel_statistics/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget.
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
#include "info/statistics/info_statistics_list_controllers.h"
@ -1012,6 +1013,11 @@ void ReceiptCreditsBox(
? tr::lng_credits_box_history_entry_subscription(tr::now)
: !e.title.isEmpty()
? e.title
: e.starrefCommission
? tr::lng_credits_commission(
tr::now,
lt_amount,
Info::BotStarRef::FormatCommission(e.starrefCommission))
: e.soldOutInfo
? tr::lng_credits_box_history_entry_gift_unavailable(tr::now)
: sentStarGift

View file

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_photo_media.h"
#include "data/data_session.h"
#include "history/view/media/history_view_sticker_player.h"
#include "info/bot/starref/info_bot_starref_common.h"
#include "info/userpic/info_userpic_emoji_builder_preview.h"
#include "lang/lang_keys.h"
#include "main/main_session.h"
@ -545,7 +546,15 @@ Fn<PaintRoundImageCallback(Fn<void()>)> PaintPreviewCallback(
}
TextWithEntities GenerateEntryName(const Data::CreditsHistoryEntry &entry) {
return (entry.floodSkip
return (entry.starrefCommission && !entry.starrefAmount)
? tr::lng_credits_commission(
tr::now,
lt_amount,
TextWithEntities{
Info::BotStarRef::FormatCommission(entry.starrefCommission)
},
TextWithEntities::Simple)
: (entry.floodSkip
? tr::lng_credits_box_history_entry_api
: entry.reaction
? tr::lng_credits_box_history_entry_reaction_name