Don't allow sending stars from stream admin.

This commit is contained in:
John Preston
2025-11-25 19:05:55 +04:00
parent ef749e695e
commit e8fba23b59
6 changed files with 51 additions and 29 deletions
+3
View File
@@ -4791,6 +4791,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_paid_react_send" = "Send {price}"; "lng_paid_react_send" = "Send {price}";
"lng_paid_react_agree" = "By sending stars, you agree to the {link}."; "lng_paid_react_agree" = "By sending stars, you agree to the {link}.";
"lng_paid_react_agree_link" = "Terms of Service"; "lng_paid_react_agree_link" = "Terms of Service";
"lng_paid_react_admin_cant" = "You can't send Stars to your own Live Story.";
"lng_paid_react_toast#one" = "Star Sent!"; "lng_paid_react_toast#one" = "Star Sent!";
"lng_paid_react_toast#other" = "Stars Sent!"; "lng_paid_react_toast#other" = "Stars Sent!";
"lng_paid_react_toast_anonymous#one" = "Star sent anonymously!"; "lng_paid_react_toast_anonymous#one" = "Star sent anonymously!";
@@ -4812,6 +4813,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_paid_reaction_title" = "React with Stars"; "lng_paid_reaction_title" = "React with Stars";
"lng_paid_reaction_about" = "Highlight and pin your message by sending Stars to {name}."; "lng_paid_reaction_about" = "Highlight and pin your message by sending Stars to {name}.";
"lng_paid_reaction_button" = "Send {stars}"; "lng_paid_reaction_button" = "Send {stars}";
"lng_paid_admin_title" = "Receive Stars from Viewers";
"lng_paid_admin_about" = "Viewers can send you Star Reactions.";
"lng_sensitive_tag" = "18+"; "lng_sensitive_tag" = "18+";
"lng_sensitive_title" = "18+"; "lng_sensitive_title" = "18+";
@@ -43,18 +43,21 @@ void VideoStreamStarsBox(
VideoStreamStarsBoxArgs &&args) { VideoStreamStarsBoxArgs &&args) {
args.show->session().credits().load(); args.show->session().credits().load();
const auto admin = args.admin;
const auto sending = args.sending; const auto sending = args.sending;
auto submitText = [=](rpl::producer<int> amount) { auto submitText = [=](rpl::producer<int> amount) {
auto nice = std::move(amount) | rpl::map([=](int count) { auto nice = std::move(amount) | rpl::map([=](int count) {
return Ui::CreditsEmojiSmall().append( return Ui::CreditsEmojiSmall().append(
Lang::FormatCountDecimal(count)); Lang::FormatCountDecimal(count));
}); });
return (sending return admin
? tr::lng_paid_reaction_button ? tr::lng_box_ok(tr::marked)
: tr::lng_paid_comment_button)( : (sending
lt_stars, ? tr::lng_paid_reaction_button
std::move(nice), : tr::lng_paid_comment_button)(
Ui::Text::RichLangValue); lt_stars,
std::move(nice),
tr::rich);
}; };
const auto &show = args.show; const auto &show = args.show;
const auto session = &show->session(); const auto session = &show->session();
@@ -121,14 +124,17 @@ void VideoStreamStarsBox(
.submit = std::move(submitText), .submit = std::move(submitText),
.colorings = show->session().appConfig().groupCallColorings(), .colorings = show->session().appConfig().groupCallColorings(),
.balanceValue = session->credits().balanceValue(), .balanceValue = session->credits().balanceValue(),
.send = [weak, save = args.save](int count, uint64 barePeerId) { .send = [=, save = args.save](int count, uint64 barePeerId) {
save(count); if (!admin) {
save(count);
}
if (const auto strong = weak.get()) { if (const auto strong = weak.get()) {
strong->closeBox(); strong->closeBox();
} }
}, },
.videoStreamChoosing = !sending, .videoStreamChoosing = !sending,
.videoStreamSending = sending, .videoStreamSending = sending,
.videoStreamAdmin = admin,
.dark = true, .dark = true,
}); });
} }
@@ -39,6 +39,7 @@ struct VideoStreamStarsBoxArgs {
int min = 0; int min = 0;
int current = 0; int current = 0;
bool sending = false; bool sending = false;
bool admin = false;
Fn<void(int)> save; Fn<void(int)> save;
QString name; QString name;
}; };
@@ -1448,7 +1448,7 @@ void ComposeControls::setStarsReactionCounter(
_starsReaction->setAcceptBoth(); _starsReaction->setAcceptBoth();
_starsReaction->clicks( _starsReaction->clicks(
) | rpl::start_with_next([=](Qt::MouseButton button) { ) | rpl::start_with_next([=](Qt::MouseButton button) {
if (button == Qt::LeftButton) { if (_chosenStarsCount && button == Qt::LeftButton) {
_starsReactionIncrements.fire({ .count = 1 }); _starsReactionIncrements.fire({ .count = 1 });
startStarsSendEffect(); startStarsSendEffect();
} else { } else {
@@ -1457,6 +1457,7 @@ void ComposeControls::setStarsReactionCounter(
.top = _starsReactionTop.current(), .top = _starsReactionTop.current(),
.current = 0, .current = 0,
.sending = true, .sending = true,
.admin = !_chosenStarsCount,
.save = crl::guard(_starsReaction, [=](int count) { .save = crl::guard(_starsReaction, [=](int count) {
_starsReactionIncrements.fire({ _starsReactionIncrements.fire({
.count = count, .count = count,
@@ -1465,7 +1466,6 @@ void ComposeControls::setStarsReactionCounter(
}), }),
.name = _history ? _history->peer->shortName() : QString(), .name = _history ? _history->peer->shortName() : QString(),
})); }));
} }
}, _starsReaction->lifetime()); }, _starsReaction->lifetime());
@@ -493,6 +493,7 @@ void PaidReactionsBox(
const auto colorings = args.colorings; const auto colorings = args.colorings;
const auto videoStreamChoosing = args.videoStreamChoosing; const auto videoStreamChoosing = args.videoStreamChoosing;
const auto videoStreamSending = args.videoStreamSending; const auto videoStreamSending = args.videoStreamSending;
const auto videoStreamAdmin = args.videoStreamAdmin;
const auto videoStream = videoStreamChoosing || videoStreamSending; const auto videoStream = videoStreamChoosing || videoStreamSending;
const auto initialShownPeer = ranges::find( const auto initialShownPeer = ranges::find(
args.top, args.top,
@@ -514,7 +515,7 @@ void PaidReactionsBox(
count); count);
return Ui::ColorFromSerialized(coloring.bgLight); return Ui::ColorFromSerialized(coloring.bgLight);
}; };
AddStarSelectBubble( const auto bubble = AddStarSelectBubble(
content, content,
BoxShowFinishes(box), BoxShowFinishes(box),
state->chosen.value(), state->chosen.value(),
@@ -544,8 +545,12 @@ void PaidReactionsBox(
content, content,
std::move(args.top), std::move(args.top),
colorings, colorings,
state->chosen.value(), (videoStreamAdmin
state->shownPeer.value(), ? rpl::single(state->chosen.current())
: state->chosen.value()),
(videoStreamAdmin
? rpl::single(state->shownPeer.current())
: state->shownPeer.value()),
[=](uint64 barePeerId) { [=](uint64 barePeerId) {
state->shownPeer = state->savedShownPeer = barePeerId; state->shownPeer = state->savedShownPeer = barePeerId;
}, },
@@ -564,7 +569,9 @@ void PaidReactionsBox(
box->addRow( box->addRow(
object_ptr<FlatLabel>( object_ptr<FlatLabel>(
box, box,
(videoStreamChoosing (videoStreamAdmin
? tr::lng_paid_admin_title()
: videoStreamChoosing
? tr::lng_paid_comment_title() ? tr::lng_paid_comment_title()
: videoStreamSending : videoStreamSending
? tr::lng_paid_reaction_title() ? tr::lng_paid_reaction_title()
@@ -579,22 +586,24 @@ void PaidReactionsBox(
+ QMargins(0, st::lineWidth, 0, st::boostBottomSkip))); + QMargins(0, st::lineWidth, 0, st::boostBottomSkip)));
const auto label = CreateChild<FlatLabel>( const auto label = CreateChild<FlatLabel>(
labelWrap, labelWrap,
(videoStream (videoStreamAdmin
? tr::lng_paid_admin_about(tr::marked)
: videoStream
? (videoStreamChoosing ? (videoStreamChoosing
? tr::lng_paid_comment_about ? tr::lng_paid_comment_about
: tr::lng_paid_reaction_about)( : tr::lng_paid_reaction_about)(
lt_name, lt_name,
rpl::single(Text::Bold(args.name)), rpl::single(tr::bold(args.name)),
Text::RichLangValue) tr::rich)
: already : already
? tr::lng_paid_react_already( ? tr::lng_paid_react_already(
lt_count, lt_count,
rpl::single(already) | tr::to_count(), rpl::single(already) | tr::to_count(),
Text::RichLangValue) tr::rich)
: tr::lng_paid_react_about( : tr::lng_paid_react_about(
lt_channel, lt_channel,
rpl::single(Text::Bold(args.name)), rpl::single(tr::bold(args.name)),
Text::RichLangValue)), tr::rich)),
dark ? st::darkEditStarsText : st::boostText); dark ? st::darkEditStarsText : st::boostText);
label->setTryMakeSimilarLines(true); label->setTryMakeSimilarLines(true);
labelWrap->widthValue() | rpl::start_with_next([=](int width) { labelWrap->widthValue() | rpl::start_with_next([=](int width) {
@@ -630,15 +639,17 @@ void PaidReactionsBox(
AddDividerText( AddDividerText(
content, content,
tr::lng_paid_react_agree( (videoStreamAdmin
lt_link, ? tr::lng_paid_react_admin_cant(tr::marked)
rpl::combine( : tr::lng_paid_react_agree(
tr::lng_paid_react_agree_link(), lt_link,
tr::lng_group_invite_subscription_about_url() rpl::combine(
) | rpl::map([](const QString &text, const QString &url) { tr::lng_paid_react_agree_link(),
return Ui::Text::Link(text, url); tr::lng_group_invite_subscription_about_url()
}), ) | rpl::map([](const QString &text, const QString &url) {
Ui::Text::RichLangValue), return tr::link(text, url);
}),
tr::rich)),
st::defaultBoxDividerLabelPadding, st::defaultBoxDividerLabelPadding,
dark ? st::groupCallDividerLabel : st::defaultDividerLabel); dark ? st::groupCallDividerLabel : st::defaultDividerLabel);
@@ -56,6 +56,7 @@ struct PaidReactionBoxArgs {
Fn<void(int, uint64)> send; Fn<void(int, uint64)> send;
bool videoStreamChoosing = false; bool videoStreamChoosing = false;
bool videoStreamSending = false; bool videoStreamSending = false;
bool videoStreamAdmin = false;
bool dark = false; bool dark = false;
}; };