Allow selecting how many stars to send.

This commit is contained in:
John Preston
2025-10-17 16:23:54 +04:00
parent ecdca38d9e
commit a61d73f48a
11 changed files with 296 additions and 44 deletions
+2
View File
@@ -377,6 +377,8 @@ PRIVATE
calls/group/calls_group_rtmp.h
calls/group/calls_group_settings.cpp
calls/group/calls_group_settings.h
calls/group/calls_group_stars_box.cpp
calls/group/calls_group_stars_box.h
calls/group/calls_group_toasts.cpp
calls/group/calls_group_toasts.h
calls/group/calls_group_viewport.cpp
+13
View File
@@ -4655,6 +4655,19 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_paid_react_show_in_top" = "Show me in Top Senders";
"lng_paid_react_anonymous" = "Anonymous";
"lng_paid_comment_title" = "Highlight and Pin";
"lng_paid_comment_about" = "Highlight and pin your message by adding Stars for {name}.";
"lng_paid_comment_button" = "Add {stars}";
"lng_paid_comment_pin_about" = "pin in chat";
"lng_paid_comment_pin_minutes#one" = "{count}m";
"lng_paid_comment_pin_minutes#other" = "{count}m";
"lng_paid_comment_pin_hours#one" = "{count}h";
"lng_paid_comment_pin_hours#other" = "{count}h";
"lng_paid_comment_limit_about#one" = "character";
"lng_paid_comment_limit_about#other" = "characters";
"lng_paid_comment_emoji_about#one" = "emoji";
"lng_paid_comment_emoji_about#other" = "emoji";
"lng_sensitive_tag" = "18+";
"lng_sensitive_title" = "18+";
"lng_sensitive_text" = "This media may contain sensitive content suitable only for adults. Do you still want to view it?";
@@ -39,6 +39,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_calls.h"
#include "styles/style_chat_helpers.h"
#include "styles/style_chat.h"
#include "styles/style_credits.h"
#include "styles/style_media_view.h"
#include <QtGui/QGuiApplication>
@@ -152,6 +153,8 @@ struct MessagesUi::MessageView {
QPoint reactionShift;
Ui::PeerUserpicView view;
Ui::Text::String text;
Ui::Text::String price;
int stars = 0;
int top = 0;
int width = 0;
int left = 0;
@@ -178,6 +181,7 @@ MessagesUi::MessagesUi(
return result;
})
, _messageBgRect(CountMessageRadius(), _messageBg.color())
, _payedBgRect(CountMessageRadius(), st::creditsBg3)
, _fadeHeight(st::normalFont->height)
, _streamMode(_mode == MessagesMode::VideoStream) {
setupList(std::move(messages), std::move(shown));
@@ -323,11 +327,23 @@ void MessagesUi::setContentFailed(MessageView &entry) {
Ui::Text::Italic(u"Failed to send the message."_q)),
kMarkupTextOptions,
st::groupCallWidth / 4);
entry.price = Ui::Text::String();
}
void MessagesUi::setContent(
MessageView &entry,
const TextWithEntities &text) {
const TextWithEntities &text,
int stars) {
if (stars) {
entry.price = Ui::Text::String(
st::messageTextStyle,
Ui::Text::IconEmoji(
&st::starIconEmojiSmall
).append(Lang::FormatCountDecimal(stars)),
kMarkupTextOptions);
} else {
entry.price = Ui::Text::String();
}
entry.text = Ui::Text::String(
st::messageTextStyle,
text,
@@ -337,6 +353,11 @@ void MessagesUi::setContent(
.session = &_show->session(),
.repaint = [this, id = entry.id] { repaintMessage(id); },
}));
if (!entry.price.isEmpty()) {
entry.text.updateSkipBlock(
entry.price.maxWidth(),
st::normalFont->height);
}
entry.text.setLink(1, entry.fromLink);
if (entry.text.hasSpoilers()) {
const auto id = entry.id;
@@ -424,6 +445,7 @@ void MessagesUi::appendMessage(const Message &data) {
auto &entry = _views.emplace_back();
const auto id = entry.id = data.id;
entry.stars = data.stars;
const auto repaint = [=] {
repaintMessage(id);
};
@@ -438,11 +460,7 @@ void MessagesUi::appendMessage(const Message &data) {
} else {
auto text = Ui::Text::Link(Ui::Text::Bold(data.peer->shortName()), 1)
.append(' ').append(data.text);
if (data.stars) {
text.append(" (").append(
QString::number(data.stars)).append(" stars)");
}
setContent(entry, text);
setContent(entry, text, data.stars);
}
entry.top = top;
updateMessageSize(entry);
@@ -713,9 +731,12 @@ void MessagesUi::setupMessagesWidget() {
}
if (!_streamMode) {
_messageBgRect.paint(p, { x, y, width, use });
} else if (entry.stars) {
_payedBgRect.paint(p, { x, y, width, use });
}
auto leftSkip = padding.left();
const auto priceSkip = padding.right() / 2;
const auto hasUserpic = !entry.failed;
if (hasUserpic) {
const auto userpicSize = st::groupCallUserpic;
@@ -766,6 +787,15 @@ void MessagesUi::setupMessagesWidget() {
.now = now,
.paused = !_messages->window()->isActiveWindow(),
});
if (!entry.price.isEmpty()) {
entry.price.draw(p, {
.position = {
x + entry.width - entry.price.maxWidth() - priceSkip,
y + use - st::normalFont->height,
},
.availableWidth = entry.price.maxWidth(),
});
}
if (!scaled && entry.reactionId && !entry.reactionAnimation) {
startReactionAnimation(entry);
}
@@ -64,7 +64,10 @@ private:
void handleIdUpdates(rpl::producer<MessageIdUpdate> idUpdates);
void toggleMessage(MessageView &entry, bool shown);
void setContentFailed(MessageView &entry);
void setContent(MessageView &entry, const TextWithEntities &text);
void setContent(
MessageView &entry,
const TextWithEntities &text,
int stars);
void updateMessageSize(MessageView &entry);
bool updateMessageHeight(MessageView &entry);
void animateMessageSent(MessageView &entry);
@@ -95,6 +98,8 @@ private:
style::complex_color _messageBg;
Ui::RoundRect _messageBgRect;
Ui::RoundRect _payedBgRect;
QPoint _reactionBasePosition;
rpl::lifetime _effectsLifetime;
@@ -0,0 +1,127 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "calls/group/calls_group_stars_box.h"
#include "boxes/send_credits_box.h"
#include "chat_helpers/compose/compose_show.h"
#include "data/data_message_reactions.h"
#include "data/data_peer.h"
#include "data/data_user.h"
#include "lang/lang_keys.h"
#include "main/main_app_config.h"
#include "main/main_session.h"
#include "payments/ui/payments_reaction_box.h"
#include "ui/layers/generic_box.h"
#include "ui/text/text_utilities.h"
#include "ui/dynamic_thumbnails.h"
#include "window/window_session_controller.h"
namespace Calls::Group {
namespace {
constexpr auto kMaxStarsFallback = 10'000;
constexpr auto kDefaultStars = 10;
} // namespace
void VideoStreamStarsBox(
not_null<Ui::GenericBox*> box,
VideoStreamStarsBoxArgs &&args) {
args.show->session().credits().load();
auto submitText = [=](rpl::producer<int> amount) {
auto nice = std::move(amount) | rpl::map([=](int count) {
return Ui::CreditsEmojiSmall().append(
Lang::FormatCountDecimal(count));
});
return tr::lng_paid_comment_button(
lt_stars,
std::move(nice),
Ui::Text::RichLangValue);
};
const auto &show = args.show;
const auto session = &show->session();
const auto appConfig = &session->appConfig();
const auto max = std::max(
appConfig->get<int>(
u"stars_paid_reaction_amount_max"_q,
kMaxStarsFallback),
2);
const auto chosen = std::clamp(
args.current ? args.current : kDefaultStars,
1,
max);
auto top = std::vector<Ui::PaidReactionTop>();
const auto add = [&](const Data::MessageReactionsTopPaid &entry) {
const auto peer = entry.peer;
const auto name = peer
? peer->shortName()
: tr::lng_paid_react_anonymous(tr::now);
const auto open = [=] {
if (const auto controller = show->resolveWindow()) {
controller->showPeerInfo(peer);
}
};
top.push_back({
.name = name,
.photo = (peer
? Ui::MakeUserpicThumbnail(peer)
: Ui::MakeHiddenAuthorThumbnail()),
.barePeerId = peer ? uint64(peer->id.value) : 0,
.count = int(entry.count),
.click = peer ? open : Fn<void()>(),
.my = (entry.my == 1),
});
};
top.reserve(2);
auto myAdded = base::flat_set<uint64>();
const auto i = ranges::find(top, true, &Ui::PaidReactionTop::my);
if (i != end(top)) {
myAdded.emplace(i->barePeerId);
}
const auto myCount = uint32((i != end(top)) ? i->count : 0);
const auto myAdd = [&](PeerData *peer) {
const auto barePeerId = peer ? uint64(peer->id.value) : 0;
if (!myAdded.emplace(barePeerId).second) {
return;
}
add(Data::MessageReactionsTopPaid{
.peer = peer,
.count = myCount,
.my = true,
});
};
myAdd(session->user());
myAdd(nullptr);
ranges::stable_sort(top, ranges::greater(), &Ui::PaidReactionTop::count);
const auto weak = base::make_weak(box);
Ui::PaidReactionsBox(box, {
.chosen = chosen,
.max = max,
.top = std::move(top),
.session = &show->session(),
.name = args.name,
.submit = std::move(submitText),
.balanceValue = session->credits().balanceValue(),
.send = [weak, save = args.save](int count, uint64 barePeerId) {
save(count);
if (const auto strong = weak.get()) {
strong->closeBox();
}
},
.videoStreamChoosing = true,
.dark = true,
});
}
object_ptr<Ui::BoxContent> MakeVideoStreamStarsBox(
VideoStreamStarsBoxArgs &&args) {
return Box(VideoStreamStarsBox, std::move(args));
}
} // namespace Calls::Group
@@ -0,0 +1,35 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
namespace ChatHelpers {
class Show;
} // namespace ChatHelpers
namespace Ui {
class BoxContent;
class GenericBox;
} // namespace Ui
namespace Calls::Group {
struct VideoStreamStarsBoxArgs {
std::shared_ptr<ChatHelpers::Show> show;
int current = 0;
Fn<void(int)> save;
QString name;
};
void VideoStreamStarsBox(
not_null<Ui::GenericBox*> box,
VideoStreamStarsBoxArgs &&args);
[[nodiscard]] object_ptr<Ui::BoxContent> MakeVideoStreamStarsBox(
VideoStreamStarsBoxArgs &&args);
} // namespace Calls::Group
@@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/timer_rpl.h"
#include "base/unixtime.h"
#include "boxes/edit_caption_box.h"
#include "calls/group/calls_group_stars_box.h"
#include "chat_helpers/compose/compose_show.h"
#include "chat_helpers/emoji_suggestions_widget.h"
#include "chat_helpers/message_field.h"
@@ -1080,12 +1081,15 @@ void ComposeControls::initLikeButton() {
void ComposeControls::initEditStarsButton() {
if (_editStars) {
_editStars->setClickedCallback([=] {
if (!_chosenStarsCount) {
_chosenStarsCount = 1;
} else {
++*_chosenStarsCount;
}
updateSendButtonType();
_show->show(Calls::Group::MakeVideoStreamStarsBox({
.show = _show,
.current = _chosenStarsCount.value_or(0),
.save = crl::guard(_editStars, [=](int count) {
_chosenStarsCount = count;
updateSendButtonType();
}),
.name = _history ? _history->peer->name() : QString(),
}));
});
}
}
@@ -39,7 +39,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Payments {
namespace {
constexpr auto kMaxPerReactionFallback = 2'500;
constexpr auto kMaxPerReactionFallback = 10'000;
constexpr auto kDefaultPerReaction = 50;
void TryAddingPaidReaction(
@@ -247,7 +247,7 @@ void ShowPaidReactionDetails(
.max = max,
.top = std::move(top),
.session = &channel->session(),
.channel = channel->name(),
.name = channel->name(),
.submit = std::move(submitText),
.balanceValue = session->credits().balanceValue(),
.send = [=](int count, uint64 barePeerId) {
@@ -477,11 +477,12 @@ void PaidReactionsBox(
PaidReactionBoxArgs &&args) {
Expects(!args.top.empty());
const auto dark = args.dark;
args.max = std::max(args.max, 2);
args.chosen = std::clamp(args.chosen, 1, args.max);
box->setWidth(st::boxWideWidth);
box->setStyle(st::paidReactBox);
box->setStyle(dark ? st::darkEditStarsBox : st::paidReactBox);
box->setNoContentMargin(true);
struct State {
@@ -496,6 +497,7 @@ void PaidReactionsBox(
state->chosen = count;
};
const auto videoStream = args.videoStreamChoosing;
const auto initialShownPeer = ranges::find(
args.top,
true,
@@ -540,13 +542,17 @@ void PaidReactionsBox(
&PaidReactionTop::my)->count;
PaidReactionSlider(content, args.chosen, args.max, changed);
box->addTopButton(st::boxTitleClose, [=] { box->closeBox(); });
box->addTopButton(
dark ? st::darkEditStarsClose : st::boxTitleClose,
[=] { box->closeBox(); });
box->addRow(
object_ptr<FlatLabel>(
box,
tr::lng_paid_react_title(),
st::boostCenteredTitle),
(videoStream
? tr::lng_paid_comment_title()
: tr::lng_paid_react_title()),
dark ? st::darkEditStarsCenteredTitle : st::boostCenteredTitle),
st::boxRowPadding + QMargins(0, st::paidReactTitleSkip, 0, 0),
style::al_top);
const auto labelWrap = box->addRow(
@@ -555,16 +561,21 @@ void PaidReactionsBox(
+ QMargins(0, st::lineWidth, 0, st::boostBottomSkip)));
const auto label = CreateChild<FlatLabel>(
labelWrap,
(already
(videoStream
? tr::lng_paid_comment_about(
lt_name,
rpl::single(Text::Bold(args.name)),
Text::RichLangValue)
: already
? tr::lng_paid_react_already(
lt_count,
rpl::single(already) | tr::to_count(),
Text::RichLangValue)
: tr::lng_paid_react_about(
lt_channel,
rpl::single(Text::Bold(args.channel)),
rpl::single(Text::Bold(args.name)),
Text::RichLangValue)),
st::boostText);
dark ? st::darkEditStarsText : st::boostText);
labelWrap->widthValue() | rpl::start_with_next([=](int width) {
label->resizeToWidth(width);
}, label->lifetime());
@@ -575,26 +586,27 @@ void PaidReactionsBox(
label->moveToLeft(0, skip);
}, label->lifetime());
FillTopReactors(
content,
std::move(args.top),
state->chosen.value(),
state->shownPeer.value(),
[=](uint64 barePeerId) {
state->shownPeer = state->savedShownPeer = barePeerId;
});
const auto named = box->addRow(
object_ptr<Checkbox>(
box,
tr::lng_paid_react_show_in_top(tr::now),
state->shownPeer.current() != 0,
st::paidReactBoxCheckbox),
style::al_top);
named->checkedValue(
) | rpl::start_with_next([=](bool show) {
state->shownPeer = show ? state->savedShownPeer : 0;
}, named->lifetime());
if (!args.videoStreamChoosing) {
FillTopReactors(
content,
std::move(args.top),
state->chosen.value(),
state->shownPeer.value(),
[=](uint64 barePeerId) {
state->shownPeer = state->savedShownPeer = barePeerId;
});
const auto named = box->addRow(
object_ptr<Checkbox>(
box,
tr::lng_paid_react_show_in_top(tr::now),
state->shownPeer.current() != 0,
st::paidReactBoxCheckbox),
style::al_top);
named->checkedValue(
) | rpl::start_with_next([=](bool show) {
state->shownPeer = show ? state->savedShownPeer : 0;
}, named->lifetime());
}
AddSkip(content);
AddSkip(content);
@@ -656,7 +668,9 @@ void PaidReactionsBox(
content,
args.session,
std::move(args.balanceValue),
false);
false,
nullptr,
dark);
rpl::combine(
balance->sizeValue(),
box->widthValue()
@@ -39,10 +39,12 @@ struct PaidReactionBoxArgs {
std::vector<PaidReactionTop> top;
not_null<Main::Session*> session;
QString channel;
QString name;
Fn<rpl::producer<TextWithEntities>(rpl::producer<int> amount)> submit;
rpl::producer<CreditsAmount> balanceValue;
Fn<void(int, uint64)> send;
bool videoStreamChoosing = false;
bool dark = false;
};
void PaidReactionsBox(
@@ -289,11 +289,17 @@ boostTitleBadgeSkip: 6px;
boostCenteredTitle: FlatLabel(boostTitle) {
align: align(top);
}
darkEditStarsCenteredTitle: FlatLabel(boostCenteredTitle) {
textFg: groupCallMembersFg;
}
boostTextSkip: 5px;
boostText: FlatLabel(defaultFlatLabel) {
minWidth: 40px;
align: align(top);
}
darkEditStarsText: FlatLabel(boostText) {
textFg: groupCallMembersFg;
}
boostTextPending: FlatLabel(boostText) {
textFg: windowSubTextFg;
}
@@ -315,6 +321,13 @@ boostBox: Box(premiumPreviewDoubledLimitsBox) {
style: semiboldTextStyle;
}
}
darkEditStarsClose: IconButton(boxTitleClose) {
icon: icon {{ "box_button_close", groupCallMemberInactiveIcon }};
iconOver: icon {{ "box_button_close", groupCallMemberInactiveIcon }};
ripple: RippleAnimation(defaultRippleAnimation) {
color: groupCallMembersBgOver;
}
}
boostReplaceUserpicsPadding: margins(0px, 18px, 0px, 20px);
boostReplaceUserpicsSkip: 42px;
@@ -401,6 +414,13 @@ paidReactBox: Box(boostBox) {
paidReactBoxCheckbox: Checkbox(defaultCheckbox) {
width: 0px;
}
darkEditStarsBox: Box(paidReactBox) {
bg: groupCallMembersBg;
title: FlatLabel(boxTitle) {
textFg: groupCallMembersFg;
align: align(top);
}
}
paidReactBubbleIcon: icon{{ "settings/premium/star", premiumButtonFg }};
paidReactBubbleTop: 5px;
paidReactSliderTop: 5px;