Add special toast title for anonymous stars.

This commit is contained in:
John Preston 2024-12-09 22:00:39 +04:00
parent 4701badb2a
commit 65d6636a41
5 changed files with 43 additions and 14 deletions

View file

@ -3806,6 +3806,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_paid_react_agree_link" = "Terms of Service"; "lng_paid_react_agree_link" = "Terms of Service";
"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#other" = "Stars sent anonymously!";
"lng_paid_react_toast_text#one" = "You reacted with **{count} Star**."; "lng_paid_react_toast_text#one" = "You reacted with **{count} Star**.";
"lng_paid_react_toast_text#other" = "You reacted with **{count} Stars**."; "lng_paid_react_toast_text#other" = "You reacted with **{count} Stars**.";
"lng_paid_react_undo" = "Undo"; "lng_paid_react_undo" = "Undo";

View file

@ -2694,6 +2694,10 @@ int HistoryItem::reactionsPaidScheduled() const {
return _reactions ? _reactions->scheduledPaid() : 0; return _reactions ? _reactions->scheduledPaid() : 0;
} }
bool HistoryItem::reactionsLocalAnonymous() const {
return _reactions ? _reactions->localPaidAnonymous() : false;
}
bool HistoryItem::reactionsAreTags() const { bool HistoryItem::reactionsAreTags() const {
return _flags & MessageFlag::ReactionsAreTags; return _flags & MessageFlag::ReactionsAreTags;
} }
@ -5337,19 +5341,28 @@ void HistoryItem::setServiceMessageByAction(const MTPmessageAction &action) {
&_history->session(), &_history->session(),
amount, amount,
currency); currency);
result.links.push_back(peer->createOpenLink()); const auto anonymous = _from->isServiceUser();
result.text = isSelf if (anonymous) {
? tr::lng_action_gift_sent(tr::now, result.text = tr::lng_action_gift_received_anonymous(
lt_cost,
cost,
Ui::Text::WithEntities)
: tr::lng_action_gift_received(
tr::now, tr::now,
lt_user,
Ui::Text::Link(peer->shortName(), 1), // Link 1.
lt_cost, lt_cost,
cost, cost,
Ui::Text::WithEntities); Ui::Text::WithEntities);
} else {
result.links.push_back(peer->createOpenLink());
result.text = isSelf
? tr::lng_action_gift_sent(tr::now,
lt_cost,
cost,
Ui::Text::WithEntities)
: tr::lng_action_gift_received(
tr::now,
lt_user,
Ui::Text::Link(peer->shortName(), 1), // Link 1.
lt_cost,
cost,
Ui::Text::WithEntities);
}
return result; return result;
}; };

View file

@ -471,6 +471,7 @@ public:
[[nodiscard]] auto topPaidReactionsWithLocal() const [[nodiscard]] auto topPaidReactionsWithLocal() const
-> std::vector<Data::MessageReactionsTopPaid>; -> std::vector<Data::MessageReactionsTopPaid>;
[[nodiscard]] int reactionsPaidScheduled() const; [[nodiscard]] int reactionsPaidScheduled() const;
[[nodiscard]] bool reactionsLocalAnonymous() const;
[[nodiscard]] bool canViewReactions() const; [[nodiscard]] bool canViewReactions() const;
[[nodiscard]] std::vector<Data::ReactionId> chosenReactions() const; [[nodiscard]] std::vector<Data::ReactionId> chosenReactions() const;
[[nodiscard]] Data::ReactionId lookupUnreadReaction( [[nodiscard]] Data::ReactionId lookupUnreadReaction(

View file

@ -163,6 +163,7 @@ PaidReactionToast::~PaidReactionToast() {
bool PaidReactionToast::maybeShowFor(not_null<HistoryItem*> item) { bool PaidReactionToast::maybeShowFor(not_null<HistoryItem*> item) {
const auto count = item->reactionsPaidScheduled(); const auto count = item->reactionsPaidScheduled();
const auto anonymous = item->reactionsLocalAnonymous();
const auto at = _owner->reactions().sendingScheduledPaidAt(item); const auto at = _owner->reactions().sendingScheduledPaidAt(item);
if (!count || !at) { if (!count || !at) {
return false; return false;
@ -172,13 +173,14 @@ bool PaidReactionToast::maybeShowFor(not_null<HistoryItem*> item) {
if (at <= crl::now() + ignore) { if (at <= crl::now() + ignore) {
return false; return false;
} }
showFor(item->fullId(), count, at - ignore, total); showFor(item->fullId(), count, anonymous, at - ignore, total);
return true; return true;
} }
void PaidReactionToast::showFor( void PaidReactionToast::showFor(
FullMsgId itemId, FullMsgId itemId,
int count, int count,
bool anonymous,
crl::time finish, crl::time finish,
crl::time total) { crl::time total) {
const auto old = _weak.get(); const auto old = _weak.get();
@ -186,6 +188,7 @@ void PaidReactionToast::showFor(
if (i != end(_stack)) { if (i != end(_stack)) {
if (old && i + 1 == end(_stack)) { if (old && i + 1 == end(_stack)) {
_count = count; _count = count;
_anonymous = anonymous;
_timeFinish = finish; _timeFinish = finish;
return; return;
} }
@ -199,14 +202,22 @@ void PaidReactionToast::showFor(
_hiding.push_back(base::take(_weak)); _hiding.push_back(base::take(_weak));
} }
_count.reset(); _count.reset();
_anonymous.reset();
_timeFinish.reset(); _timeFinish.reset();
_count = count; _count = count;
_anonymous = anonymous;
_timeFinish = finish; _timeFinish = finish;
auto text = rpl::combine( auto text = rpl::combine(
tr::lng_paid_react_toast( rpl::conditional(
lt_count, _anonymous.value(),
_count.value() | tr::to_count(), tr::lng_paid_react_toast_anonymous(
Ui::Text::Bold), lt_count,
_count.value() | tr::to_count(),
Ui::Text::Bold),
tr::lng_paid_react_toast(
lt_count,
_count.value() | tr::to_count(),
Ui::Text::Bold)),
tr::lng_paid_react_toast_text( tr::lng_paid_react_toast_text(
lt_count_decimal, lt_count_decimal,
_count.value() | tr::to_count(), _count.value() | tr::to_count(),

View file

@ -40,6 +40,7 @@ private:
void showFor( void showFor(
FullMsgId itemId, FullMsgId itemId,
int count, int count,
bool anonymous,
crl::time left, crl::time left,
crl::time total); crl::time total);
@ -53,6 +54,7 @@ private:
base::weak_ptr<Ui::Toast::Instance> _weak; base::weak_ptr<Ui::Toast::Instance> _weak;
std::vector<base::weak_ptr<Ui::Toast::Instance>> _hiding; std::vector<base::weak_ptr<Ui::Toast::Instance>> _hiding;
rpl::variable<int> _count; rpl::variable<int> _count;
rpl::variable<bool> _anonymous;
rpl::variable<crl::time> _timeFinish; rpl::variable<crl::time> _timeFinish;
std::vector<FullMsgId> _stack; std::vector<FullMsgId> _stack;